I have a list of polygons' points like
[[x1,y1],[x2,y2],[x3,y3],[x4,y4]] [[x5,y5],[x6,y6],[x7,y7].[x8,y8]]
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 QgsGeometry.fromMultiPolygon()
?
or maybe I am wrong with something?
======================Newly Update======================================
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[0]
y=points[1]
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?
polygon_lines[0][0][0]
is[
, 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).shapes_point.txt
come from?shpae[i].points
intoshapes_points.txt