mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[afs] Add unit test for non OBJECTID named id fields
This commit is contained in:
parent
e3f55dc549
commit
1c8c461a2a
@ -151,10 +151,10 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri )
|
||||
appendError( QgsErrorMessage( tr( "Failed to determine objectIdFieldName and/or objectIds" ), QStringLiteral( "AFSProvider" ) ) );
|
||||
return;
|
||||
}
|
||||
objectIdFieldName = objectIdData[QStringLiteral( "objectIdFieldName" )].toString();
|
||||
mSharedData->mObjectIdFieldName = objectIdData[QStringLiteral( "objectIdFieldName" )].toString();
|
||||
for ( int idx = 0, nIdx = mSharedData->mFields.count(); idx < nIdx; ++idx )
|
||||
{
|
||||
if ( mSharedData->mFields.at( idx ).name() == objectIdFieldName )
|
||||
if ( mSharedData->mFields.at( idx ).name() == mSharedData->mObjectIdFieldName )
|
||||
{
|
||||
mObjectIdFieldIdx = idx;
|
||||
|
||||
|
@ -148,6 +148,7 @@ QgsFeatureIds QgsAfsSharedData::getFeatureIdsInExtent( const QgsRectangle &exten
|
||||
|
||||
|
||||
const QList<quint32> featuresInRect = QgsArcGisRestUtils::getObjectIdsByExtent( mDataSource.param( QStringLiteral( "url" ) ),
|
||||
mObjectIdFieldName,
|
||||
extent, errorTitle, errorText );
|
||||
|
||||
QgsFeatureIds ids;
|
||||
|
@ -46,6 +46,7 @@ class QgsAfsSharedData : public QObject
|
||||
QgsRectangle mExtent;
|
||||
QgsWkbTypes::Type mGeometryType = QgsWkbTypes::Unknown;
|
||||
QgsFields mFields;
|
||||
QString mObjectIdFieldName;
|
||||
QList<quint32> mObjectIds;
|
||||
QMap<QgsFeatureId, QgsFeature> mCache;
|
||||
QgsCoordinateReferenceSystem mSourceCRS;
|
||||
|
@ -407,11 +407,11 @@ QVariantMap QgsArcGisRestUtils::getObjects( const QString &layerurl, const QList
|
||||
return queryServiceJSON( queryUrl, errorTitle, errorText );
|
||||
}
|
||||
|
||||
QList<quint32> QgsArcGisRestUtils::getObjectIdsByExtent( const QString &layerurl, const QgsRectangle &filterRect, QString &errorTitle, QString &errorText )
|
||||
QList<quint32> QgsArcGisRestUtils::getObjectIdsByExtent( const QString &layerurl, const QString &objectIdField, const QgsRectangle &filterRect, QString &errorTitle, QString &errorText )
|
||||
{
|
||||
QUrl queryUrl( layerurl + "/query" );
|
||||
queryUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "json" ) );
|
||||
queryUrl.addQueryItem( QStringLiteral( "where" ), QStringLiteral( "objectid=objectid" ) );
|
||||
queryUrl.addQueryItem( QStringLiteral( "where" ), QStringLiteral( "%1=%1" ).arg( objectIdField ) );
|
||||
queryUrl.addQueryItem( QStringLiteral( "returnIdsOnly" ), QStringLiteral( "true" ) );
|
||||
queryUrl.addQueryItem( QStringLiteral( "geometry" ), QStringLiteral( "%1,%2,%3,%4" )
|
||||
.arg( filterRect.xMinimum(), 0, 'f', -1 ).arg( filterRect.yMinimum(), 0, 'f', -1 )
|
||||
|
@ -41,7 +41,7 @@ class QgsArcGisRestUtils
|
||||
static QVariantMap getObjects( const QString &layerurl, const QList<quint32> &objectIds, const QString &crs,
|
||||
bool fetchGeometry, const QStringList &fetchAttributes, bool fetchM, bool fetchZ,
|
||||
const QgsRectangle &filterRect, QString &errorTitle, QString &errorText );
|
||||
static QList<quint32> getObjectIdsByExtent( const QString &layerurl, const QgsRectangle &filterRect, QString &errorTitle, QString &errorText );
|
||||
static QList<quint32> getObjectIdsByExtent( const QString &layerurl, const QString &objectIdField, const QgsRectangle &filterRect, QString &errorTitle, QString &errorText );
|
||||
static QByteArray queryService( const QUrl &url, QString &errorTitle, QString &errorText );
|
||||
static QVariantMap queryServiceJSON( const QUrl &url, QString &errorTitle, QString &errorText );
|
||||
|
||||
|
@ -111,7 +111,7 @@ class TestPyQgsAFSProvider(unittest.TestCase, ProviderTestCase):
|
||||
"supportsAdvancedQueries":true,"supportedQueryFormats":"JSON, AMF",
|
||||
"ownershipBasedAccessControlForFeatures":{"allowOthersToQuery":true},"useStandardizedQueries":true}""".encode('UTF-8'))
|
||||
|
||||
with open(sanitize(endpoint, '/query?f=json_where=objectid=objectid_returnIdsOnly=true'), 'wb') as f:
|
||||
with open(sanitize(endpoint, '/query?f=json_where=OBJECTID=OBJECTID_returnIdsOnly=true'), 'wb') as f:
|
||||
f.write("""
|
||||
{
|
||||
"objectIdFieldName": "OBJECTID",
|
||||
@ -312,7 +312,7 @@ class TestPyQgsAFSProvider(unittest.TestCase, ProviderTestCase):
|
||||
]
|
||||
}""".encode('UTF-8'))
|
||||
|
||||
with open(sanitize(endpoint, '/query?f=json&where=objectid=objectid&returnIdsOnly=true&geometry=-70.000000,67.000000,-60.000000,80.000000&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects'), 'wb') as f:
|
||||
with open(sanitize(endpoint, '/query?f=json&where=OBJECTID=OBJECTID&returnIdsOnly=true&geometry=-70.000000,67.000000,-60.000000,80.000000&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects'), 'wb') as f:
|
||||
f.write("""
|
||||
{
|
||||
"objectIdFieldName": "OBJECTID",
|
||||
@ -323,7 +323,7 @@ class TestPyQgsAFSProvider(unittest.TestCase, ProviderTestCase):
|
||||
}
|
||||
""".encode('UTF-8'))
|
||||
|
||||
with open(sanitize(endpoint, '/query?f=json&where=objectid=objectid&returnIdsOnly=true&geometry=-73.000000,70.000000,-63.000000,80.000000&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects'), 'wb') as f:
|
||||
with open(sanitize(endpoint, '/query?f=json&where=OBJECTID=OBJECTID&returnIdsOnly=true&geometry=-73.000000,70.000000,-63.000000,80.000000&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects'), 'wb') as f:
|
||||
f.write("""
|
||||
{
|
||||
"objectIdFieldName": "OBJECTID",
|
||||
@ -334,7 +334,7 @@ class TestPyQgsAFSProvider(unittest.TestCase, ProviderTestCase):
|
||||
}
|
||||
""".encode('UTF-8'))
|
||||
|
||||
with open(sanitize(endpoint, '/query?f=json&where=objectid=objectid&returnIdsOnly=true&geometry=-68.721119,68.177676,-64.678700,79.123755&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects'), 'wb') as f:
|
||||
with open(sanitize(endpoint, '/query?f=json&where=OBJECTID=OBJECTID&returnIdsOnly=true&geometry=-68.721119,68.177676,-64.678700,79.123755&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelEnvelopeIntersects'), 'wb') as f:
|
||||
f.write("""
|
||||
{
|
||||
"objectIdFieldName": "OBJECTID",
|
||||
@ -366,6 +366,47 @@ class TestPyQgsAFSProvider(unittest.TestCase, ProviderTestCase):
|
||||
"""
|
||||
pass
|
||||
|
||||
def testObjectIdDifferentName(self):
|
||||
""" Test that object id fields not named OBJECTID work correctly """
|
||||
|
||||
endpoint = self.basetestpath + '/oid_fake_qgis_http_endpoint'
|
||||
with open(sanitize(endpoint, '?f=json'), 'wb') as f:
|
||||
f.write("""
|
||||
{"currentVersion":10.22,"id":1,"name":"QGIS Test","type":"Feature Layer","description":
|
||||
"QGIS Provider Test Layer.\n","geometryType":"esriGeometryPoint","copyrightText":"","parentLayer":{"id":0,"name":"QGIS Tests"},"subLayers":[],
|
||||
"minScale":72225,"maxScale":0,
|
||||
"defaultVisibility":true,
|
||||
"extent":{"xmin":-71.123,"ymin":66.33,"xmax":-65.32,"ymax":78.3,
|
||||
"spatialReference":{"wkid":4326,"latestWkid":4326}},
|
||||
"hasAttachments":false,"htmlPopupType":"esriServerHTMLPopupTypeAsHTMLText",
|
||||
"displayField":"LABEL","typeIdField":null,
|
||||
"fields":[{"name":"OBJECTID1","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null},
|
||||
{"name":"pk","type":"esriFieldTypeInteger","alias":"pk","domain":null},
|
||||
{"name":"cnt","type":"esriFieldTypeInteger","alias":"cnt","domain":null}],
|
||||
"relationships":[],"canModifyLayer":false,"canScaleSymbols":false,"hasLabels":false,
|
||||
"capabilities":"Map,Query,Data","maxRecordCount":1000,"supportsStatistics":true,
|
||||
"supportsAdvancedQueries":true,"supportedQueryFormats":"JSON, AMF",
|
||||
"ownershipBasedAccessControlForFeatures":{"allowOthersToQuery":true},"useStandardizedQueries":true}""".encode(
|
||||
'UTF-8'))
|
||||
|
||||
with open(sanitize(endpoint, '/query?f=json_where=OBJECTID1=OBJECTID1_returnIdsOnly=true'), 'wb') as f:
|
||||
f.write("""
|
||||
{
|
||||
"objectIdFieldName": "OBJECTID1",
|
||||
"objectIds": [
|
||||
5,
|
||||
3,
|
||||
1,
|
||||
2,
|
||||
4
|
||||
]
|
||||
}
|
||||
""".encode('UTF-8'))
|
||||
|
||||
# Create test layer
|
||||
vl = QgsVectorLayer("url='http://" + endpoint + "' crs='epsg:4326'", 'test', 'arcgisfeatureserver')
|
||||
assert vl.isValid()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user