How to Create a Custom Geographic Filter for an user-defined area in Foundry?

  1. How can I save / define this transformation inside a Foundry object to reuse later for filtering datasets in Pipeline Builder?
  2. 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)

One easy way to do this is to copy-paste your geojson into a String-type column in a Pipeline Builder “manual data entry” node, convert that to a Geometry-type column using the Pipeline Builder “prepare geometry” transform, and then do a “Geo Intersection inner join” between your geometry and a dataset of lat-long points. The whole pipeline should look like this (in this example, the points are also manually entered, but they could of course come from a dataset instead).

The “prepare point geometries” node:

The “prepare region geometries” node:

The join node:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.