⚠️ Our 0.1 release refactored several early-development functions for long-term stability, to update your code see here. ⚠️
Future changes will come with deprecation warnings! 🙂

Proximity to raster or vector

Proximity to raster or vector#

This example demonstrates the calculation of proximity distances to a raster or vector using proximity().

We open an example raster, and a vector for which we select a single feature

import geoutils as gu

filename_rast = gu.examples.get_path("everest_landsat_b4")
filename_vect = gu.examples.get_path("everest_rgi_outlines")
rast = gu.Raster(filename_rast)
vect = gu.Vector(filename_vect)
vect = vect[vect["RGIId"] == "RGI60-15.10055"]
rast.crop(vect)

# Plot the raster and vector
rast.plot(cmap="Blues")
vect.reproject(rast).plot(fc="none", ec="k", lw=2)
proximity metric

We use the raster as a reference to match for rasterizing the proximity distances with proximity(). See Match-reference functionality for more details.

proximity metric

Proximity can also be computed to target pixels of a raster, or that of a mask

# Get mask of pixels within 30 of 200 infrared
import numpy as np

mask_200 = np.abs(rast - 200) < 30
mask_200.plot()
proximity metric

Because a mask is bool, no need to pass target pixels

proximity metric

By default, proximity is computed using the georeference unit from a Raster’s res, here meters. It can also be computed in pixels.

proximity_mask = mask_200.proximity(distance_unit="pixel")
proximity_mask.plot(cmap="viridis")
proximity metric

Total running time of the script: (0 minutes 1.063 seconds)

Gallery generated by Sphinx-Gallery