Skip to main content
deleted 16 characters in body; edited tags; edited title
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

Inputting Using coordinates from mouse click intofor QgsPointXY when creating point using PyQGIS

I have this code so far, but I can not figure out how to input the coordinates through a mouse click instead of the code below. I am trying to create a temporary layer of a point from a mouse click. Everything seems to work except for that I can not figure the coordinates out. I am also still very new to PyQGIS.

vl = QgsVectorLayer("Point", "POI", "memory")
from qgis.PyQt.QtCore import QVariant
pr = vl.dataProvider()
pr.addAttributes([QgsField("ID", QVariant.String)])
vl.updateFields() 
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(10,10)))
f.setAttributes(["1"])

pr.addFeature(f)
vl.updateExtents() 
QgsProject.instance().addMapLayer(vl)
from qgis.PyQt.QtCore import QVariant

vl = QgsVectorLayer("Point", "POI", "memory")    
pr = vl.dataProvider()
pr.addAttributes([QgsField("ID", QVariant.String)])
vl.updateFields() 
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(10,10)))
f.setAttributes(["1"])

pr.addFeature(f)
vl.updateExtents() 
QgsProject.instance().addMapLayer(vl)

Inputting coordinates from mouse click into QgsPointXY when creating point using PyQGIS

I have this code so far, but I can not figure out how to input the coordinates through a mouse click instead. I am trying to create a temporary layer of a point from a mouse click. Everything seems to work except for that I can not figure the coordinates out. I am also still very new to PyQGIS.

vl = QgsVectorLayer("Point", "POI", "memory")
from qgis.PyQt.QtCore import QVariant
pr = vl.dataProvider()
pr.addAttributes([QgsField("ID", QVariant.String)])
vl.updateFields() 
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(10,10)))
f.setAttributes(["1"])

pr.addFeature(f)
vl.updateExtents() 
QgsProject.instance().addMapLayer(vl)

Using coordinates from mouse click for QgsPointXY when creating point using PyQGIS

I can not figure out how to input the coordinates through a mouse click instead of the code below. I am trying to create a temporary layer of a point from a mouse click. Everything seems to work except for that I can not figure the coordinates out.

from qgis.PyQt.QtCore import QVariant

vl = QgsVectorLayer("Point", "POI", "memory")    
pr = vl.dataProvider()
pr.addAttributes([QgsField("ID", QVariant.String)])
vl.updateFields() 
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(10,10)))
f.setAttributes(["1"])

pr.addFeature(f)
vl.updateExtents() 
QgsProject.instance().addMapLayer(vl)
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

How to input Inputting coordinates from mouse click into QgsPointXY when creating a point using PyQgis?PyQGIS

added 48 characters in body
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

I have this code so far, but I can not figure out how to input the coordinates through a mouse click instead. I am trying to create a temporary layer of a point from a mouse click. Everything seems to work except for that I can not figure the coordinates out. I am also still very new to PyQGIS.

vl = QgsVectorLayer("Point", "POI", "memory") from qgis.PyQt.QtCore import QVariant pr = vl.dataProvider() pr.addAttributes([QgsField("ID", QVariant.String)]) vl.updateFields() f = QgsFeature() f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(10,10))) f.setAttributes(["1"])

pr.addFeature(f) vl.updateExtents() QgsProject.instance().addMapLayer(vl)

vl = QgsVectorLayer("Point", "POI", "memory")
from qgis.PyQt.QtCore import QVariant
pr = vl.dataProvider()
pr.addAttributes([QgsField("ID", QVariant.String)])
vl.updateFields() 
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(10,10)))
f.setAttributes(["1"])

pr.addFeature(f)
vl.updateExtents() 
QgsProject.instance().addMapLayer(vl)

I have this code so far, but I can not figure out how to input the coordinates through a mouse click instead. I am trying to create a temporary layer of a point from a mouse click. Everything seems to work except for that I can not figure the coordinates out. I am also still very new to PyQGIS.

vl = QgsVectorLayer("Point", "POI", "memory") from qgis.PyQt.QtCore import QVariant pr = vl.dataProvider() pr.addAttributes([QgsField("ID", QVariant.String)]) vl.updateFields() f = QgsFeature() f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(10,10))) f.setAttributes(["1"])

pr.addFeature(f) vl.updateExtents() QgsProject.instance().addMapLayer(vl)

I have this code so far, but I can not figure out how to input the coordinates through a mouse click instead. I am trying to create a temporary layer of a point from a mouse click. Everything seems to work except for that I can not figure the coordinates out. I am also still very new to PyQGIS.

vl = QgsVectorLayer("Point", "POI", "memory")
from qgis.PyQt.QtCore import QVariant
pr = vl.dataProvider()
pr.addAttributes([QgsField("ID", QVariant.String)])
vl.updateFields() 
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(10,10)))
f.setAttributes(["1"])

pr.addFeature(f)
vl.updateExtents() 
QgsProject.instance().addMapLayer(vl)
Source Link
Al110
  • 35
  • 3
Loading