3

I have a Pandas dataframe containing Latitude and Longitude data for an abundance of points, and I would like to clip them to a shapefile; ie: everything outside the boundaries of the shapefile is dropped.

Is there a way to achieve this within a Python package such as MatPlotLib?

I have searched on Google, but 'clipping' seems to refer to data being cut off by map legends/axis rather than what I'm describing.

This image displays what I'm after - I did this in ArcMap but need to automate the process. The grey points represent the entire dataframe, while red points are 'clipped' to the green shapefile below.

Clipped points (Red)

Here is the code I'm running to over-lay the points in case it is of any use:

f, ax = plt.subplots(1, figsize=(12, 12))
ax.plot(Easting,Northing, 'bo', markersize=5)
IMD.plot(column='imd_score', colormap='Blues', linewidth=0.1, axes=ax)
locs, labels = plt.xticks()
plt.setp(labels, rotation=90)
plt.axis('equal')
Cobain
  • 195
  • 1
  • 14

1 Answers1

1

You can try geopandas. It's a very good library that works basically with pandas dataframes, but geolocalized, i.e. containing a column of Geometry. You can import export shapefiles directly within it, and finally do something like Intersection.

Fabio Lamanna
  • 20,504
  • 24
  • 90
  • 122