Skip to content

Commit c962ad2

Browse files
authoredSep 17, 2018
Merge pull request #7868 from m-kuhn/geosErrorTranslation
Translate GEOS errors
2 parents f2e0b6a + 5fef039 commit c962ad2

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed
 

‎src/core/qgsgeometryvalidator.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void QgsGeometryValidator::validatePolygon( int idx, const QgsPolygonXY &polygon
187187
{
188188
if ( !ringInRing( polygon[i], polygon[0] ) )
189189
{
190-
QString msg = QObject::tr( "ring %1 of polygon %2 not in exterior ring" ).arg( i ).arg( idx );
190+
QString msg = QObject::tr( "Ring %1 of polygon %2 not in exterior ring" ).arg( i ).arg( idx );
191191
QgsDebugMsg( msg );
192192
emit errorFound( QgsGeometry::Error( msg ) );
193193
mErrorCount++;
@@ -230,6 +230,28 @@ void QgsGeometryValidator::run()
230230
char res = GEOSisValidDetail_r( handle, g0.get(), GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g1 );
231231
if ( res != 1 )
232232
{
233+
static QgsStringMap translatedErrors;
234+
235+
if ( translatedErrors.empty() )
236+
{
237+
// Copied from https://git.osgeo.org/gitea/geos/geos/src/branch/master/src/operation/valid/TopologyValidationError.cpp
238+
translatedErrors.insert( QStringLiteral( "topology validation error" ), QObject::tr( "Topology validation error", "GEOS Error" ) );
239+
translatedErrors.insert( QStringLiteral( "repeated point" ), QObject::tr( "Repeated point", "GEOS Error" ) );
240+
translatedErrors.insert( QStringLiteral( "hole lies outside shell" ), QObject::tr( "Hole lies outside shell", "GEOS Error" ) );
241+
translatedErrors.insert( QStringLiteral( "holes are nested" ), QObject::tr( "Holes are nested", "GEOS Error" ) );
242+
translatedErrors.insert( QStringLiteral( "interior is disconnected" ), QObject::tr( "Interior is disconnected", "GEOS Error" ) );
243+
translatedErrors.insert( QStringLiteral( "self-intersection" ), QObject::tr( "Self-intersection", "GEOS Error" ) );
244+
translatedErrors.insert( QStringLiteral( "ring self-intersection" ), QObject::tr( "Ring self-intersection", "GEOS Error" ) );
245+
translatedErrors.insert( QStringLiteral( "nested shells" ), QObject::tr( "Nested shells", "GEOS Error" ) );
246+
translatedErrors.insert( QStringLiteral( "duplicate rings" ), QObject::tr( "Duplicate rings", "GEOS Error" ) );
247+
translatedErrors.insert( QStringLiteral( "too few points in geometry component" ), QObject::tr( "Too few points in geometry component", "GEOS Error" ) );
248+
translatedErrors.insert( QStringLiteral( "invalid coordinate" ), QObject::tr( "Invalid coordinate", "GEOS Error" ) );
249+
translatedErrors.insert( QStringLiteral( "ring is not closed" ), QObject::tr( "Ring is not closed", "GEOS Error" ) );
250+
}
251+
252+
const QString errorMsg( r );
253+
const QString translatedErrorMsg = translatedErrors.value( errorMsg.toLower(), errorMsg );
254+
233255
if ( g1 )
234256
{
235257
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( handle, g1 );
@@ -240,15 +262,16 @@ void QgsGeometryValidator::run()
240262
double x, y;
241263
GEOSCoordSeq_getX_r( handle, cs, 0, &x );
242264
GEOSCoordSeq_getY_r( handle, cs, 0, &y );
243-
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error: %1" ).arg( r ), QgsPointXY( x, y ) ) );
265+
266+
emit errorFound( QgsGeometry::Error( translatedErrorMsg, QgsPointXY( x, y ) ) );
244267
mErrorCount++;
245268
}
246269

247270
GEOSGeom_destroy_r( handle, g1 );
248271
}
249272
else
250273
{
251-
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error: %1" ).arg( r ) ) );
274+
emit errorFound( QgsGeometry::Error( translatedErrorMsg ) );
252275
mErrorCount++;
253276
}
254277

@@ -290,7 +313,7 @@ void QgsGeometryValidator::run()
290313
{
291314
if ( mp[i].isEmpty() )
292315
{
293-
emit errorFound( QgsGeometry::Error( QObject::tr( "polygon %1 has no rings" ).arg( i ) ) );
316+
emit errorFound( QgsGeometry::Error( QObject::tr( "Polygon %1 has no rings" ).arg( i ) ) );
294317
mErrorCount++;
295318
continue;
296319
}
@@ -302,12 +325,12 @@ void QgsGeometryValidator::run()
302325

303326
if ( ringInRing( mp[i][0], mp[j][0] ) )
304327
{
305-
emit errorFound( QgsGeometry::Error( QObject::tr( "polygon %1 inside polygon %2" ).arg( i ).arg( j ) ) );
328+
emit errorFound( QgsGeometry::Error( QObject::tr( "Polygon %1 lies inside polygon %2" ).arg( i ).arg( j ) ) );
306329
mErrorCount++;
307330
}
308331
else if ( ringInRing( mp[j][0], mp[i][0] ) )
309332
{
310-
emit errorFound( QgsGeometry::Error( QObject::tr( "polygon %1 inside polygon %2" ).arg( j ).arg( i ) ) );
333+
emit errorFound( QgsGeometry::Error( QObject::tr( "Polygon %1 lies inside polygon %2" ).arg( j ).arg( i ) ) );
311334
mErrorCount++;
312335
}
313336
else
@@ -320,7 +343,6 @@ void QgsGeometryValidator::run()
320343

321344
else if ( flatType == QgsWkbTypes::Unknown )
322345
{
323-
QgsDebugMsg( QObject::tr( "Unknown geometry type" ) );
324346
emit errorFound( QgsGeometry::Error( QObject::tr( "Unknown geometry type %1" ).arg( mGeometry.wkbType() ) ) );
325347
mErrorCount++;
326348
}

0 commit comments

Comments
 (0)
Please sign in to comment.