Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

  vl = QgsVectorLayer("LineString", layerName, "memory")
  pr = vl.dataProvider()
  vl.startEditing()
  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
add comment

1 Answer

I made it work by using these lines of code:

geom = fet.geometry()
geom.insertVertex(x4,y4,len(geom.asPolyline()))
fet.setGeometry(geom)
share|improve this answer
2  
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
add comment

Your Answer

 
discard

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.