mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-05 00:09:32 -04:00
Add bbox-crs parameter to the request (if not default CRS84)
This commit is contained in:
parent
e2220596c0
commit
a4ae707ff6
@ -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
|
||||
|
@ -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 );
|
||||
|
@ -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 )
|
||||
|
@ -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 -----------------------------------
|
||||
|
||||
/**
|
||||
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 )
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user