[Qgis-user] Creating Polygon Vector Layer from specific .csv file
Marcin
prokes95 at interia.pl
Sat Mar 21 15:39:13 PDT 2020
Hi folks,
QGIS 3.10
I would like to create polygons (see 4 corners everyone) with Python form .csv like that:
LP CORNER Y X
1 1 51.558868 21.696985
1 2 51.596337 21.745589
1 3 51.603166 21.727687
1 4 51.565424 21.682416
2 1 51.590928 21.760442
2 2 51.553125 21.709847
2 3 51.559536 21.6959
2 4 51.598023 21.742078
3 1 51.548047 21.724327
3 2 51.586238 21.773843
3 3 51.593172 21.756185
3 4 51.554643 21.709932
According to QGIS Python Programming Cookbook
I know how to load csv file:
uri = "D:/PODYPLOM/plikiCSVtoSHPviaPythonpokrycieCSV.csv?"
uri += "type=csv&"
uri += "xField=X&yField=Y&"
uri += "spatialIndex=no&"
uri += "subsetIndex=no&"
uri += "watchFile=no&"
uri += "crs=epsg:4326"
layer=QgsVectorLayer(uri,"Tourism Sites","delimitedtext")
QgsProject.instance().addMapLayers([layer])
and I know how to create polygon layer from points added by finger:
vectorLyr = QgsVectorLayer('D:/qgis_data/polygon/polygon.shp', 'Polygon', "ogr")
vpr = vectorLyr.dataProvider()
points = []
points.append(QgsPointXY(-123.26,49.06))
points.append(QgsPointXY(-127.19,43.07))
points.append(QgsPointXY(-120.70,35.21))
points.append(QgsPointXY(-115.89,40.02))
points.append(QgsPointXY(-123.26,49.06))
poly = QgsGeometry.fromPolygonXY([points])
f = QgsFeature()
f.setGeometry(poly)
vpr.addFeatures([f])
vectorLyr.updateExtents()
but I can't load points from csv to line: points.append(QgsPointXY())
Anybody can help me how to do this ?
Cheers, Marcin Pietruszewski
More information about the Qgis-user
mailing list