6

I am trying to create a closed LineString made of a number of CircularSrings, but have got stuck. I cannot see how to add the geometry from both strings.

This is what I have so far. QGIS version 3.4.2

from qgis.PyQt.QtCore import QVariant

vl = QgsVectorLayer("LineString", "temp", "memory")

pr = vl.dataProvider() pr.addAttributes([QgsField("name", QVariant.String)]) vl.updateFields() cString1 = QgsCircularString.fromTwoPointsAndCenter(QgsPoint(306580,167317),QgsPoint(306680,167317),QgsPoint(306680,167217)) cString2 = QgsCircularString.fromTwoPointsAndCenter(QgsPoint(306680,167317),QgsPoint(306580,167317),QgsPoint(306680,167417))

geom_cString1 = QgsGeometry(cString1) geom_cString2 = QgsGeometry(cString2) f = QgsFeature() f.setGeometry(geom_cString1) f.setAttributes(["One"]) pr.addFeature(f) vl.updateExtents() QgsProject.instance().addMapLayer(vl)

Taras
  • 32,823
  • 4
  • 66
  • 137
Tilson
  • 171
  • 5

1 Answers1

5

Static collectGeometry method of QgsGeometry class performs what you need.

...
geom_cString1=QgsGeometry(cString1)
geom_cString2=QgsGeometry(cString2)

geom = QgsGeometry().collectGeometry([geom_cString1, geom_cString2])

f = QgsFeature() f.setGeometry(geom) ...

The closed ring in the image is one LineString geometry.

enter image description here

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389