Home > OS >  Most efficient way to find polygon-coordinate intersections in large GeoJSON object
Most efficient way to find polygon-coordinate intersections in large GeoJSON object

Time:10-30

I'm working on a project that requires coordinate mappings - determining whether a coordinate point exists in a series of polygons. The number of mappings is quite large - ~10 million coordinates across 100 million polygons.

Before I continue, I've already looked at the questions enter image description here

I'd join it with the "within" predicate:

from shapely.geometry import Point, Polygon
import geopandas

polys = geopandas.GeoDataFrame({
    "name": ["foo", "bar"],
    "geometry": [
        Polygon([(5, 5), (5, 13), (13, 13), (13, 5)]),
        Polygon([(10, 10), (10, 15), (15, 15), (15, 10)]),
    ]
})

pnts = geopandas.GeoDataFrame({
    "pnt": ["A", "B", "C"],
    "geometry": [
        Point(3, 3), Point(8, 8), Point(11, 11)
    ]
})

result = geopandas.sjoin(pnts, polys, how='left', op='within')

I get:

pnt                  geometry  index_right name
  A   POINT (3.00000 3.00000)          NaN  NaN
  B   POINT (8.00000 8.00000)          0.0  foo
  C POINT (11.00000 11.00000)          0.0  foo
  C POINT (11.00000 11.00000)          1.0  bar

  • Related