|
49 | 49 | "\n", |
50 | 50 | "DATA_DIR = Path().cwd() / \"data\"\n", |
51 | 51 | "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()" |
53 | 82 | ] |
54 | 83 | }, |
55 | 84 | { |
|
82 | 111 | ")\n", |
83 | 112 | "\n", |
84 | 113 | "new_haven_redlining = redlines.execute().set_crs(\"EPSG:4326\")\n", |
| 114 | + "# TODO: Set a numeric grade for graduated symbology\n", |
| 115 | + "\n", |
85 | 116 | "new_haven_redlining.to_file(INEQUALITY_GEOJSON_FILE, engine=\"fiona\")\n", |
86 | 117 | "\n", |
87 | 118 | "new_haven_bbox = new_haven_redlining.total_bounds" |
|
92 | 123 | "id": "63f92fa9-49cd-4e9e-a19d-7d6a60747b65", |
93 | 124 | "metadata": {}, |
94 | 125 | "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\"**. " |
96 | 129 | ] |
97 | 130 | }, |
98 | 131 | { |
|
102 | 135 | "metadata": {}, |
103 | 136 | "outputs": [], |
104 | 137 | "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" |
106 | 154 | ] |
107 | 155 | }, |
108 | 156 | { |
109 | 157 | "cell_type": "markdown", |
110 | 158 | "id": "61803898-9832-44a9-a04f-23bdb1a4ac3c", |
111 | 159 | "metadata": {}, |
112 | 160 | "source": [ |
113 | | - "### Calculating NDVI\n", |
| 161 | + "### Calculate NDVI\n", |
114 | 162 | "\n", |
115 | 163 | "We're going to calculate NDVI from Sentinel-2 data." |
116 | 164 | ] |
|
202 | 250 | "ndvi.rio.reproject(\n", |
203 | 251 | " \"EPSG:4326\",\n", |
204 | 252 | ").rio.to_raster(\n", |
205 | | - " raster_path=NDVI_FILE, \n", |
| 253 | + " raster_path=NDVI_GEOTIFF_FILE, \n", |
206 | 254 | " driver=\"COG\",\n", |
207 | 255 | ")" |
208 | 256 | ] |
209 | 257 | }, |
| 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 | + }, |
210 | 290 | { |
211 | 291 | "cell_type": "markdown", |
212 | 292 | "id": "41a3f550-04da-4170-9e69-b4131d428fdd", |
|
227 | 307 | "from exactextract import exact_extract\n", |
228 | 308 | "\n", |
229 | 309 | "new_haven_redlining_and_ndvi = exact_extract(\n", |
230 | | - " NDVI_FILE,\n", |
| 310 | + " NDVI_GEOTIFF_FILE,\n", |
231 | 311 | " new_haven_redlining,\n", |
232 | 312 | " \"mean_ndvi=mean\",\n", |
233 | 313 | " include_geom = True,\n", |
234 | 314 | " include_cols=[\"label\", \"grade\", \"city\", \"fill\"],\n", |
235 | 315 | " output=\"pandas\",\n", |
236 | 316 | ")\n", |
237 | 317 | "\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" |
239 | 334 | ] |
240 | 335 | }, |
241 | 336 | { |
|
0 commit comments