Skip to content

Commit

Permalink
[Server] WMS GetCapabilities refactoring - Part 2
Browse files Browse the repository at this point in the history
Part 2 (the last) for removing QgsWMSProjectParser from GetCapabilities
  • Loading branch information
rldhont committed May 20, 2017
1 parent 258c872 commit 33b4582
Show file tree
Hide file tree
Showing 7 changed files with 1,131 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/server/qgsserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
59 changes: 59 additions & 0 deletions src/server/qgsserverprojectutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( "/" ), "" );
Expand Down
24 changes: 24 additions & 0 deletions src/server/qgsserverprojectutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 33b4582

Please sign in to comment.