TransWikia.com

Haversine based distance transform

Geographic Information Systems Asked on November 11, 2020

I have a binary image with pixel resolution in units of degrees (EPSG:4326):

enter image description here

In this case, all the light-blue pixels are water (value = 1) and purple pixels are not water (value = 0). I would like to compute a distance transform of this image, where the result is each pixel’s distance away from the nearest "on" (water) pixel. This is doable with scipy:

enter image description here

However, the returned distances are Euclidean with respect to the row, column coordinates of each pixel. Does anyone know of a package or function that will compute a distance transform using the Haversine formula on the lon, lat coordinates rather than the row, col coordinates?

[I know I can reproject to a length-preserving CRS and multiply by the resolution.]

One Answer

I would follow these steps:

  • Create points from individual pixel's center, assign each pixel value and coordinate of its center to the corresponding point. Review this post. (rasterio, geopandas)
  • Collect all water points to one multipoint object. (geopandas)
  • Calculate haversine distance between a point and the multipoint and assign the distance to the point. In this step, the result is each point's distance away from the nearest point in the multipoint (water points). Review this post. (geopandas/shapely)
  • Create new raster from points' value (based-on source raster properties)

Since there will be millions of points for high resolution raster, this method will be time-consuming.

Answered by Kadir Şahbaz on November 11, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP