mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[Server] WMS GetCapabilities refactoring - Part 2
Part 2 (the last) for removing QgsWMSProjectParser from GetCapabilities
This commit is contained in:
parent
258c872c45
commit
33b4582f49
@ -31,6 +31,7 @@
|
||||
#include "qgsrequesthandler.h"
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsconfigcache.h"
|
||||
#include "qgsconfigparserutils.h"
|
||||
#include "qgscapabilitiescache.h"
|
||||
#include "qgsmapsettings.h"
|
||||
#include "qgsmessagelog.h"
|
||||
|
@ -139,11 +139,70 @@ QStringList QgsServerProjectUtils::wmsRestrictedComposers( const QgsProject &pro
|
||||
return project.readListEntry( QStringLiteral( "WMSRestrictedComposers" ), QStringLiteral( "/" ), QStringList() );
|
||||
}
|
||||
|
||||
QStringList QgsServerProjectUtils::wmsOutputCrsList( const QgsProject &project )
|
||||
{
|
||||
QStringList crsList = project.readListEntry( QStringLiteral( "WMSCrsList" ), QStringLiteral( "/" ), QStringList() );
|
||||
if ( crsList.isEmpty() )
|
||||
{
|
||||
QStringList valueList = project.readListEntry( QStringLiteral( "WMSEpsgList" ), QStringLiteral( "/" ), QStringList() );
|
||||
bool conversionOk;
|
||||
for ( int i = 0; i < valueList.size(); ++i )
|
||||
{
|
||||
int epsgNr = valueList.at( i ).toInt( &conversionOk );
|
||||
if ( conversionOk )
|
||||
{
|
||||
crsList.append( QStringLiteral( "EPSG:%1" ).arg( epsgNr ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( crsList.isEmpty() )
|
||||
{
|
||||
//no CRS restriction defined in the project. Provide project CRS, wgs84 and pseudo mercator
|
||||
QString projectCrsId = project.crs().authid();
|
||||
crsList.append( projectCrsId );
|
||||
if ( projectCrsId.compare( QLatin1String( "EPSG:4326" ), Qt::CaseInsensitive ) != 0 )
|
||||
{
|
||||
crsList.append( QStringLiteral( "EPSG:%1" ).arg( 4326 ) );
|
||||
}
|
||||
if ( projectCrsId.compare( QLatin1String( "EPSG:3857" ), Qt::CaseInsensitive ) != 0 )
|
||||
{
|
||||
crsList.append( QStringLiteral( "EPSG:%1" ).arg( 3857 ) );
|
||||
}
|
||||
}
|
||||
return crsList;
|
||||
}
|
||||
|
||||
QString QgsServerProjectUtils::wmsServiceUrl( const QgsProject &project )
|
||||
{
|
||||
return project.readEntry( QStringLiteral( "WMSUrl" ), QStringLiteral( "/" ), "" );
|
||||
}
|
||||
|
||||
QString QgsServerProjectUtils::wmsRootName( const QgsProject &project )
|
||||
{
|
||||
return project.readEntry( QStringLiteral( "WMSRootName" ), QStringLiteral( "/" ), "" );
|
||||
}
|
||||
|
||||
QStringList QgsServerProjectUtils::wmsRestrictedLayers( const QgsProject &project )
|
||||
{
|
||||
return project.readListEntry( QStringLiteral( "WMSRestrictedLayers" ), QStringLiteral( "/" ), QStringList() );
|
||||
}
|
||||
|
||||
QgsRectangle QgsServerProjectUtils::wmsExtent( const QgsProject &project )
|
||||
{
|
||||
bool ok = false;
|
||||
QStringList values = project.readListEntry( QStringLiteral( "WMSExtent" ), QStringLiteral( "/" ), QStringList(), &ok );
|
||||
if ( !ok || values.size() != 4 )
|
||||
{
|
||||
return QgsRectangle();
|
||||
}
|
||||
//order of value elements must be xmin, ymin, xmax, ymax
|
||||
double xmin = values[ 0 ].toDouble();
|
||||
double ymin = values[ 1 ].toDouble();
|
||||
double xmax = values[ 2 ].toDouble();
|
||||
double ymax = values[ 3 ].toDouble();
|
||||
return QgsRectangle( xmin, ymin, xmax, ymax );
|
||||
}
|
||||
|
||||
QString QgsServerProjectUtils::wfsServiceUrl( const QgsProject &project )
|
||||
{
|
||||
return project.readEntry( QStringLiteral( "WFSUrl" ), QStringLiteral( "/" ), "" );
|
||||
|
@ -173,6 +173,30 @@ namespace QgsServerProjectUtils
|
||||
*/
|
||||
SERVER_EXPORT QString wmsServiceUrl( const QgsProject &project );
|
||||
|
||||
/** Returns the WMS root layer name defined in a QGIS project.
|
||||
* \param project the QGIS project
|
||||
* \returns root layer name if defined in project, an empty string otherwise.
|
||||
*/
|
||||
SERVER_EXPORT QString wmsRootName( const QgsProject &project );
|
||||
|
||||
/** Returns the restricted layer name list.
|
||||
* \param project the QGIS project
|
||||
* \returns the restricted layer name list if defined in project.
|
||||
*/
|
||||
SERVER_EXPORT QStringList wmsRestrictedLayers( const QgsProject &project );
|
||||
|
||||
/** Returns the WMS output CRS list.
|
||||
* \param project the QGIS project
|
||||
* \returns the WMS output CRS list.
|
||||
*/
|
||||
SERVER_EXPORT QStringList wmsOutputCrsList( const QgsProject &project );
|
||||
|
||||
/** Returns the WMS Extent restriction.
|
||||
* \param project the QGIS project
|
||||
* \returns the WMS Extent restriction.
|
||||
*/
|
||||
SERVER_EXPORT QgsRectangle wmsExtent( const QgsProject &project );
|
||||
|
||||
/** Returns the WFS service url defined in a QGIS project.
|
||||
* \param project the QGIS project
|
||||
* \returns url if defined in project, an empty string otherwise.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -21,9 +21,22 @@
|
||||
#ifndef QGSWMSGETCAPABILITIES_H
|
||||
#define QGSWMSGETCAPABILITIES_H
|
||||
|
||||
#include "qgslayertreenode.h"
|
||||
#include "qgslayertreegroup.h"
|
||||
#include "qgslayertreelayer.h"
|
||||
#include "qgslayertreemodel.h"
|
||||
#include "qgslayertree.h"
|
||||
|
||||
namespace QgsWms
|
||||
{
|
||||
|
||||
/**
|
||||
* Create element for get capabilities document
|
||||
*/
|
||||
QDomElement getLayersAndStylesCapabilitiesElement( QDomDocument &doc, QgsServerInterface *serverIface,
|
||||
const QgsProject *project, const QString &version,
|
||||
const QgsServerRequest &request, bool projectSettings );
|
||||
|
||||
/**
|
||||
* Create WFSLayers element for get capabilities document
|
||||
*/
|
||||
|
@ -37,6 +37,9 @@ class QgsRectangle;
|
||||
//! WMS implementation
|
||||
namespace QgsWms
|
||||
{
|
||||
// style name to use for the unnamed style of layers (must not be empty name in WMS)
|
||||
// this implies that a layer style called "default" will not be usable in WMS server
|
||||
const QString EMPTY_STYLE_NAME = QStringLiteral( "default" );
|
||||
|
||||
//! Supported image output format
|
||||
enum ImageOutputFormat
|
||||
|
@ -234,6 +234,36 @@ class TestQgsServerAccessControl(unittest.TestCase):
|
||||
str(response).find("<Name>Country</Name>") != -1,
|
||||
"Country layer in GetCapabilities\n%s" % response)
|
||||
|
||||
def test_wms_getprojectsettings(self):
|
||||
query_string = "&".join(["%s=%s" % i for i in list({
|
||||
"MAP": urllib.parse.quote(self.projectPath),
|
||||
"SERVICE": "WMS",
|
||||
"VERSION": "1.1.1",
|
||||
"REQUEST": "GetProjectSettings"
|
||||
}.items())])
|
||||
|
||||
response, headers = self._get_fullaccess(query_string)
|
||||
self.assertTrue(
|
||||
str(response).find("<TreeName>Hello</TreeName>") != -1,
|
||||
"No Hello layer in GetProjectSettings\n%s" % response)
|
||||
self.assertTrue(
|
||||
str(response).find("<TreeName>Country</TreeName>") != -1,
|
||||
"No Country layer in GetProjectSettings\n%s" % response)
|
||||
self.assertTrue(
|
||||
str(response).find("<LayerDrawingOrder>Country_Labels,Country,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point</LayerDrawingOrder>") != -1,
|
||||
"LayerDrawingOrder in GetProjectSettings\n%s" % response)
|
||||
|
||||
response, headers = self._get_restricted(query_string)
|
||||
self.assertTrue(
|
||||
str(response).find("<TreeName>Hello</TreeName>") != -1,
|
||||
"No Hello layer in GetProjectSettings\n%s" % response)
|
||||
self.assertFalse(
|
||||
str(response).find("<TreeName>Country</TreeName>") != -1,
|
||||
"Country layer in GetProjectSettings\n%s" % response)
|
||||
self.assertTrue(
|
||||
str(response).find("<LayerDrawingOrder>Country_Labels,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point</LayerDrawingOrder>") != -1,
|
||||
"LayerDrawingOrder in GetProjectSettings\n%s" % response)
|
||||
|
||||
def test_wms_describelayer_hello(self):
|
||||
query_string = "&".join(["%s=%s" % i for i in list({
|
||||
"MAP": urllib.parse.quote(self.projectPath),
|
||||
|
Loading…
x
Reference in New Issue
Block a user