Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
gboeing committed Feb 14, 2024
1 parent 896cf2b commit c0b46c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
16 changes: 7 additions & 9 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
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

0 comments on commit c0b46c2

Please sign in to comment.