diff --git a/python/core/auto_generated/proj/qgscoordinatereferencesystem.sip.in b/python/core/auto_generated/proj/qgscoordinatereferencesystem.sip.in index 41310eb5888..0e7a50e1417 100644 --- a/python/core/auto_generated/proj/qgscoordinatereferencesystem.sip.in +++ b/python/core/auto_generated/proj/qgscoordinatereferencesystem.sip.in @@ -976,6 +976,12 @@ projection in the WGS 84 CRS. .. versionadded:: 3.0 %End + QString toOgcUri() const; +%Docstring +Returns the crs as OGC URI (format: http://www.opengis.net/def/crs/OGC/1.3/CRS84) +Returns an empty string on failure. +%End + void updateDefinition(); %Docstring diff --git a/python/server/auto_generated/qgsserverapiutils.sip.in b/python/server/auto_generated/qgsserverapiutils.sip.in index af2455acec8..0e82da9e433 100644 --- a/python/server/auto_generated/qgsserverapiutils.sip.in +++ b/python/server/auto_generated/qgsserverapiutils.sip.in @@ -137,10 +137,13 @@ Returns the list of CRSs (format: http://www.opengis.net/def/crs/OGC/1.3/CRS84) Information is read from project WMS configuration. %End - static QString crsToOgcUri( const QgsCoordinateReferenceSystem &crs ); + static QString crsToOgcUri( const QgsCoordinateReferenceSystem &crs ) /Deprecated/; %Docstring Returns a ``crs`` as OGC URI (format: http://www.opengis.net/def/crs/OGC/1.3/CRS84) Returns an empty string on failure. + +.. deprecated:: QGIS 3.30 + use :py:func:`QgsCoordinateReferenceSystem.toOgcUri()` instead %End static QString appendMapParameter( const QString &path, const QUrl &requestUrl ); diff --git a/src/core/proj/qgscoordinatereferencesystem.cpp b/src/core/proj/qgscoordinatereferencesystem.cpp index e067e0768c6..2407c4ff07f 100644 --- a/src/core/proj/qgscoordinatereferencesystem.cpp +++ b/src/core/proj/qgscoordinatereferencesystem.cpp @@ -1495,6 +1495,29 @@ QgsRectangle QgsCoordinateReferenceSystem::bounds() const return rect; } +QString QgsCoordinateReferenceSystem::toOgcUri() const +{ + const auto parts { authid().split( ':' ) }; + if ( parts.length() == 2 ) + { + if ( parts[0] == QLatin1String( "EPSG" ) ) + return QStringLiteral( "http://www.opengis.net/def/crs/EPSG/9.6.2/%1" ).arg( parts[1] ) ; + else if ( parts[0] == QLatin1String( "OGC" ) ) + { + return QStringLiteral( "http://www.opengis.net/def/crs/OGC/1.3/%1" ).arg( parts[1] ) ; + } + else + { + QgsMessageLog::logMessage( QStringLiteral( "Error converting published CRS to URI %1: (not OGC or EPSG)" ).arg( authid() ), QStringLiteral( "CRS" ), Qgis::MessageLevel::Critical ); + } + } + else + { + QgsMessageLog::logMessage( QStringLiteral( "Error converting published CRS to URI: %1" ).arg( authid() ), QStringLiteral( "CRS" ), Qgis::MessageLevel::Critical ); + } + return QString(); +} + void QgsCoordinateReferenceSystem::updateDefinition() { if ( !d->mIsValid ) diff --git a/src/core/proj/qgscoordinatereferencesystem.h b/src/core/proj/qgscoordinatereferencesystem.h index 68904f8466c..49d201fd475 100644 --- a/src/core/proj/qgscoordinatereferencesystem.h +++ b/src/core/proj/qgscoordinatereferencesystem.h @@ -901,6 +901,12 @@ class CORE_EXPORT QgsCoordinateReferenceSystem */ QgsRectangle bounds() const; + /** + * Returns the crs as OGC URI (format: http://www.opengis.net/def/crs/OGC/1.3/CRS84) + * Returns an empty string on failure. + */ + QString toOgcUri() const; + // Mutators ----------------------------------- /** diff --git a/src/providers/wfs/oapif/qgsoapifprovider.cpp b/src/providers/wfs/oapif/qgsoapifprovider.cpp index a397b754f5a..02787064b02 100644 --- a/src/providers/wfs/oapif/qgsoapifprovider.cpp +++ b/src/providers/wfs/oapif/qgsoapifprovider.cpp @@ -740,6 +740,10 @@ void QgsOapifFeatureDownloaderImpl::run( bool serializeFeatures, long long maxFe qgsDoubleToString( rect.yMinimum() ), qgsDoubleToString( rect.xMaximum() ), qgsDoubleToString( rect.yMaximum() ) ); + + if ( mShared->mSourceCrs + != QgsCoordinateReferenceSystem::fromOgcWmsCrs( QgsOapifProvider::OAPIF_PROVIDER_DEFAULT_CRS ) ) + url += QStringLiteral( "&bbox-crs=%1" ).arg( mShared->mSourceCrs.toOgcUri() ); } } diff --git a/src/server/qgsserverapiutils.cpp b/src/server/qgsserverapiutils.cpp index 89daaa77095..db2fdb3b0ef 100644 --- a/src/server/qgsserverapiutils.cpp +++ b/src/server/qgsserverapiutils.cpp @@ -613,7 +613,7 @@ QStringList QgsServerApiUtils::publishedCrsList( const QgsProject *project ) const QStringList outputCrsList = QgsServerProjectUtils::wmsOutputCrsList( *project ); for ( const QString &crsId : outputCrsList ) { - const auto crsUri { crsToOgcUri( QgsCoordinateReferenceSystem::fromOgcWmsCrs( crsId ) ) }; + const auto crsUri { QgsCoordinateReferenceSystem::fromOgcWmsCrs( crsId ).toOgcUri() }; if ( ! crsUri.isEmpty() ) { result.push_back( crsUri ); @@ -625,25 +625,7 @@ QStringList QgsServerApiUtils::publishedCrsList( const QgsProject *project ) QString QgsServerApiUtils::crsToOgcUri( const QgsCoordinateReferenceSystem &crs ) { - const auto parts { crs.authid().split( ':' ) }; - if ( parts.length() == 2 ) - { - if ( parts[0] == QLatin1String( "EPSG" ) ) - return QStringLiteral( "http://www.opengis.net/def/crs/EPSG/9.6.2/%1" ).arg( parts[1] ) ; - else if ( parts[0] == QLatin1String( "OGC" ) ) - { - return QStringLiteral( "http://www.opengis.net/def/crs/OGC/1.3/%1" ).arg( parts[1] ) ; - } - else - { - QgsMessageLog::logMessage( QStringLiteral( "Error converting published CRS to URI %1: (not OGC or EPSG)" ).arg( crs.authid() ), QStringLiteral( "Server" ), Qgis::MessageLevel::Critical ); - } - } - else - { - QgsMessageLog::logMessage( QStringLiteral( "Error converting published CRS to URI: %1" ).arg( crs.authid() ), QStringLiteral( "Server" ), Qgis::MessageLevel::Critical ); - } - return QString(); + return crs.toOgcUri(); } QString QgsServerApiUtils::appendMapParameter( const QString &path, const QUrl &requestUrl ) diff --git a/src/server/qgsserverapiutils.h b/src/server/qgsserverapiutils.h index ece60828c1b..eec7295b4f7 100644 --- a/src/server/qgsserverapiutils.h +++ b/src/server/qgsserverapiutils.h @@ -225,8 +225,10 @@ class SERVER_EXPORT QgsServerApiUtils /** * Returns a \a crs as OGC URI (format: http://www.opengis.net/def/crs/OGC/1.3/CRS84) * Returns an empty string on failure. + * + * \deprecated since QGIS 3.30 use QgsCoordinateReferenceSystem::toOgcUri() instead */ - static QString crsToOgcUri( const QgsCoordinateReferenceSystem &crs ); + Q_DECL_DEPRECATED static QString crsToOgcUri( const QgsCoordinateReferenceSystem &crs ) SIP_DEPRECATED; /** * Appends MAP query string parameter from current \a requestUrl to the given \a path diff --git a/tests/src/core/testqgscoordinatereferencesystem.cpp b/tests/src/core/testqgscoordinatereferencesystem.cpp index ac772c8ae39..0b0a416fdb6 100644 --- a/tests/src/core/testqgscoordinatereferencesystem.cpp +++ b/tests/src/core/testqgscoordinatereferencesystem.cpp @@ -104,6 +104,7 @@ class TestQgsCoordinateReferenceSystem: public QObject void createFromWktWithIdentify(); void fromProj4EPSG20936(); void projFactors(); + void toOgcUri(); private: void debugPrint( QgsCoordinateReferenceSystem &crs ); @@ -1887,5 +1888,20 @@ void TestQgsCoordinateReferenceSystem::displayIdentifier() QCOMPARE( crs.userFriendlyIdentifier(), QStringLiteral( "USER:%1 - my test" ).arg( crs.srsid() ) ); } +void TestQgsCoordinateReferenceSystem::toOgcUri() +{ + QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:3717" ) ); + QVERIFY( crs.isValid() ); + QCOMPARE( crs.toOgcUri(), "http://www.opengis.net/def/crs/EPSG/9.6.2/3717" ); + + crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ); + QVERIFY( crs.isValid() ); + QCOMPARE( crs.toOgcUri(), "http://www.opengis.net/def/crs/EPSG/9.6.2/4326" ); + + crs = QgsCoordinateReferenceSystem( QStringLiteral( "OGC:CRS84" ) ); + QVERIFY( crs.isValid() ); + QCOMPARE( crs.toOgcUri(), "http://www.opengis.net/def/crs/OGC/1.3/CRS84" ); +} + QGSTEST_MAIN( TestQgsCoordinateReferenceSystem ) #include "testqgscoordinatereferencesystem.moc" diff --git a/tests/src/python/test_provider_oapif.py b/tests/src/python/test_provider_oapif.py index 28ff7c083f0..bcf3cc345f1 100644 --- a/tests/src/python/test_provider_oapif.py +++ b/tests/src/python/test_provider_oapif.py @@ -289,7 +289,7 @@ class TestPyQgsOapifProvider(unittest.TestCase, ProviderTestCase): "geometry": {"type": "Point", "coordinates": [-68.2, 70.8]}} ] } - with open(sanitize(endpoint, '/collections/mycollection/items?limit=1000&bbox=-71,65.5,-65,78&' + ACCEPT_ITEMS), + with open(sanitize(endpoint, '/collections/mycollection/items?limit=1000&bbox=-71,65.5,-65,78&bbox-crs=http://www.opengis.net/def/crs/EPSG/9.6.2/4326&' + ACCEPT_ITEMS), 'wb') as f: f.write(json.dumps(items).encode('UTF-8')) @@ -307,7 +307,7 @@ class TestPyQgsOapifProvider(unittest.TestCase, ProviderTestCase): # Test clamping of bbox with open( - sanitize(endpoint, '/collections/mycollection/items?limit=1000&bbox=-180,64.5,-65,78&' + ACCEPT_ITEMS), + sanitize(endpoint, '/collections/mycollection/items?limit=1000&bbox=-180,64.5,-65,78&bbox-crs=http://www.opengis.net/def/crs/EPSG/9.6.2/4326&' + ACCEPT_ITEMS), 'wb') as f: f.write(json.dumps(items).encode('UTF-8')) @@ -334,7 +334,7 @@ class TestPyQgsOapifProvider(unittest.TestCase, ProviderTestCase): "geometry": {"type": "Point", "coordinates": [-65.32, 78.3]}} ] } - with open(sanitize(endpoint, '/collections/mycollection/items?limit=1000&bbox=-180,-90,180,90&' + ACCEPT_ITEMS), 'wb') as f: + with open(sanitize(endpoint, '/collections/mycollection/items?limit=1000&bbox=-180,-90,180,90&bbox-crs=http://www.opengis.net/def/crs/EPSG/9.6.2/4326&' + ACCEPT_ITEMS), 'wb') as f: f.write(json.dumps(items).encode('UTF-8')) extent = QgsRectangle(-181, -91, 181, 91)