Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using the following code, I make a polyline with two points.

  vl = QgsVectorLayer("LineString", layerName, "memory")
  pr = vl.dataProvider()
  fet = QgsFeature()
  fet.setGeometry( QgsGeometry.fromPolyline( [QgsPoint(x1,y1), QgsPoint(x2,y2)] ))
  pr.addFeatures( [ fet ] )

What I want is to add a line to this polyline while I keep only one id. So I can not use:

  fet.setGeometry( QgsGeometry.fromPolyline( [QgsPoint(x3,y3), QgsPoint(x4,y4)] ))

because this will save two lines with two different id's.

I can see in the QGIS API that there is a command:

    addPart (const QList< QgsPoint > &points)
    Adds a new island polygon to a multipolygon feature.

but I do not know if it works or how to use it. Does anybody have any idea how to add points or several points to an existing polygon or polyline?

share|improve this question

I made it work by using these lines of code:

geom = fet.geometry()
share|improve this answer
You're asking a lot of questions about PyQGIS-bindings. To make your answers useable/searchable for other users try to (1) accept correct answers, (2) apply the correct tags and a descriptive headline – Curlew Apr 3 '13 at 8:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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