I like a write a script which:
- Imports a CSV file that contains a series of points (latitude and longitude) into QGIS
Here are the points when I import them into the QGIS. I want to create one polygon using these points.
- Create a polygon from imported points and finally create a shapefile.
Here is how I did part 1:
uri = "file:///C:/Users/katala/Desktop/PyQGIS/Tailings Pond 1A.csv?encoding=%s&delimiter=%s&xField=%s&yField=%s&crs=%s" % ("UTF-8",",", "Lat", "Long","epsg:4326") #Make a vector layer eq_layer=QgsVectorLayer(uri,"eq-data","delimitedtext") #Check if layer is valid if not eq_layer.isValid(): print ("Layer not loaded") #Add CSV data QgsProject.instance().addMapLayer(eq_layer)
But I don't know how to do the second part and create a polygon. I found the following code, but I don't know how to adjust it to read the points from the generated vector layer.