I have one raster layer and point vector layer. I want to measure distance between center of each pixel in raster to each point in vector layer. I extracted x,y center of each cell and added them to a list, but I can't make a relation between this list and vector points to calculate distances. How can I measure distances?
from qgis.core import *
from osgeo import gdal, ogr, osr
pntLayer = QgsVectorLayer("/Data/Villages.shp","pointLayer")
feat = [ feat for feat in pntLayer.getFeatures() ]
# Open tif file
ds = QgsRasterLayer("/Data/Study.tif","Study")
pixelWidth = ds.rasterUnitsPerPixelX()
pixelHeight = ds.rasterUnitsPerPixelY()
# extent of the layer
ext = ds.extent()
originX ,originY = (ext.xMinimum(),ext.yMinimum())
src_cols = ds.width()
src_rows = ds.height()
outDs = drive.Create("/Data/pop_Rst.tif", src_cols, src_rows, 1, gdal.GDT_Float32)
outBand = outDs.GetRasterBand(1)
outData = numpy.zeros((src_cols, src_rows), numpy.float32)
def pixel2coord(x, y):
xp = (pixelWidth * x) + originX + (pixelWidth/2)
yp = (pixelHeight * y) + originY + (pixelHeight /2)
return(xp, yp)
pntRstList = []
for i in range(0, src_cols):
for j in range(0, src_rows):
rspnt = pixel2coord(i,j)
pntRstList.append(rspnt)
print pntRstList
distas a variable, for example. – mgri Jul 06 '17 at 08:27pntRstList.append(QgsPoint(rspnt))instead of what you provided? – mgri Jul 06 '17 at 08:43