Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring updates #25

Merged
merged 4 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/05-geocoding-apis/lecture.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@
"ax = vacant.plot(c=\"b\", markersize=1, alpha=0.5)\n",
"\n",
"occupied = parking[parking[\"occupancystate\"] == \"OCCUPIED\"]\n",
"ax = vacant.plot(ax=ax, c=\"r\", markersize=1, alpha=0.5)"
"ax = occupied.plot(ax=ax, c=\"r\", markersize=1, alpha=0.5)"
]
},
{
Expand Down
18 changes: 8 additions & 10 deletions modules/06-spatial-data/lecture.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"import folium\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import rasterio\n",
"import rasterio.features"
Expand Down Expand Up @@ -171,9 +170,10 @@
"metadata": {},
"outputs": [],
"source": [
"# create a geopandas geodataframe from the pandas dataframe\n",
"gdf_business = gpd.GeoDataFrame(df)\n",
"gdf_business.shape"
"# create a geometry array to contain shapely geometry for geopandas to use\n",
"# notice the shapely points are lng, lat so that they are equivalent to x, y\n",
"geometry = gpd.points_from_xy(x=df[\"lng\"], y=df[\"lat\"])\n",
"geometry[:5]"
]
},
{
Expand All @@ -182,11 +182,9 @@
"metadata": {},
"outputs": [],
"source": [
"# create a geometry column to contain shapely geometry for geopandas to use\n",
"# notice the shapely points are lng, lat so that they are equivalent to x, y\n",
"# create a geopandas geodataframe from the pandas dataframe\n",
"# also notice that we set the CRS explicitly\n",
"gdf_business[\"geometry\"] = gpd.points_from_xy(x=gdf_business[\"lng\"], y=gdf_business[\"lat\"])\n",
"gdf_business.crs = \"epsg:4326\"\n",
"gdf_business = gpd.GeoDataFrame(df, geometry=geometry, crs=\"epsg:4326\")\n",
"gdf_business.shape"
]
},
Expand Down Expand Up @@ -418,7 +416,7 @@
"# takes a few seconds...\n",
"# dissolve lets you aggregate (merge geometries together) by shared attribute values\n",
"# this is the spatial equivalent of pandas's groupby function\n",
"gdf_counties = gdf_tracts.dissolve(by=\"COUNTYFP\", aggfunc=np.sum)"
"gdf_counties = gdf_tracts.dissolve(by=\"COUNTYFP\", aggfunc=\"sum\")"
]
},
{
Expand Down Expand Up @@ -831,7 +829,7 @@
" legend_name=\"Businesses per square km\",\n",
").add_to(m)\n",
"\n",
"# add mouseover tooltip to the countries\n",
"# add mouseover tooltip to the tracts\n",
"c.geojson.add_child(folium.features.GeoJsonTooltip([\"GEOID\", \"density\"]))\n",
"\n",
"# save web map to disk\n",
Expand Down
5 changes: 3 additions & 2 deletions modules/06-spatial-data/raster-crop-bbox.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"metadata": {},
"outputs": [],
"source": [
"import rasterio.mask\n",
"import rasterio\n",
"from rasterio.mask import mask\n",
"from shapely.wkt import loads"
]
},
Expand Down Expand Up @@ -54,7 +55,7 @@
"outputs": [],
"source": [
"# crop the raster to the bounding box\n",
"out_image, out_transform = rasterio.mask.mask(raster, [bbox], crop=True)\n",
"out_image, out_transform = mask(raster, [bbox], crop=True)\n",
"out_meta = raster.meta\n",
"out_meta.update(\n",
" {\n",
Expand Down
2 changes: 1 addition & 1 deletion modules/07-urban-networks-i/lecture.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@
"metadata": {},
"outputs": [],
"source": [
"# restaurants near the empire state buildings\n",
"# restaurants near the empire state building\n",
"address = \"350 5th Ave, New York, NY 10001\"\n",
"tags = {\"amenity\": \"restaurant\"}\n",
"gdf = ox.geometries_from_address(address, tags=tags, dist=500)\n",
Expand Down