I'm trying to find a function in Python, that given two arrays with geographic coordinates, returns a list or array of raster values in those positions. that is to say:

import numpy as np
"""geog coordinates on x axis """
xc = [878571.041, 878583.54109659, 878596.04119319]
""" geographical coordinates on y axis """
yc = [187189.14, 187176.64015077, 187164.14030153]
"""list to array"""
x = np.array (xc)
y = np.array (yc)
"""raster values at those coordinates"""
z = function (x y) 
z = function (xc, yc)

The output I expect is an array with raster values in the x, y positions. Is there a function in GDAL, Python or any other library that allows me to do this? Or must I necessarily use a for loop to obtain these values.

1 Answer 1


You should be able do this in rasterio with sample:

with rasterio.open("example.tif") as src:
    values = np.array(src.sample(zip(Xc, Yc)))

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.