2

When I modify the code (which works) from:

vertices = fProject.geometry().asMultiPolygon()
for v in vertices:
    points.append(v)
fet.setGeometry(QgsGeometry.fromMultiPolygonXY(points))

to:

pt = QgsPointXY(92.5,22.5)
points.append(pt)
pt = QgsPointXY(93.5,22.5)
points.append(pt)
pt = QgsPointXY(93.5,23.5)
points.append(pt)
fet.setGeometry(QgsGeometry.fromMultiPolygonXY(points))

throws an error: TypeError: QgsGeometry.fromMultiPolygonXY(): argument 1 has unexpected type 'list'

  • Where does vertices come from? What's the type of v in the loop for v in vertices? – Matthias Kuhn Jan 16 at 11:10
  • vertices = fProject.geometry().asMultiPolygon() @MatthiasKuhn – abhijeet pillai Jan 16 at 11:15
2

Replace the last line of your code with the last line of the following code.

fet = QgsFeature()
pt = QgsPointXY(92.5,22.5)
points.append(pt)
pt = QgsPointXY(93.5,22.5)
points.append(pt)
pt = QgsPointXY(93.5,23.5)
points.append(pt)
fet.setGeometry(QgsGeometry.fromMultiPolygonXY([[points]]))
| improve this answer | |
  • 1
    Thanks a lot @Vincent Bré. The code worked :) – abhijeet pillai Jan 16 at 11:18
  • You're welcome ! You can approve my answer if it's solved your problem. Have a nice day. – Vincent Bré Jan 16 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.