Skip to content

Commit

Permalink
remove links
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldorman committed Jul 11, 2024
1 parent e85a412 commit d2d50a4
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 138 deletions.
10 changes: 6 additions & 4 deletions 05-raster-vector.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ Possible values other than `'mean'`, `'min'`, and `'max'` are:
- `'majority'`---The most frequently occurring value
- `'median'`---The median value

See the [documentation](https://pythonhosted.org/rasterstats/manual.html#statistics) of `rasterstats.zonal_stats` for the complete list.
See the documentation of `rasterstats.zonal_stats` for the complete list.
Additionally, the `rasterstats.zonal_stats` function accepts user-defined functions for calculating any custom statistics.

To count occurrences of categorical raster values within polygons (@fig-raster-extract-to-polygon (b)), we can use masking (@sec-raster-cropping) combined with `np.unique`, as follows.
Expand Down Expand Up @@ -502,9 +502,11 @@ The default `merge_alg=rasterio.enums.MergeAlg.replace` means that "later" value
The other option `merge_alg=rasterio.enums.MergeAlg.add` means that burned values are summed, i.e., the pixel gets the sum of all burned values.

When rasterizing lines and polygons, we also have the choice between two pixel-matching algorithms.
The default, `all_touched=False`, implies pixels that are selected by [Bresenham's line algorithm](https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm) (for lines) or pixels whose center is within the polygon (for polygons).
The default, `all_touched=False`, implies pixels that are selected by Bresenham's line algorithm[^bresenham] (for lines) or pixels whose center is within the polygon (for polygons).
The other option `all_touched=True`, as the name suggests, implies that all pixels intersecting with the geometry are matched.

[^bresenham]: [https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm](https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm)

Finally, we can set the `fill` value, which is the value that "unaffected" pixels get, with `fill=0` being the default.

How the `rasterio.features.rasterize` function works with all of these various parameters will be made clear in the next examples.
Expand Down Expand Up @@ -937,8 +939,8 @@ Unfortunately, **rasterio** does not provide any way of extracting the contour l

There are two possible workarounds:

1. Using `gdal_contour` on the [command line](https://gdal.org/programs/gdal_contour.html) (see below), or through its Python interface [**osgeo**](https://gis.stackexchange.com/questions/360431/how-can-i-create-contours-from-geotiff-and-python-gdal-rasterio-etc-into-sh)
2. Writing a custom function to export contour coordinates generated by, e.g., [**matplotlib**](https://www.tutorialspoint.com/how-to-get-coordinates-from-the-contour-in-matplotlib) or [**skimage**](https://gis.stackexchange.com/questions/268331/how-can-i-extract-contours-from-a-raster-with-python)
1. Using `gdal_contour` on the command line (see below), or through its Python interface **osgeo**
2. Writing a custom function to export contour coordinates generated by, e.g., **matplotlib** or **skimage**

We demonstrate the first approach, using `gdal_contour`.
Although we deviate from the Python-focused approach towards more direct interaction with GDAL, the benefit of `gdal_contour` is the proven algorithm, customized to spatial data, and with many relevant options.
Expand Down
169 changes: 76 additions & 93 deletions Geocomputation-with-Python.tex

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions geckodriver.log
Original file line number Diff line number Diff line change
Expand Up @@ -5947,3 +5947,19 @@ WebDriver BiDi listening on ws://127.0.0.1:40001
console.error: ({})
DevTools listening on ws://127.0.0.1:40001/devtools/browser/55452ebd-6e52-4d26-84c2-5eda809b7809
1720548080298 Marionette INFO Stopped listening on port 36931
1720616186961 geckodriver INFO Listening on 127.0.0.1:35039
1720616187851 geckodriver INFO Listening on 127.0.0.1:43679
1720616188708 geckodriver INFO Listening on 127.0.0.1:36719
1720616189565 geckodriver INFO Listening on 127.0.0.1:46739
1720616190484 geckodriver INFO Listening on 127.0.0.1:35525
1720616240084 geckodriver INFO Listening on 127.0.0.1:46697
1720616257247 geckodriver INFO Listening on 127.0.0.1:56855
1720616352792 geckodriver INFO Listening on 127.0.0.1:59151
1720616353708 geckodriver INFO Listening on 127.0.0.1:60795
1720616354526 geckodriver INFO Listening on 127.0.0.1:36559
1720616355305 geckodriver INFO Listening on 127.0.0.1:38331
1720616356043 geckodriver INFO Listening on 127.0.0.1:52157
1720616356852 geckodriver INFO Listening on 127.0.0.1:47075
1720616357676 geckodriver INFO Listening on 127.0.0.1:56603
1720616358446 geckodriver INFO Listening on 127.0.0.1:60809
1720616359262 geckodriver INFO Listening on 127.0.0.1:50487
82 changes: 41 additions & 41 deletions output/plot_rasterio2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified output/w_many_features.gpkg
Binary file not shown.
Binary file modified output/w_many_layers.gpkg
Binary file not shown.
Binary file modified output/world.gpkg
Binary file not shown.

0 comments on commit d2d50a4

Please sign in to comment.