Created
June 17, 2016 17:16
-
-
Save mhweber/cdb80fb03144fde8758d8e5b20a9b417 to your computer and use it in GitHub Desktop.
A quick and dirty poor man's clip using geopandas. First does a union between a plot shapefile and an overlapping features shapefilie, then subsets where attributes of the features shapefile are not null to get the features clipped to boundaries of plots.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Plots = gpd.GeoDataFrame.from_file('Plots.shp') | |
Plots.plot() | |
Features = gpd.GeoDataFrame.from_file('Features.shp') | |
Features.plot() | |
# union features | |
Both = overlay(Plots, Features, how="union") | |
Both.head() | |
# 'clip' by getting rid of union features where attributes for plot are null in the union | |
Clips = Both[pd.notnull(Both['ORIG_FID'])] | |
Clips.plot() | |
Clips.to_file('Clips.shp', driver = 'ESRI Shapefile') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think overlay is wrong. Should it be gpd.overlay or from some other package because I get an error?