Saturday, 10 November 2018

python - How to view the features of a point with a click in QGIS


I am developing a plug-in for QGIS. I am creating a form of personalized editing using QtCreator. The form is in the following image



enter image description here


I read a csv file and when i click in a button OK I get a layer with any desired points


My goal: When I click on the "SELECT POINT" I want plot a graph with the point attributes. I see this code


   class nameform:
"""QGIS Plugin Implementation."""

def __init__(self, iface):

self.iface = iface
self.dlg.pushButtonContour.clicked.connect(self.open_contour)



self.canvas = self.iface.mapCanvas()

def open_graph(self):
self.pointEmitter = QgsMapToolEmitPoint(self.iface.mapCanvas())
QObject.connect( self.pointEmitter, SIGNAL("canvasClicked(const QgsPoint, Qt::MouseButton)"), self.selectNow)
self.iface.mapCanvas().setMapTool( self.pointEmitter )

def selectNow(self, point, button):

layer = self.iface.activeLayer()
if not layer or layer.type() != QgsMapLayer.VectorLayer:
QMessageBox.warning(None, "No!", "Select a vector layer")
return
width = self.iface.mapCanvas().mapUnitsPerPixel() * 2
rect = QgsRectangle(point.x() - width, point.y() - width, point.x() + width, point.y() + width)
rect = self.iface.mapCanvas().mapRenderer().mapToLayerCoordinates(layer, rect)
layer.select([], rect)
feat = QgsFeature()
ids = []

while layer.nextFeature(feat):
ids.append( feat.id() )
layer.setSelectedFeatures( ids )

But i have a error. When i click in select point and i pick in the point gives me this error


TypeError: arguments did not match any overloaded call:
QgsVectorLayer.select(QgsRectangle, bool): argument 1 has unexpected type 'list'
QgsVectorLayer.select(int): argument 1 has unexpected type 'list'
QgsVectorLayer.select(unknown-type): too many arguments


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...