Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#8725R: fix invalid LineStrings
  • Loading branch information
ahuarte47 committed Jan 22, 2014
1 parent 01a733b commit 2baf403
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/core/qgsgeometry.cpp
Expand Up @@ -4697,7 +4697,10 @@ bool QgsGeometry::exportWkbToGeos() const
}
sequence << QgsPoint( *x, *y );
}
lines << createGeosLineString( sequence );

// ignore invalid parts, it can come from ST_Simplify operations
if ( sequence.count() > 1 )
lines << createGeosLineString( sequence );
}
mGeos = createGeosCollection( GEOS_MULTILINESTRING, lines );
mDirtyGeos = false;
Expand Down
20 changes: 17 additions & 3 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Expand Up @@ -370,7 +370,7 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
}

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

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

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

QgsGeometry *envelope = new QgsGeometry();
envelope->fromWkb( featureGeom, returnedLength + 1 );
feature.setGeometry( envelope );

if ( QGis::flatType( QGis::singleType( P->geometryType() ) ) == QGis::WKBPolygon )
{
feature.setGeometry( envelope );
}
else
{
QgsPolyline polyline;
polyline.append( envelope->vertexAt( 0 ) );
polyline.append( envelope->vertexAt( 2 ) );
delete envelope;

geometry = QgsGeometry::fromPolyline( polyline );
feature.setGeometry( geometry );
}
}
}
}
Expand Down

0 comments on commit 2baf403

Please sign in to comment.