i have a ploblem with geotiff, I want to get image coordinate in Row number and Column number.So i start to get canvas coordinate from mouse event and transform it in image coordinate (R,C) with QgsMapToPixel() class . I use the conner point of image
but it's not work. the result is not correct when i check with OpenEV. this is my code
Код: Выделить всё
def leftClicked(self,xy):
dt = "info-leftClicked"
mapCoords = self.canvas.getCoordinateTransform().toMapCoordinates(xy["x"],xy["y"])
# Get Image info
img_layers = self.iface.mapCanvas().layer(0)
extlayer = img_layers.extent()
img_height = img_layers.height()
img_width = img_layers.width()
# warp canvas
self.canvas.setExtent(extlayer)
cav_pixs = self.canvas.getCoordinateTransform() # canvas dimension
# cal canvas coordinte of image frame
c_ul = cav_pixs.transform(0,0)
c_ll = cav_pixs.transform(0,-img_height)
# cal pixel size
cc = (c_ul.y()-c_ll.y())/img_height
# Build image_frame domian from canvas coordinate
image_frame = QgsMapToPixel(cc,c_ul.y(),c_ll.y(),c_ll.x())
# find point to image coord
pix = image_frame.transform(xy["x"],xy["y"])
self.pluginGui.textEdit_X.setText(str(mapCoords.x()))
self.pluginGui.textEdit_Y.setText(str(mapCoords.y()))
#-----
#self.pluginGui.textEdit_X.setText(str(xy["x"]))
#self.pluginGui.textEdit_Y.setText(str(xy["y"]))
self.pluginGui.textEdit_mX.setText(str(float(pix.x()))
self.pluginGui.textEdit_mY.setText(str(float(pix.y()))
Somebody know how i get the image coordinate at mouse event from the geotiff
thanks