0

I want to extract the elevation at any point in longitude/latitude from GeoTIFF, similar to Global Mapper. Using GDAL and rasterio, I get an image with a size of (6000, 6000) points. And the distance between each point, when translated into meters, is 90 meters, and I need a step between the points of 10 meters. Is it possible using raster libraries to get a result where the elevation is calculated based on the gradient of the raster, as Global Mapper does?

I use simple code:

from osgeo import gdal
import os
import geopy.distance

gdal_data = gdal.Open("./n50e045_dem.tif", gdal.GA_ReadOnly)
raster_band = gdal_data.GetRasterBand(1)
raster = raster_band.ReadAsArray()
print(raster.size, raster.shape)  
>>> 36000000 (6000, 6000)


width = gdal_data.RasterXSize
height = gdal_data.RasterYSize
i_x = 4315
i_y = 861
X = gt[0] + i_x*gt[1] + i_y*gt[2]
Y = gt[3] + i_x*gt[4] + i_y*gt[5]
Z = raster[i_y, i_x] # in array elevations
coords_1 = (54.282916666666665, 48.595416666666665)
coords_2 = (Y, X)
print (geopy.distance.geodesic(coords_1, coords_2).m)  
>>> 92.75854901199543

I need 10 meters instead of 90.

3
  • 1
    Welcome to GIS SE. As a new user, please take the Tour. It is not possible to express a uniform conversion of degrees to meters, because all the meridians converge at the poles and even latitudes are not uniform due to oblateness. You can interpolate across three arc-second pixels, but the results are far from perfect. "Is it possible?" questions ask the wrong question -- what you really want is "How is it possible to..." We expect that your Question will include what you've tried.
    – Vince
    Commented Sep 17, 2022 at 14:22
  • 1
    Does this answer your question? Extracting data from a raster
    – snowman2
    Commented Sep 17, 2022 at 15:59
  • I don't think this is a duplicate. The desired result seems to be an interpolation of Z values between cell centroids (e.g. 1, 2).
    – user2856
    Commented Sep 18, 2022 at 9:35

1 Answer 1

0

I recommend first resampling the raster to 10 meters, then extract the points.

Step 1: Resample raster to 10 meters

Step 2: Extract data Extracting data from a raster

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.