Skip to content

Commit

Permalink
extract to points figure
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldorman committed Aug 2, 2023
1 parent f3411d8 commit dfb1add
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions 06-raster-vector.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,18 @@ In the following examples, we use a third-party package called `rasterstats`, wh

### Extraction to points {#sec-extraction-to-points}

The basic example is of extracting the value of a raster cell at specific points. For this purpose, we will use `zion_points`, which contain a sample of 30 locations within the Zion National Park (Figure ...). The following expression extracts elevation values from `srtm`:
The basic example is of extracting the value of a raster cell at specific points. For this purpose, we will use `zion_points`, which contain a sample of 30 locations within the Zion National Park, which in figure @fig-zion-points:

```{python}
#| label: fig-zion-points
#| fig-cap: 30 point locations within the Zion National Park, with elevation in the background
fig, ax = plt.subplots()
rasterio.plot.show(src_srtm, ax=ax)
zion_points.plot(ax=ax, color='black');
```

The following expression extracts elevation values from `srtm`:

```{python}
result = rasterstats.point_query(
Expand All @@ -197,7 +208,7 @@ The resulting object is a `list` of raster values, corresponding to `zion_points
result[:5]
```

To create a `DataFrame` with points' IDs (one value per vector's row) and related `srtm` values for each point, we need to assign it:
To get a `DataFrame` with points geometries (and attributes, if any) and the related `srtm` values for each point, we can assign the extraction result into a new column:

```{python}
zion_points['elev'] = result
Expand Down
Binary file modified output/dem_contour.gpkg
Binary file not shown.
Binary file modified output/nlcd_4326.tif
Binary file not shown.
Binary file modified output/nlcd_4326_2.tif
Binary file not shown.
Binary file modified output/srtm_32612.tif
Binary file not shown.

0 comments on commit dfb1add

Please sign in to comment.