- How can I save / define this transformation inside a Foundry object to reuse later for filtering datasets in Pipeline Builder?
- Is this the best approach to filter geographic data in Foundry, or are there better methods/tools within Foundry for this purpose?
I want to save the geo-object defined by my transformation inside this Contour object, save that and filter the underlying data doing something like:
import geopandas as gpd
from shapely.geometry import shape
import json
# Define the GeoJSON directly as a string
geojson = """
{
"type": "Polygon",
"coordinates": [
[
[0.000000, 50.34019],
[0.4826020, 50.39630],
[1.934890, 51.45618],
[2.699252, 53.02397],
[1.552709, 54.26984],
[0.000000, 55.13357],
[-0.8932500, 55.63047],
[-1.963357, 56.18742],
[-4.218225, 55.56569],
[-5.708732, 53.52674],
[-6.702403, 50.12755],
[-5.326551, 49.43660],
[-2.039793, 50.10304],
[0.000000, 50.34019]
]
]
}
"""
# Parse the GeoJSON string into a Python dictionary
geojson_data = json.loads(geojson)
# Convert the GeoJSON Polygon to a Shapely Polygon object
polygon = shape(geojson_data)
# Example usage with a GeoDataFrame
file_path = "geodataframe_file.geojson"
gdf = gpd.read_file(file_path)
# Filter rows where geometry is within the Polygon
filtered_rows = gdf[gdf.geometry.within(polygon)]
# Output the filtered rows
print(filtered_rows)