Skip to content
Permalink
Browse files

[afs] Read field aliases from layer definition

  • Loading branch information
nyalldawson committed Jun 28, 2020
1 parent cd92345 commit 639bbee926c2d8276d9490f578df7ca6946165fe
Showing with 43 additions and 0 deletions.
  1. +3 −0 src/providers/arcgisrest/qgsafsprovider.cpp
  2. +40 −0 tests/src/python/test_provider_afs.py
@@ -132,6 +132,7 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri, const ProviderOptions &optio
{
const QVariantMap fieldDataMap = fieldData.toMap();
const QString fieldName = fieldDataMap[QStringLiteral( "name" )].toString();
const QString fieldAlias = fieldDataMap[QStringLiteral( "alias" )].toString();
const QString fieldTypeString = fieldDataMap[QStringLiteral( "type" )].toString();
QVariant::Type type = QgsArcGisRestUtils::mapEsriFieldType( fieldTypeString );
if ( fieldName == QLatin1String( "geometry" ) || fieldTypeString == QLatin1String( "esriFieldTypeGeometry" ) )
@@ -149,6 +150,8 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri, const ProviderOptions &optio
continue;
}
QgsField field( fieldName, type, fieldDataMap[QStringLiteral( "type" )].toString(), fieldDataMap[QStringLiteral( "length" )].toInt() );
if ( !fieldAlias.isEmpty() && fieldAlias != fieldName )
field.setAlias( fieldAlias );

if ( fieldDataMap.contains( QStringLiteral( "domain" ) ) && fieldDataMap.value( QStringLiteral( "domain" ) ).toMap().value( QStringLiteral( "type" ) ).toString() == QStringLiteral( "codedValue" ) )
{
@@ -697,6 +697,46 @@ def testMetadata(self):
l.url = 'http://' + sanitize(endpoint, '')
self.assertEqual(md.links(), [l])

def testFieldAlias(self):
""" Test that field aliases are correctly acquired from provider """

endpoint = self.basetestpath + '/alias_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","geometryType":"esriGeometryPoint","copyrightText":"not copyright","parentLayer":{"id":2,"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":"OBJECTID","type":"esriFieldTypeOID","alias":"field id","domain":null},{"name":"second","type":"esriFieldTypeString","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=1=1&returnIdsOnly=true'), 'wb') as f:
f.write("""
{
"objectIdFieldName": "OBJECTID",
"objectIds": [
1
]
}
""".encode('UTF-8'))

# Create test layer
vl = QgsVectorLayer("url='http://" + endpoint + "' crs='epsg:4326'", 'test', 'arcgisfeatureserver')
self.assertTrue(vl.isValid())

self.assertEqual(vl.fields().at(0).name(), 'OBJECTID')
self.assertEqual(vl.fields().at(0).alias(), 'field id')
self.assertEqual(vl.fields().at(1).name(), 'second')
self.assertFalse(vl.fields().at(1).alias())

def testRenderer(self):
""" Test that renderer is correctly acquired from provider """

0 comments on commit 639bbee

Please sign in to comment.
You can’t perform that action at this time.