Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

You can do this in Python with the help of Rtree and Shapely. The procedure would look similar to this answerthis answer.

The R-tree index would identify a list of possible nearest polygons, all based on bounding boxes. Then from this shortlist list, you'd go through them and use Shapely to determine which polygon is closest, based on the minimum distance between the geometries. Consider that you might have more than one geometry that is closest (e.g., if there are multiple polygons that intersect, they will all be 0 distance, thus there is no metric for "closest". You could additionally evaluate the minimum distance of centroids from polygons with 0 distance.)

This is a pretty good blog post showing how to use GeoPanda's sindex (spatial index), which is based on Rtree (which is an optional dependency for GeoPandas).

You can do this in Python with the help of Rtree and Shapely. The procedure would look similar to this answer.

The R-tree index would identify a list of possible nearest polygons, all based on bounding boxes. Then from this shortlist list, you'd go through them and use Shapely to determine which polygon is closest, based on the minimum distance between the geometries. Consider that you might have more than one geometry that is closest (e.g., if there are multiple polygons that intersect, they will all be 0 distance, thus there is no metric for "closest". You could additionally evaluate the minimum distance of centroids from polygons with 0 distance.)

This is a pretty good blog post showing how to use GeoPanda's sindex (spatial index), which is based on Rtree (which is an optional dependency for GeoPandas).

You can do this in Python with the help of Rtree and Shapely. The procedure would look similar to this answer.

The R-tree index would identify a list of possible nearest polygons, all based on bounding boxes. Then from this shortlist list, you'd go through them and use Shapely to determine which polygon is closest, based on the minimum distance between the geometries. Consider that you might have more than one geometry that is closest (e.g., if there are multiple polygons that intersect, they will all be 0 distance, thus there is no metric for "closest". You could additionally evaluate the minimum distance of centroids from polygons with 0 distance.)

This is a pretty good blog post showing how to use GeoPanda's sindex (spatial index), which is based on Rtree (which is an optional dependency for GeoPandas).

Source Link
Mike T
  • 42.4k
  • 10
  • 129
  • 190

You can do this in Python with the help of Rtree and Shapely. The procedure would look similar to this answer.

The R-tree index would identify a list of possible nearest polygons, all based on bounding boxes. Then from this shortlist list, you'd go through them and use Shapely to determine which polygon is closest, based on the minimum distance between the geometries. Consider that you might have more than one geometry that is closest (e.g., if there are multiple polygons that intersect, they will all be 0 distance, thus there is no metric for "closest". You could additionally evaluate the minimum distance of centroids from polygons with 0 distance.)

This is a pretty good blog post showing how to use GeoPanda's sindex (spatial index), which is based on Rtree (which is an optional dependency for GeoPandas).