Distance operations

Distance operations#

Computing distance between sets of geospatial data or manipulating their shape based on distance is often important for later analysis. To facilitate this type of operations, GeoUtils implements distance-specific functionalities for both vectors and rasters.

Tip

It is often important to compute distances in a metric CRS. For this, reproject (with reproject()) to a local metric CRS (that can be estimated with get_metric_crs()).

Proximity#

Proximity corresponds to the distance to the closest target geospatial data, computed on each pixel of a raster’s grid. The target geospatial data can be either a vector or a raster.

geoutils.Raster.proximity() and geoutils.Vector.proximity()

Hide the code for opening example files
import matplotlib.pyplot as plt
import geoutils as gu
import numpy as np

rast = gu.Raster(gu.examples.get_path("everest_landsat_b4"))
rast.set_nodata(0)  # Annoying to have to do this here, should we update it in the example?
vect = gu.Vector(gu.examples.get_path("everest_rgi_outlines"))
# Compute proximity to vector outlines
proximity = vect.proximity(rast)
Hide the code for plotting the figure
f, ax = plt.subplots(1, 2)
ax[0].set_title("Raster and vector")
rast.plot(ax=ax[0], cmap="gray", add_cbar=False)
vect.plot(ref_crs=rast, ax=ax[0], ec="k", fc="none")
ax[1].set_title("Proximity")
proximity.plot(ax=ax[1], cmap="viridis", cbar_title="Distance to outlines (m)")
_ = ax[1].set_yticklabels([])
plt.tight_layout()
_images/caa690c090ab5d7dccef3284752fed205376206d08e353d2b16a1544934aaf48.png

Buffering without overlap#

Buffering consists in expanding or collapsing vector geometries equally in all directions. However, this can often lead to overlap between shapes, which is sometimes undesirable. Using Voronoi polygons, we provide a buffering method without overlap.

geoutils.Vector.buffer_without_overlap()

# Compute buffer without overlap from vector exterior
vect_buff_nolap = vect.buffer_without_overlap(buffer_size=500)
Hide the code for plotting the figure
# Plot with color to see that the attributes are retained for every feature
vect.plot(ax="new", ec="k", column="Area", alpha=0.5, add_cbar=False)
vect_buff_nolap.plot(column="Area", cbar_title="Buffer around initial features\ncolored by glacier area (km)")
_images/c5c1112ccd377290eab914cd8bd6a1bb6f7216f15061df6f0a20293727d8e3e9.png