I've retrieved some attributes and coordinates from a point layer in QGIS:
path_file = myfile
layer = QgsVectorLayer(path_file, "name", "ogr")
QgsProject.instance().addMapLayer(layer)
features = layer.getFeatures()
for f in features:
point = f.geometry().asPoint()
x = point.x()
y = point.y()
and I'd like to export "ID"
, "x"
, and "y"
values into a CSV file, possibly one for a column. I tried with .write()
but couldn't get a good output. Any help?
print("ID: %d; XY coordinates: %f, %f" % (f['ID'], x, y))
, but maybe I didn' get the point of your comment