mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-24 13:30:40 +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
4.2 KiB
4.2 KiB
In [ ]:
import geopandas as gpd
import folium
import matplotlib.pyplot as pltIn [ ]:
path = gpd.datasets.get_path('nybb')
df = gpd.read_file(path)
df.head()In [ ]:
df.plot(figsize=(6, 6))
plt.show()In [ ]:
print(df.crs)In [ ]:
df = df.to_crs(epsg=4326)
print(df.crs)
df.head()In [ ]:
df.plot(figsize=(6, 6))
plt.show()In [ ]:
m = folium.Map(location=[40.70, -73.94], zoom_start=10, tiles='CartoDB positron')
mIn [ ]:
for _, r in df.iterrows():
#without simplifying the representation of each borough, the map might not be displayed
#sim_geo = gpd.GeoSeries(r['geometry'])
sim_geo = gpd.GeoSeries(r['geometry']).simplify(tolerance=0.001)
geo_j = sim_geo.to_json()
geo_j = folium.GeoJson(data=geo_j,
style_function=lambda x: {'fillColor': 'orange'})
folium.Popup(r['BoroName']).add_to(geo_j)
geo_j.add_to(m)
mIn [ ]:
df['lat'] = df.centroid.y
df['lon'] = df.centroid.x
df.head()In [ ]:
for _, r in df.iterrows():
folium.Marker(location=[r['lat'], r['lon']], popup='length: {} <br> area: {}'.format(r['Shape_Leng'], r['Shape_Area'])).add_to(m)
mIn [ ]: