2

I am using the QgsMapToolEmitPoint and QgsMapToolIdentifyFeature classes in my QGIS project.

I created 2 variables:

self.pointTool = QgsMapToolEmitPoint (self.canvas)
self.linetool = QgsMapToolIdentifyFeature (self.canvas)

The first variable connects to a function that generates lines in a layer. Next, I call the second function, which identifies the end point of the lines where I click.

My problem is, after making a line, calling the second function:

self.pointTool.canvasClicked.connect (self.criar_line)
self.linetool.featureIdentified.connect (self.identify)

this function captures the end point of the line created earlier, but I don't want that. I want to choose the line I want to capture the endpoint.

0

Make sure you are catching the feature object which is passed by the featureIdentified signal, and using it when you define your self.identify slot function like this:

def identify(self, feat):
    geom = feat.geometry().constGet()[0]
    end_point = QgsPointXY(geom[-1])
    X = end_point.x()
    Y = end_point.y()
    # do something with end_point, X, or Y

Also, make sure your identify tool has the correct layer set to it, either by passing the layer object to the class constructor:

self.linetool = QgsMapToolIdentifyFeature(self.canvas, self.layer)

or by using the setLayer() method:

self.linetool.setLayer(self.layer)

Where self.layer is the QgsVectorLayer object of your line layer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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