mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-23 13:20:36 +08:00
* don't execute * list examples * try with executed notebooks * build intro, add pygeos * auto build * build the same as currently * remove kernel name * add few more * revert choro * add rest * remove kernelspec * clear choropleths * build choropleths, clear choro_legends * clear introduction * remove kernelspec * clean meta * execute choro_legends * always execute + exceptions * fix cartopy plot
7.5 KiB
7.5 KiB
In [ ]:
%matplotlib inline
from shapely.geometry import Point
from geopandas import datasets, GeoDataFrame, read_file
from geopandas.tools import overlay
# NYC Boros
zippath = datasets.get_path('nybb')
polydf = read_file(zippath)
# Generate some points
b = [int(x) for x in polydf.total_bounds]
N = 8
pointdf = GeoDataFrame([
{'geometry': Point(x, y), 'value1': x + y, 'value2': x - y}
for x, y in zip(range(b[0], b[2], int((b[2] - b[0]) / N)),
range(b[1], b[3], int((b[3] - b[1]) / N)))])
# Make sure they're using the same projection reference
pointdf.crs = polydf.crsIn [ ]:
pointdfIn [ ]:
polydfIn [ ]:
pointdf.plot()In [ ]:
polydf.plot()In [ ]:
from geopandas.tools import sjoin
join_left_df = sjoin(pointdf, polydf, how="left")
join_left_df
# Note the NaNs where the point did not intersect a boroIn [ ]:
join_right_df = sjoin(pointdf, polydf, how="right")
join_right_df
# Note Staten Island is repeatedIn [ ]:
join_inner_df = sjoin(pointdf, polydf, how="inner")
join_inner_df
# Note the lack of NaNs; dropped anything that didn't intersectIn [ ]:
sjoin(pointdf, polydf, how="left", op="within")