# Extract a cutline from VRT file in world coordinates?

I'm trying to extract the world coordinates of a cutline (clipping polygon) in a GDAL VRT file. Unfortunately, the cutline is stored in image coordinates (pixels), and i could not find the right method to transform it into world coordinates.

The following python functions didn't help:

``````def Pixel2world(geoMatrix, x, y):
ulX = geoMatrix
ulY = geoMatrix
xDist = geoMatrix
yDist = geoMatrix
coorX = (ulX + (x * xDist))
coorY = (ulY + (y * yDist))
return (coorX, coorY)

def Pixel2coord(geoMatrix, x, y):
"""Returns global coordinates from pixel x, y coords"""
xoff, a, b, yoff, d, e = geoMatrix
xp = a * x + b * y + xoff
yp = d * x + e * y + yoff
return(xp, yp)

raster=r'virtual_raster.vrt'
ds=gdal.Open(raster)

gt=ds.GetGeoTransform()
print Pixel2coord(gt,1000,1000) #=> Returns wrong coordinates
print Pixel2world(gt,1000,1000) #=> Returns wrong coordinates
``````

BTW: due to a coordinate transformation inside the VRT from EPSG:31255 to EPSG:3857, the resulting image is shifted and rotated. And (geoMatrix,geoMatrix) does contain the upper left corner of the cutted image and not the uncutted one.

Has anyone successfully extracted a VRT cutline in world coordinates?

The image/raster coordinates of a point x,y (world coordinates) are

``````gt = (263104.72544800001, 10.002079999999999, 0.0, 155223.647811, 0.0, -10.002079999999999)
x,y  = (263220.5,155110.6)
rasterx = (x - gt) / gt
rastery = (y - gt) / gt
print rasterx,rastery
11.5750475901 11.3024301945
``````

This allows to extract the value of the pixel at coordinate x, y (a = number of band 1,2, 3)

``````layer.GetRasterBand(a).ReadAsArray(int(rasterx),int(rastery), 1, 1)
``````

Therefore, if you have the image coordinates (rasterx, rastery)

``````x = rasterx * gt + gt
y = rastery * gt + gt
print x, y
263220.5 155110.6
``````
• Maybe that's correct for images/rasters that are not clipped. But for my VRT cutline it doesn't work. (gt,gt) is not the origin of the original image, it's the origin of the clipped image. And the cutline seems to have the original image coordinates. – christoph Feb 11 '16 at 9:45