Skip to content

Commit 2f702b7

Browse files
committed
Translate GEOS errors
1 parent d7fb5f9 commit 2f702b7

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/core/qgsgeometryvalidator.cpp

+25-2
Original file line numberDiff line numberDiff line change
@@ -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, 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

0 commit comments

Comments
 (0)