1

I have a huge point dataset with almost 300.000 points and I want to intersect them with a country geometry that has a complex geometry (multiple islands and borders). What I've done so far is to construct a GeoPandas dataframe and then clip it, however the process takes almost 50 minutes whereas if I perform the same task with ArcGIS the entire process takes only 43 seconds. I've been searching for a way to improve the process without success.

gdf = gpd.GeoDataFrame(
    merged_data,
    crs='EPSG:4326',
    geometry=[Point(xy) for xy in zip(merged_data.longitude, merged_data.latitude)])
poly = country_boundary.geometry.unary_union
points_clip = gdf[gdf.geometry.intersects(poly)]
Vince
  • 20,017
  • 15
  • 45
  • 64
dguerrero
  • 204
  • 1
  • 8

1 Answers1

2

Use geopandas.clip for clipping. That is an efficient way how to do so, especially with GeoPandas 0.8.0 and pygeos.

points_clip = gpd.clip(gdf, country_boundary)
martinfleis
  • 2,407
  • 11
  • 17