Created
August 19, 2022 19:00
-
-
Save evandiewald/15f0a8f09f43b65954e4d5fce31526de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_elevation_profile_of_segment(dataset: rasterio.DatasetReader, coords: list[list]): | |
""" | |
Get the elevation profile (distance vs. altitude) of a path segment from the list of coordinates. | |
Args: | |
dataset: The opened rasterio dataset for the SRTM global topography data. | |
coords: The path coordinates in [[lon1, lat1], [lon2, lat2], ...] format. | |
Returns: The distance (in miles) and elevation (in feet) vectors. | |
""" | |
# coordinates are [lon, lat], flip for rasterio | |
coords = [[c[1], c[0]] for c in coords] | |
# convert meters to feet and use rasterio.sample.sample_gen to query each point | |
elev = [e[0] * 3.28084 for e in sample_gen(dataset, coords)] | |
d = [0.0] | |
for j in range(len(coords) - 1): | |
# use haversine distance | |
d.append(d[j] + haversine((coords[j][1], coords[j][0]), (coords[j + 1][1], coords[j + 1][0]), Unit.MILES)) | |
return d, elev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment