I have a list of polygons' points like
now I want to create multipolygon from it by using
feature = QgsFeature() feature.setGeometry(QgsGeometry.fromMultiPolygon([polygon_points]))
but it returns an error:
TypeError: QgsGeometry.fromMultiPolygon(): argument 1 has unexpected type 'list'
So how to make it right type for
or maybe I am wrong with something?
following is my point list
My code read this list by
read_polygon=open('shapes_point.txt','rb') polygons= polygon_lines=read_polygon.readlines() #read all polygons for line in polygon_lines: #read per polygon in polygons for points in line: #read per point in polygon x=points y=points Qgs_point=QgsPoint(float(x),float(y)) polygons.append(Qgs_point) feature = QgsFeature() feature.setGeometry(QgsGeometry.fromMultiPolygon((QgsGeometry.fromMultiPolygon([polygons for polygon in polygons]))))
and returns me the error above
I will try to make it more details
I want to read a shapefile in a dialog box, after some calculate progress, I will put values in each polygon features. The following is the main problem I have now!
I have the shapefile, and I want to fill it with color by values, but the method I only know is make a new polygon shapefile and append value to it
I don't know how to append the value in the selected polygon shapefile
So I use
feature = QgsFeature() feature.setGeometry(QgsGeometry.Polygon([polygon_points]))
but it's always crash in multipolygons
so I want to know how to make multipolygons function need?
[, not the x coordinate of the first point, as you assume. I think it would be best if you could edit your question to explain what you're actually trying to achieve (it seems like you're trying to exchange polygon data between two programs, so maybe there's a more elegant way to do that than "manually" writing the file and reading it in QGIS).