void QgsConfigParser::appendExGeographicBoundingBox( QDomElement& layerElem, QDomDocument& doc, const QgsRectangle& layerExtent, const QgsCoordinateReferenceSystem& layerCRS ) const { if ( layerElem.isNull() ) { return; } QgsCoordinateReferenceSystem wgs84; wgs84.createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID ); //Ex_GeographicBoundingBox //transform the layers native CRS into WGS84 QgsCoordinateTransform exGeoTransform( layerCRS, wgs84 ); QgsRectangle wgs84BoundingRect = exGeoTransform.transformBoundingBox( layerExtent ); QDomElement ExGeoBBoxElement = doc.createElement( "EX_GeographicBoundingBox" ); QDomElement wBoundLongitudeElement = doc.createElement( "westBoundLongitude" ); QDomText wBoundLongitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.xMinimum() ) ); wBoundLongitudeElement.appendChild( wBoundLongitudeText ); ExGeoBBoxElement.appendChild( wBoundLongitudeElement ); QDomElement eBoundLongitudeElement = doc.createElement( "eastBoundLongitude" ); QDomText eBoundLongitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.xMaximum() ) ); eBoundLongitudeElement.appendChild( eBoundLongitudeText ); ExGeoBBoxElement.appendChild( eBoundLongitudeElement ); QDomElement sBoundLatitudeElement = doc.createElement( "southBoundLatitude" ); QDomText sBoundLatitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.yMinimum() ) ); sBoundLatitudeElement.appendChild( sBoundLatitudeText ); ExGeoBBoxElement.appendChild( sBoundLatitudeElement ); QDomElement nBoundLatitudeElement = doc.createElement( "northBoundLatitude" ); QDomText nBoundLatitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.yMaximum() ) ); nBoundLatitudeElement.appendChild( nBoundLatitudeText ); ExGeoBBoxElement.appendChild( nBoundLatitudeElement ); //BoundingBox element QDomElement bBoxElement = doc.createElement( "BoundingBox" ); if ( layerCRS.isValid() ) { bBoxElement.setAttribute( "CRS", layerCRS.authid() ); } bBoxElement.setAttribute( "minx", QString::number( layerExtent.xMinimum() ) ); bBoxElement.setAttribute( "miny", QString::number( layerExtent.yMinimum() ) ); bBoxElement.setAttribute( "maxx", QString::number( layerExtent.xMaximum() ) ); bBoxElement.setAttribute( "maxy", QString::number( layerExtent.yMaximum() ) ); QDomElement lastCRSElem = layerElem.lastChildElement( "CRS" ); if ( !lastCRSElem.isNull() ) { layerElem.insertAfter( ExGeoBBoxElement, lastCRSElem ); layerElem.insertAfter( bBoxElement, ExGeoBBoxElement ); } else { layerElem.appendChild( ExGeoBBoxElement ); layerElem.appendChild( bBoxElement ); } }
tileMatrixSetLinkDef getLayerTileMatrixSetLink( const layerDef layer, const tileMatrixSetDef tms, const QgsProject *project ) { tileMatrixSetLinkDef tmsl; QMap< int, tileMatrixLimitDef > tileMatrixLimits; QgsRectangle rect( layer.wgs84BoundingRect ); if ( tms.ref != QLatin1String( "EPSG:4326" ) ) { QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( tms.ref ); QgsCoordinateTransform exGeoTransform( wgs84, crs, project ); try { rect = exGeoTransform.transformBoundingBox( layer.wgs84BoundingRect ); } catch ( const QgsCsException & ) { return tmsl; } } tmsl.ref = tms.ref; rect = rect.intersect( tms.extent ); int tmIdx = -1; for ( const tileMatrixDef &tm : tms.tileMatrixList ) { ++tmIdx; if ( layer.maxScale > 0.0 && tm.scaleDenominator > layer.maxScale ) { continue; } if ( layer.minScale > 0.0 && tm.scaleDenominator < layer.minScale ) { continue; } double res = tm.resolution; tileMatrixLimitDef tml; tml.minCol = std::floor( ( rect.xMinimum() - tm.left ) / ( tileSize * res ) ); tml.maxCol = std::ceil( ( rect.xMaximum() - tm.left ) / ( tileSize * res ) ) - 1; tml.minRow = std::floor( ( tm.top - rect.yMaximum() ) / ( tileSize * res ) ); tml.maxRow = std::ceil( ( tm.top - rect.yMinimum() ) / ( tileSize * res ) ) - 1; tileMatrixLimits[tmIdx] = tml; } tmsl.tileMatrixLimits = tileMatrixLimits; return tmsl; }
QList< layerDef > getWmtsLayerList( QgsServerInterface *serverIface, const QgsProject *project ) { QList< layerDef > wmtsLayers; #ifdef HAVE_SERVER_PYTHON_PLUGINS QgsAccessControl *accessControl = serverIface->accessControls(); #else ( void )serverIface; #endif // WMTS Project configuration bool wmtsProject = project->readBoolEntry( QStringLiteral( "WMTSLayers" ), QStringLiteral( "Project" ) ); // Root Layer name QString rootLayerName = QgsServerProjectUtils::wmsRootName( *project ); if ( rootLayerName.isEmpty() && !project->title().isEmpty() ) { rootLayerName = project->title(); } if ( wmtsProject && !rootLayerName.isEmpty() ) { layerDef pLayer; pLayer.id = rootLayerName; if ( !project->title().isEmpty() ) { pLayer.title = project->title(); pLayer.abstract = project->title(); } //transform the project native CRS into WGS84 QgsRectangle projRect = QgsServerProjectUtils::wmsExtent( *project ); QgsCoordinateReferenceSystem projCrs = project->crs(); QgsCoordinateTransform exGeoTransform( projCrs, wgs84, project ); try { pLayer.wgs84BoundingRect = exGeoTransform.transformBoundingBox( projRect ); } catch ( const QgsCsException & ) { pLayer.wgs84BoundingRect = QgsRectangle( -180, -90, 180, 90 ); } // Formats bool wmtsPngProject = project->readBoolEntry( QStringLiteral( "WMTSPngLayers" ), QStringLiteral( "Project" ) ); if ( wmtsPngProject ) pLayer.formats << QStringLiteral( "image/png" ); bool wmtsJpegProject = project->readBoolEntry( QStringLiteral( "WMTSJpegLayers" ), QStringLiteral( "Project" ) ); if ( wmtsJpegProject ) pLayer.formats << QStringLiteral( "image/jpeg" ); // Project is not queryable in WMS //pLayer.queryable = ( nonIdentifiableLayers.count() != project->count() ); pLayer.queryable = false; wmtsLayers.append( pLayer ); } QStringList wmtsGroupNameList = project->readListEntry( QStringLiteral( "WMTSLayers" ), QStringLiteral( "Group" ) ); if ( !wmtsGroupNameList.isEmpty() ) { QgsLayerTreeGroup *treeRoot = project->layerTreeRoot(); QStringList wmtsPngGroupNameList = project->readListEntry( QStringLiteral( "WMTSPngLayers" ), QStringLiteral( "Group" ) ); QStringList wmtsJpegGroupNameList = project->readListEntry( QStringLiteral( "WMTSJpegLayers" ), QStringLiteral( "Group" ) ); for ( const QString &gName : wmtsGroupNameList ) { QgsLayerTreeGroup *treeGroup = treeRoot->findGroup( gName ); if ( !treeGroup ) { continue; } layerDef pLayer; pLayer.id = treeGroup->customProperty( QStringLiteral( "wmsShortName" ) ).toString(); if ( pLayer.id.isEmpty() ) pLayer.id = gName; pLayer.title = treeGroup->customProperty( QStringLiteral( "wmsTitle" ) ).toString(); if ( pLayer.title.isEmpty() ) pLayer.title = gName; pLayer.abstract = treeGroup->customProperty( QStringLiteral( "wmsAbstract" ) ).toString(); QgsRectangle wgs84BoundingRect; bool queryable = false; double maxScale = 0.0; double minScale = 0.0; for ( QgsLayerTreeLayer *layer : treeGroup->findLayers() ) { QgsMapLayer *l = layer->layer(); if ( !l ) { continue; } //transform the layer native CRS into WGS84 QgsCoordinateReferenceSystem layerCrs = l->crs(); QgsCoordinateTransform exGeoTransform( layerCrs, wgs84, project ); try { wgs84BoundingRect.combineExtentWith( exGeoTransform.transformBoundingBox( l->extent() ) ); } catch ( const QgsCsException & ) { wgs84BoundingRect.combineExtentWith( QgsRectangle( -180, -90, 180, 90 ) ); } if ( !queryable && l->flags().testFlag( QgsMapLayer::Identifiable ) ) { queryable = true; } if ( l->hasScaleBasedVisibility() ) { double lMaxScale = l->maximumScale(); if ( lMaxScale > 0.0 && lMaxScale > maxScale ) { maxScale = lMaxScale; } double lMinScale = l->minimumScale(); if ( lMinScale > 0.0 && ( minScale == 0.0 || lMinScale < minScale ) ) { minScale = lMinScale; } } } pLayer.wgs84BoundingRect = wgs84BoundingRect; pLayer.queryable = queryable; pLayer.maxScale = maxScale; pLayer.minScale = minScale; // Formats if ( wmtsPngGroupNameList.contains( gName ) ) pLayer.formats << QStringLiteral( "image/png" ); if ( wmtsJpegGroupNameList.contains( gName ) ) pLayer.formats << QStringLiteral( "image/jpeg" ); wmtsLayers.append( pLayer ); } } QStringList wmtsLayerIdList = project->readListEntry( QStringLiteral( "WMTSLayers" ), QStringLiteral( "Layer" ) ); QStringList wmtsPngLayerIdList = project->readListEntry( QStringLiteral( "WMTSPngLayers" ), QStringLiteral( "Layer" ) ); QStringList wmtsJpegLayerIdList = project->readListEntry( QStringLiteral( "WMTSJpegLayers" ), QStringLiteral( "Layer" ) ); for ( const QString &lId : wmtsLayerIdList ) { QgsMapLayer *l = project->mapLayer( lId ); if ( !l ) { continue; } #ifdef HAVE_SERVER_PYTHON_PLUGINS if ( !accessControl->layerReadPermission( l ) ) { continue; } #endif layerDef pLayer; pLayer.id = l->name(); if ( !l->shortName().isEmpty() ) pLayer.id = l->shortName(); pLayer.id = pLayer.id.replace( ' ', '_' ); pLayer.title = l->title(); pLayer.abstract = l->abstract(); //transform the layer native CRS into WGS84 QgsCoordinateReferenceSystem layerCrs = l->crs(); QgsCoordinateTransform exGeoTransform( layerCrs, wgs84, project ); try { pLayer.wgs84BoundingRect = exGeoTransform.transformBoundingBox( l->extent() ); } catch ( const QgsCsException & ) { pLayer.wgs84BoundingRect = QgsRectangle( -180, -90, 180, 90 ); } // Formats if ( wmtsPngLayerIdList.contains( lId ) ) pLayer.formats << QStringLiteral( "image/png" ); if ( wmtsJpegLayerIdList.contains( lId ) ) pLayer.formats << QStringLiteral( "image/jpeg" ); pLayer.queryable = ( l->flags().testFlag( QgsMapLayer::Identifiable ) ); if ( l->hasScaleBasedVisibility() ) { pLayer.maxScale = l->maximumScale(); pLayer.minScale = l->minimumScale(); } else { pLayer.maxScale = 0.0; pLayer.minScale = 0.0; } wmtsLayers.append( pLayer ); } return wmtsLayers; }