diff --git a/python/core/auto_generated/providers/arcgis/qgsarcgisrestutils.sip.in b/python/core/auto_generated/providers/arcgis/qgsarcgisrestutils.sip.in index d433184ba84..933958602c3 100644 --- a/python/core/auto_generated/providers/arcgis/qgsarcgisrestutils.sip.in +++ b/python/core/auto_generated/providers/arcgis/qgsarcgisrestutils.sip.in @@ -166,6 +166,15 @@ Converts a ``crs`` to an ArcGIS REST JSON representation. Returns an empty map if the ``crs`` is not valid. .. versionadded:: 3.28 +%End + + static QgsRectangle convertRectangle( const QVariant &value ); +%Docstring +Converts a rectangle ``value`` to a :py:class:`QgsRectangle`. + +Returns a null rectangle if the value cannot be converted. + +.. versionadded:: 3.34 %End enum class FeatureToJsonFlag diff --git a/src/core/providers/arcgis/qgsarcgisrestquery.cpp b/src/core/providers/arcgis/qgsarcgisrestquery.cpp index 6fef518fb0d..afe72ba3c4b 100644 --- a/src/core/providers/arcgis/qgsarcgisrestquery.cpp +++ b/src/core/providers/arcgis/qgsarcgisrestquery.cpp @@ -87,29 +87,7 @@ QgsRectangle QgsArcGisRestQueryUtils::getExtent( const QString &layerurl, const return QgsRectangle(); } - QgsRectangle rect; - do - { - const QVariantMap coords = res.value( QStringLiteral( "extent" ) ).toMap(); - if ( coords.isEmpty() ) break; - bool ok; - const double xmin = coords.value( QStringLiteral( "xmin" ) ).toDouble( &ok ); - if ( ! ok ) break; - const double ymin = coords.value( QStringLiteral( "ymin" ) ).toDouble( &ok ); - if ( ! ok ) break; - const double xmax = coords.value( QStringLiteral( "xmax" ) ).toDouble( &ok ); - if ( ! ok ) break; - const double ymax = coords.value( QStringLiteral( "ymax" ) ).toDouble( &ok ); - if ( ! ok ) break; - - rect.setXMinimum( xmin ); - rect.setYMinimum( ymin ); - rect.setXMaximum( xmax ); - rect.setYMaximum( ymax ); - } - while ( 0 ); - - return rect; + return QgsArcGisRestUtils::convertRectangle( res.value( QStringLiteral( "extent" ) ) ); } QVariantMap QgsArcGisRestQueryUtils::getObjects( const QString &layerurl, const QString &authcfg, const QList &objectIds, const QString &crs, diff --git a/src/core/providers/arcgis/qgsarcgisrestutils.cpp b/src/core/providers/arcgis/qgsarcgisrestutils.cpp index b227a897078..6f6b7019700 100644 --- a/src/core/providers/arcgis/qgsarcgisrestutils.cpp +++ b/src/core/providers/arcgis/qgsarcgisrestutils.cpp @@ -1053,6 +1053,33 @@ QDateTime QgsArcGisRestUtils::convertDateTime( const QVariant &value ) return dt; } +QgsRectangle QgsArcGisRestUtils::convertRectangle( const QVariant &value ) +{ + if ( QgsVariantUtils::isNull( value ) ) + return QgsRectangle(); + + const QVariantMap coords = value.toMap(); + if ( coords.isEmpty() ) return QgsRectangle(); + + bool ok; + + const double xmin = coords.value( QStringLiteral( "xmin" ) ).toDouble( &ok ); + if ( ! ok ) return QgsRectangle(); + + const double ymin = coords.value( QStringLiteral( "ymin" ) ).toDouble( &ok ); + if ( ! ok ) return QgsRectangle(); + + const double xmax = coords.value( QStringLiteral( "xmax" ) ).toDouble( &ok ); + if ( ! ok ) return QgsRectangle(); + + const double ymax = coords.value( QStringLiteral( "ymax" ) ).toDouble( &ok ); + if ( ! ok ) return QgsRectangle(); + + return QgsRectangle( xmin, ymin, xmax, ymax ); + +} + + QVariantMap QgsArcGisRestUtils::geometryToJson( const QgsGeometry &geometry, const QgsArcGisRestContext &, const QgsCoordinateReferenceSystem &crs ) { QVariantMap res; diff --git a/src/core/providers/arcgis/qgsarcgisrestutils.h b/src/core/providers/arcgis/qgsarcgisrestutils.h index 7d026cf6e2d..542885b972b 100644 --- a/src/core/providers/arcgis/qgsarcgisrestutils.h +++ b/src/core/providers/arcgis/qgsarcgisrestutils.h @@ -211,6 +211,15 @@ class CORE_EXPORT QgsArcGisRestUtils */ static QVariantMap crsToJson( const QgsCoordinateReferenceSystem &crs ); + /** + * Converts a rectangle \a value to a QgsRectangle. + * + * Returns a null rectangle if the value cannot be converted. + * + * \since QGIS 3.34 + */ + static QgsRectangle convertRectangle( const QVariant &value ); + /** * Flags which control the behavior of converting features to JSON. *