Skip to content

Commit f6a470e

Browse files
committed
Flesh out demo w/ JGIS
1 parent f6ed7b3 commit f6a470e

File tree

1 file changed

+102
-7
lines changed

1 file changed

+102
-7
lines changed

modules/06-geojupyter/demo.ipynb

Lines changed: 102 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,36 @@
4949
"\n",
5050
"DATA_DIR = Path().cwd() / \"data\"\n",
5151
"INEQUALITY_GEOJSON_FILE = DATA_DIR / \"redlining_newhaven_ct.geojson\"\n",
52-
"NDVI_FILE = DATA_DIR / \"ndvi.tif\""
52+
"NDVI_GEOTIFF_FILE = DATA_DIR / \"ndvi.tif\"\n",
53+
"INEQUALITY_NDVI_GEOJSON_FILE = DATA_DIR / \"redlining_ndvi_newhaven_ct.geojson\""
54+
]
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"id": "caaed0ec-07be-4675-bf2f-c626d500d443",
59+
"metadata": {},
60+
"source": [
61+
"### Set up a JupyterGIS project\n",
62+
"\n",
63+
"We can build a JupyterGIS project from scratch in Python. Let's start by adding an OpenStreetMap basemap and displaying the widget in a side panel."
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"id": "4eb60a7f-dd77-4043-8812-32cac1bdd800",
70+
"metadata": {},
71+
"outputs": [],
72+
"source": [
73+
"from jupytergis import GISDocument\n",
74+
"\n",
75+
"jgis_project = GISDocument()\n",
76+
"jgis_project.add_raster_layer(\n",
77+
" url=\"https://tile.openstreetmap.org/{z}/{x}/{y}.png\",\n",
78+
" name=\"Basemap\",\n",
79+
")\n",
80+
"\n",
81+
"jgis_project.sidecar()"
5382
]
5483
},
5584
{
@@ -82,6 +111,8 @@
82111
")\n",
83112
"\n",
84113
"new_haven_redlining = redlines.execute().set_crs(\"EPSG:4326\")\n",
114+
"# TODO: Set a numeric grade for graduated symbology\n",
115+
"\n",
85116
"new_haven_redlining.to_file(INEQUALITY_GEOJSON_FILE, engine=\"fiona\")\n",
86117
"\n",
87118
"new_haven_bbox = new_haven_redlining.total_bounds"
@@ -92,7 +123,9 @@
92123
"id": "63f92fa9-49cd-4e9e-a19d-7d6a60747b65",
93124
"metadata": {},
94125
"source": [
95-
"Let's explore the data a little bit. Hover over the polygons after running the cell below! Does anything jump out at you?"
126+
"#### Explore the data\n",
127+
"\n",
128+
"Let's explore the data a little bit. After running the cell below, **right-click the \"New Haven neighborhood redlining\" layer** in the JupyterGIS interface, and **select \"Zoom to layer\"**. "
96129
]
97130
},
98131
{
@@ -102,15 +135,30 @@
102135
"metadata": {},
103136
"outputs": [],
104137
"source": [
105-
"new_haven_redlining.explore(column=\"grade\", cmap=\"inferno\")"
138+
"jgis_project.add_geojson_layer(\n",
139+
" path=INEQUALITY_GEOJSON_FILE,\n",
140+
" name=\"New Haven neighborhood redlining\",\n",
141+
");"
142+
]
143+
},
144+
{
145+
"cell_type": "markdown",
146+
"id": "7663ab54-2d69-479b-b8ce-cbdc0bc13143",
147+
"metadata": {},
148+
"source": [
149+
"Now, with the \"New Haven neighborhood redlining\" layer selected, **click the `i` (identify) icon in the toolbar** at the top of the JupyterGIS interface.\n",
150+
"\n",
151+
"Select some neighborhoods and view their \"Grade\" and \"Category\" attributes.\n",
152+
"\n",
153+
"TODO: Symbologize on numeric grade"
106154
]
107155
},
108156
{
109157
"cell_type": "markdown",
110158
"id": "61803898-9832-44a9-a04f-23bdb1a4ac3c",
111159
"metadata": {},
112160
"source": [
113-
"### Calculating NDVI\n",
161+
"### Calculate NDVI\n",
114162
"\n",
115163
"We're going to calculate NDVI from Sentinel-2 data."
116164
]
@@ -202,11 +250,43 @@
202250
"ndvi.rio.reproject(\n",
203251
" \"EPSG:4326\",\n",
204252
").rio.to_raster(\n",
205-
" raster_path=NDVI_FILE, \n",
253+
" raster_path=NDVI_GEOTIFF_FILE, \n",
206254
" driver=\"COG\",\n",
207255
")"
208256
]
209257
},
258+
{
259+
"cell_type": "markdown",
260+
"id": "14a184a5-00ab-4347-b576-bc384b715c92",
261+
"metadata": {},
262+
"source": [
263+
"#### Explore the data\n",
264+
"\n",
265+
"Let's explore the data in JupyterGIS again.\n",
266+
"This time, we'll add the layer with the GUI.\n",
267+
"\n",
268+
"If the \"identify\" tool is still active, click the `i` icon in the toolbar again to disable it.\n",
269+
"\n",
270+
"Now, **click the `+` icon in the toolbar** to open the new layer interface.\n",
271+
"**Select \"Add Raster Layer\", then \"New GeoTiff Layer\"**.\n",
272+
"\n",
273+
"**Select \"Browse Server Files\"** and then **navigate to `ndvi.tif` in the module 6 data directory** (`workshop-open-source-geospatial/modules/06-geojupyter/data/ndvi.tif`).\n",
274+
"\n",
275+
"Click **Select**.\n",
276+
"\n",
277+
"**Set the \"Min\" field to `0` and \"Max\" to `1`**.\n",
278+
"\n",
279+
"**Uncheck \"Normalize\"**.\n",
280+
"\n",
281+
"Scroll down to **input the layer name as \"NDVI\"**.\n",
282+
"\n",
283+
"Finally, **right-click the \"NDVI\" layer** and **select \"Edit Symbology\"**. The symbology menu may take a moment to load. Be patient! **Select \"Classify\" then click \"OK\".**\n",
284+
"\n",
285+
"The brighter areas have a higher NDVI value, and the darker areas have a lower one.\n",
286+
"\n",
287+
"We can use the identify tool (`i` icon in the toolbar) to explore the raw values."
288+
]
289+
},
210290
{
211291
"cell_type": "markdown",
212292
"id": "41a3f550-04da-4170-9e69-b4131d428fdd",
@@ -227,15 +307,30 @@
227307
"from exactextract import exact_extract\n",
228308
"\n",
229309
"new_haven_redlining_and_ndvi = exact_extract(\n",
230-
" NDVI_FILE,\n",
310+
" NDVI_GEOTIFF_FILE,\n",
231311
" new_haven_redlining,\n",
232312
" \"mean_ndvi=mean\",\n",
233313
" include_geom = True,\n",
234314
" include_cols=[\"label\", \"grade\", \"city\", \"fill\"],\n",
235315
" output=\"pandas\",\n",
236316
")\n",
237317
"\n",
238-
"new_haven_redlining_and_ndvi.explore(column=\"mean_ndvi\")"
318+
"new_haven_redlining_and_ndvi.set_crs(\n",
319+
" \"EPSG:4326\"\n",
320+
").to_file(INEQUALITY_NDVI_GEOJSON_FILE, engine=\"fiona\")"
321+
]
322+
},
323+
{
324+
"cell_type": "code",
325+
"execution_count": null,
326+
"id": "8244a541-59d2-4372-a8b6-9f7f8b6483de",
327+
"metadata": {},
328+
"outputs": [],
329+
"source": [
330+
"# jgis_project.add_geojson_layer(\n",
331+
"# path=INEQUALITY_NDVI_GEOJSON_FILE,\n",
332+
"# name=\"New Haven neighborhood redlining w/ NDVI\",\n",
333+
"# ) # TODO"
239334
]
240335
},
241336
{

0 commit comments

Comments
 (0)