GlacioHack / geoutils

Analysis of georeferenced rasters and vectors
https://geoutils.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
86 stars 19 forks source link

Export an elevation profile from a Raster along a Vector line. #591

Open Falawiss opened 4 months ago

Falawiss commented 4 months ago

Is your feature request related to a problem? Please describe. This is not related to a problem, but it is a feature that I have developed for myself after searched for an existing solution in other libraries.

Describe the solution you'd like I want to trace Line, Polyline or MultiLines on a Vector file. Then import this file (gu.Vector) and export all the encountered values where theses lines cross a Raster. Then we can plot theses profiles along a distance array. See this example :

import matplotlib.pyplot as plt
import geoutils as gu
profiles_axis = gu.Vector('profiles_axis.gpkg')
raster = gu.Raster('raster.tif')

distances, profiles = raster.extract_profile(profiles_axis)

for i in range(len(distances)) : 
    plt.plot(distances[i], profiles[i])
plt.show()

Describe alternatives you've considered In my project I use start and end points, to select Rasters values over the segment delimited by these two points.

Additional context An example of the profiles that I have traced on few DEMs along 2 tracks. These two tracks are defined by a starting and ending point, extracted from a gu.Vector file using

profiles_axis_gpkg = gu.Vector('profiles_axis.gpkg')
for line in profiles_axis_gpkg.ds.geometry :
        coords = list(line.coords)

See an example result : Profils_fortes-pentes_Ossoue

adehecq commented 4 months ago

Hi, I agree, this would be a useful functionality that many people would use. This would not be too complicated to implement, using our point interpolation.

If you feel like making a contribution to the code, feel free to submit a pull request 😉 Otherwise, we'll look into this but don't expect anything before the end of summer!

Falawiss commented 4 months ago

Cool ! I will maybe give it a try in the summer.