Skip to content

Commit 1cb067b

Browse files
olivierdalangnyalldawson
authored andcommittedAug 30, 2020
[virtual layers] support curved geometries (segmentized)
1 parent 71d0948 commit 1cb067b

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed
 

‎src/providers/virtual/qgsvirtuallayerblob.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ void qgsGeometryToSpatialiteBlob( const QgsGeometry &geom, int32_t srid, char *&
6767
{
6868
const int header_len = SpatialiteBlobHeader::LENGTH;
6969

70-
QByteArray wkb( geom.asWkb() );
70+
// we segment the geometry as spatialite doesn't support curves
71+
std::unique_ptr < QgsAbstractGeometry > segmentized( geom.constGet()->segmentize() );
72+
QByteArray wkb( segmentized->asWkb() );
7173

7274
const int wkb_size = wkb.length();
7375
size = header_len + wkb_size;

‎src/providers/virtual/qgsvirtuallayersqlitemodule.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,17 @@ struct VTable
219219
}
220220

221221
QgsVectorDataProvider *provider = mLayer ? mLayer->dataProvider() : mProvider;
222-
if ( provider->wkbType() != QgsWkbTypes::NoGeometry )
222+
223+
// spatialite doesn't support curved geometries, it will be converted to linear in qgsGeometryToSpatialiteBlob
224+
QgsWkbTypes::Type layerType = QgsWkbTypes::linearType( provider->wkbType() );
225+
226+
if ( layerType != QgsWkbTypes::NoGeometry )
223227
{
224228
// we have here a convenient hack
225229
// the type of a column can be declared with two numeric arguments, usually for setting numeric precision
226230
// we are using them to set the geometry type and srid
227231
// these will be reused by the provider when it will introspect the query to detect types
228-
sqlFields << QStringLiteral( "geometry geometry(%1,%2)" ).arg( provider->wkbType() ).arg( provider->crs().postgisSrid() );
232+
sqlFields << QStringLiteral( "geometry geometry(%1,%2)" ).arg( layerType ).arg( provider->crs().postgisSrid() );
229233

230234
// add a hidden field for rtree filtering
231235
sqlFields << QStringLiteral( "_search_frame_ HIDDEN BLOB" );

‎tests/src/python/test_provider_virtual.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,11 @@ def test_geometryTypes(self):
357357
(3, "POLYGON", "((0 0,1 0,1 1,0 0))"),
358358
(4, "MULTIPOINT", "((1 1))"),
359359
(5, "MULTILINESTRING", "((0 0,1 0),(0 1,1 1))"),
360-
(6, "MULTIPOLYGON", "(((0 0,1 0,1 1,0 0)),((2 2,3 0,3 3,2 2)))")]
360+
(6, "MULTIPOLYGON", "(((0 0,1 0,1 1,0 0)),((2 2,3 0,3 3,2 2)))"),
361+
(9, "COMPOUNDCURVE", "(CIRCULARSTRING(0 0, 1 0, 1 1))"),
362+
(10, "CURVEPOLYGON", "(COMPOUNDCURVE(CIRCULARSTRING(0 0, 1 0, 1 1)))"),
363+
(11, "MULTICURVE", "(COMPOUNDCURVE(CIRCULARSTRING(0 0, 1 0, 1 1)),COMPOUNDCURVE(CIRCULARSTRING(2 2, 3 2, 3 3)))"),
364+
(12, "MULTISURFACE", "(CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(0 0, 1 0, 1 1))),CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(2 2, 3 2, 3 3))))")]
361365
for wkb_type, wkt_type, wkt in geo:
362366
l = QgsVectorLayer("%s?crs=epsg:4326" % wkt_type, "m1", "memory", QgsVectorLayer.LayerOptions(False))
363367
self.assertEqual(l.isValid(), True)
@@ -372,7 +376,13 @@ def test_geometryTypes(self):
372376
l2 = QgsVectorLayer("?layer_ref=%s" % l.id(), "vtab", "virtual", QgsVectorLayer.LayerOptions(False))
373377
self.assertEqual(l2.isValid(), True)
374378
self.assertEqual(l2.dataProvider().featureCount(), 1)
375-
self.assertEqual(l2.dataProvider().wkbType(), wkb_type)
379+
# we ensure the geom type matches the original (semgentized) type
380+
self.assertEqual(l2.dataProvider().wkbType(), QgsWkbTypes.linearType(wkb_type))
381+
382+
# we ensure the geometry still matches the original (segmentized) geometry
383+
f2 = QgsFeature()
384+
l2.getFeatures().nextFeature(f2)
385+
self.assertEqual(f2.geometry().asWkt(), f1.geometry().constGet().segmentize().asWkt())
376386

377387
QgsProject.instance().removeMapLayer(l.id())
378388

0 commit comments

Comments
 (0)
Please sign in to comment.