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.

I what to create many lines with this code:

v_layer = QgsVectorLayer("LineString", "cable", "memory")
pr = v_layer.dataProvider()
seg = QgsFeature()
seg.setGeometry(QgsGeometry.fromPolyline([line_start, geomPoint]))
pr.addFeatures( [ seg ] )
v_layer.updateExtents()
QgsMapLayerRegistry.instance().addMapLayers([v_layer])

Buth this create one layer for each of this code.

How can I create all in one layer.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

you need to add all the geometries before the addMapLayers

v_layer = QgsVectorLayer("LineString", "cable", "memory")
pr = v_layer.dataProvider()
# first element
seg = QgsFeature()
seg.setGeometry(QgsGeometry.fromPolyline([line_start, geomPoint]))
pr.addFeatures( [ seg ] )
v_layer.updateExtents()
# second element
seg = QgsFeature()
seg.setGeometry(QgsGeometry.fromPolyline([geomPoint, newgeomPoint]))
pr.addFeatures( [ seg ] )
v_layer.updateExtents()
# etc
......
QgsMapLayerRegistry.instance().addMapLayers([v_layer])

so use a for loop

share|improve this answer
    
Thats it, Thank you –  user1573901 May 21 '13 at 11:10
    
@user1573901 Please upvote useful answers and accept answers that solve your problem (by clicking the tick mark on the left). –  underdark May 21 '13 at 11:41
    
Ok, I did not know, thanks! –  user1573901 May 21 '13 at 12:14
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.