Skip to content

Commit 2baf403

Browse files
committed
#8725R: fix invalid LineStrings
1 parent 01a733b commit 2baf403

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/core/qgsgeometry.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -4697,7 +4697,10 @@ bool QgsGeometry::exportWkbToGeos() const
46974697
}
46984698
sequence << QgsPoint( *x, *y );
46994699
}
4700-
lines << createGeosLineString( sequence );
4700+
4701+
// ignore invalid parts, it can come from ST_Simplify operations
4702+
if ( sequence.count() > 1 )
4703+
lines << createGeosLineString( sequence );
47014704
}
47024705
mGeos = createGeosCollection( GEOS_MULTILINESTRING, lines );
47034706
mDirtyGeos = false;

src/providers/postgres/qgspostgresfeatureiterator.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
370370
}
371371

372372
// query BBOX of geometries to redefine the geometries collapsed by ST_Simplify()
373-
if ( simplifyGeometry && !( P->mConnectionRO->majorVersion() >= 2 && P->mConnectionRO->minorVersion() >= 1 ) && QGis::flatType( QGis::singleType( P->geometryType() ) ) == QGis::WKBPolygon )
373+
if ( simplifyGeometry && !( P->mConnectionRO->majorVersion() >= 2 && P->mConnectionRO->minorVersion() >= 1 ) )
374374
{
375375
query += QString( ",%1(%5(%2)%3,'%4')" )
376376
.arg( P->mConnectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" )
@@ -605,7 +605,7 @@ bool QgsPostgresFeatureIterator::getFeature( QgsPostgresResult &queryResult, int
605605

606606
// fix collapsed geometries by ST_Simplify() using the BBOX fetched from the current query
607607
const QgsSimplifyMethod& simplifyMethod = mRequest.simplifyMethod();
608-
if ( mFetchGeometry && !simplifyMethod.forceLocalOptimization() && simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering && QGis::flatType( QGis::singleType( P->geometryType() ) ) == QGis::WKBPolygon )
608+
if ( mFetchGeometry && !simplifyMethod.forceLocalOptimization() && simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering )
609609
{
610610
QgsGeometry* geometry = feature.geometry();
611611

@@ -621,7 +621,21 @@ bool QgsPostgresFeatureIterator::getFeature( QgsPostgresResult &queryResult, int
621621

622622
QgsGeometry *envelope = new QgsGeometry();
623623
envelope->fromWkb( featureGeom, returnedLength + 1 );
624-
feature.setGeometry( envelope );
624+
625+
if ( QGis::flatType( QGis::singleType( P->geometryType() ) ) == QGis::WKBPolygon )
626+
{
627+
feature.setGeometry( envelope );
628+
}
629+
else
630+
{
631+
QgsPolyline polyline;
632+
polyline.append( envelope->vertexAt( 0 ) );
633+
polyline.append( envelope->vertexAt( 2 ) );
634+
delete envelope;
635+
636+
geometry = QgsGeometry::fromPolyline( polyline );
637+
feature.setGeometry( geometry );
638+
}
625639
}
626640
}
627641
}

0 commit comments

Comments
 (0)