4

I am working in QGIS console. I'd like to create new point in existing layer and using two floats as coordinates [1604288.165, 642862.0068].

feat.setGeometry(QgsGeometry.fromPointXY(coords[0], coords[1]))

But getting TypeError ((

Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "<string>", line 80, in <module>
TypeError: QgsGeometry.fromPointXY(): argument 1 has unexpected type 'float'

Into which type should I convert my coordinates?

2

1 Answer 1

4

fromPointXY creates a new geometry from a QgsPointXY object which is created by providing two coordinates:

feat.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(coords[0], coords[1])))
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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