Skip to content

Commit

Permalink
[arcgisrest] Fix parsing of imageserver raster layer
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jun 7, 2019
1 parent b1e4a27 commit 2a9028a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/providers/arcgisrest/qgsamsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,19 @@ QgsAmsProvider::QgsAmsProvider( const QString &uri, const ProviderOptions &optio

const QString serviceUrl = dataSource.param( QStringLiteral( "url" ) );
mServiceInfo = QgsArcGisRestUtils::getServiceInfo( serviceUrl, authcfg, mErrorTitle, mError, mRequestHeaders );
const QString layerUrl = dataSource.param( QStringLiteral( "url" ) ) + "/" + dataSource.param( QStringLiteral( "layer" ) );
mLayerInfo = QgsArcGisRestUtils::getLayerInfo( layerUrl, authcfg, mErrorTitle, mError, mRequestHeaders );

QString layerUrl;
if ( mServiceInfo.value( QStringLiteral( "serviceDataType" ) ).toString().startsWith( QLatin1String( "esriImageService" ) ) )
{
layerUrl = serviceUrl;
mLayerInfo = mServiceInfo;
mImageServer = true;
}
else
{
layerUrl = dataSource.param( QStringLiteral( "url" ) ) + "/" + dataSource.param( QStringLiteral( "layer" ) );
mLayerInfo = QgsArcGisRestUtils::getLayerInfo( layerUrl, authcfg, mErrorTitle, mError, mRequestHeaders );
}

const QVariantMap extentData = mLayerInfo.value( QStringLiteral( "extent" ) ).toMap();
mExtent.setXMinimum( extentData[QStringLiteral( "xmin" )].toDouble() );
Expand Down Expand Up @@ -264,6 +275,7 @@ QgsAmsProvider::QgsAmsProvider( const QgsAmsProvider &other, const QgsDataProvid
, mSubLayerVisibilities( other.mSubLayerVisibilities )
, mRequestHeaders( other.mRequestHeaders )
, mTiled( other.mTiled )
, mImageServer( other.mImageServer )
, mLayerMetadata( other.mLayerMetadata )
, mResolutions( other.mResolutions )
// intentionally omitted:
Expand Down Expand Up @@ -629,7 +641,7 @@ QImage QgsAmsProvider::draw( const QgsRectangle &viewExtent, int pixelWidth, int
return mCachedImage;
}

QUrl requestUrl( dataSource.param( QStringLiteral( "url" ) ) + "/export" );
QUrl requestUrl( dataSource.param( QStringLiteral( "url" ) ) + ( mImageServer ? "/exportImage" : "/export" ) );
requestUrl.addQueryItem( QStringLiteral( "bbox" ), QStringLiteral( "%1,%2,%3,%4" ).arg( viewExtent.xMinimum(), 0, 'f', -1 ).arg( viewExtent.yMinimum(), 0, 'f', -1 ).arg( viewExtent.xMaximum(), 0, 'f', -1 ).arg( viewExtent.yMaximum(), 0, 'f', -1 ) );
requestUrl.addQueryItem( QStringLiteral( "size" ), QStringLiteral( "%1,%2" ).arg( pixelWidth ).arg( pixelHeight ) );
requestUrl.addQueryItem( QStringLiteral( "format" ), dataSource.param( QStringLiteral( "format" ) ) );
Expand Down
1 change: 1 addition & 0 deletions src/providers/arcgisrest/qgsamsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class QgsAmsProvider : public QgsRasterDataProvider
QgsStringMap mRequestHeaders;
int mTileReqNo = 0;
bool mTiled = false;
bool mImageServer = false;
QgsLayerMetadata mLayerMetadata;
QList< double > mResolutions;
};
Expand Down
9 changes: 8 additions & 1 deletion src/providers/arcgisrest/qgsarcgisrestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ void QgsArcGisRestUtils::visitServiceItems( const std::function< void( const QSt
{
const QVariantMap serviceMap = service.toMap();
const QString serviceType = serviceMap.value( QStringLiteral( "type" ) ).toString();
if ( serviceType != QLatin1String( "MapServer" ) && serviceType != QLatin1String( "FeatureServer" ) )
if ( serviceType != QLatin1String( "MapServer" ) && serviceType != QLatin1String( "FeatureServer" ) && serviceType != QLatin1String( "ImageServer" ) )
continue;

const QString serviceName = serviceMap.value( QStringLiteral( "name" ) ).toString();
Expand Down Expand Up @@ -1370,4 +1370,11 @@ void QgsArcGisRestUtils::addLayerItems( const std::function< void( const QString
visitor( parentLayerId, id, name, description, parentUrl + '/' + id, false, authid, format );
}
}

if ( serviceData.value( QStringLiteral( "serviceDataType" ) ).toString().startsWith( QLatin1String( "esriImageService" ) ) )
{
const QString name = serviceData.value( QStringLiteral( "name" ) ).toString();
const QString description = serviceData.value( QStringLiteral( "description" ) ).toString();
visitor( 0, 0, name, description, parentUrl, false, authid, format );
}
}

0 comments on commit 2a9028a

Please sign in to comment.