Skip to content

Commit b4f21e2

Browse files
committedMar 30, 2014
Add QgsSLDConfigParser and create calss QgsConfigParserUtils for parts which are common between project parser and sld parser
1 parent e490991 commit b4f21e2

10 files changed

+1855
-169
lines changed
 

‎src/mapserver/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ SET ( qgis_mapserv_SRCS
4444
qgswfsprojectparser.cpp
4545
qgswmsprojectparser.cpp
4646
qgsserverprojectparser.cpp
47+
qgssldconfigparser.cpp
48+
qgsconfigparserutils.cpp
4749
)
4850

4951
# SET (qgis_mapserv_UIS
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/***************************************************************************
2+
qgsconfigparserutils.cpp
3+
------------------------
4+
begin : March 28, 2014
5+
copyright : (C) 2014 by Marco Hugentobler
6+
email : marco dot hugentobler at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsconfigparserutils.h"
19+
#include "qgsapplication.h"
20+
#include "qgscoordinatereferencesystem.h"
21+
#include "qgscoordinatetransform.h"
22+
#include "qgscrscache.h"
23+
#include "qgsmaplayer.h"
24+
#include "qgsrectangle.h"
25+
26+
#include <QDomDocument>
27+
#include <QDomElement>
28+
#include <QString>
29+
30+
#include <sqlite3.h>
31+
32+
class QgsCoordinateReferenceSystem;
33+
class QgsRectangle;
34+
class QDomDocument;
35+
class QDomElement;
36+
class QString;
37+
class QStringList;
38+
39+
void QgsConfigParserUtils::appendCRSElementsToLayer( QDomElement& layerElement, QDomDocument& doc,
40+
const QStringList &crsList, const QStringList& constrainedCrsList )
41+
{
42+
if ( layerElement.isNull() )
43+
{
44+
return;
45+
}
46+
47+
//insert the CRS elements after the title element to be in accordance with the WMS 1.3 specification
48+
QDomElement titleElement = layerElement.firstChildElement( "Title" );
49+
QDomElement abstractElement = layerElement.firstChildElement( "Abstract" );
50+
QDomElement CRSPrecedingElement = abstractElement.isNull() ? titleElement : abstractElement; //last element before the CRS elements
51+
52+
//In case the number of advertised CRS is constrained
53+
if ( constrainedCrsList.size() > 0 )
54+
{
55+
for ( int i = constrainedCrsList.size() - 1; i >= 0; --i )
56+
{
57+
appendCRSElementToLayer( layerElement, CRSPrecedingElement, constrainedCrsList.at( i ), doc );
58+
}
59+
}
60+
else //no crs constraint
61+
{
62+
foreach ( QString crs, crsList )
63+
{
64+
appendCRSElementToLayer( layerElement, CRSPrecedingElement, crs, doc );
65+
}
66+
}
67+
}
68+
69+
void QgsConfigParserUtils::appendCRSElementToLayer( QDomElement& layerElement, const QDomElement& precedingElement,
70+
const QString& crsText, QDomDocument& doc )
71+
{
72+
QString version = doc.documentElement().attribute( "version" );
73+
QDomElement crsElement = doc.createElement( version == "1.1.1" ? "SRS" : "CRS" );
74+
QDomText crsTextNode = doc.createTextNode( crsText );
75+
crsElement.appendChild( crsTextNode );
76+
layerElement.insertAfter( crsElement, precedingElement );
77+
}
78+
79+
void QgsConfigParserUtils::appendLayerBoundingBoxes( QDomElement& layerElem, QDomDocument& doc, const QgsRectangle& layerExtent,
80+
const QgsCoordinateReferenceSystem& layerCRS )
81+
{
82+
if ( layerElem.isNull() )
83+
{
84+
return;
85+
}
86+
87+
const QgsCoordinateReferenceSystem& wgs84 = QgsCRSCache::instance()->crsByAuthId( GEO_EPSG_CRS_AUTHID );
88+
89+
QString version = doc.documentElement().attribute( "version" );
90+
91+
//Ex_GeographicBoundingBox
92+
QDomElement ExGeoBBoxElement;
93+
//transform the layers native CRS into WGS84
94+
QgsCoordinateTransform exGeoTransform( layerCRS, wgs84 );
95+
QgsRectangle wgs84BoundingRect = exGeoTransform.transformBoundingBox( layerExtent );
96+
if ( version == "1.1.1" ) // WMS Version 1.1.1
97+
{
98+
ExGeoBBoxElement = doc.createElement( "LatLonBoundingBox" );
99+
ExGeoBBoxElement.setAttribute( "minx", QString::number( wgs84BoundingRect.xMinimum() ) );
100+
ExGeoBBoxElement.setAttribute( "maxx", QString::number( wgs84BoundingRect.xMaximum() ) );
101+
ExGeoBBoxElement.setAttribute( "miny", QString::number( wgs84BoundingRect.yMinimum() ) );
102+
ExGeoBBoxElement.setAttribute( "maxy", QString::number( wgs84BoundingRect.yMaximum() ) );
103+
}
104+
else // WMS Version 1.3.0
105+
{
106+
ExGeoBBoxElement = doc.createElement( "EX_GeographicBoundingBox" );
107+
QDomElement wBoundLongitudeElement = doc.createElement( "westBoundLongitude" );
108+
QDomText wBoundLongitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.xMinimum() ) );
109+
wBoundLongitudeElement.appendChild( wBoundLongitudeText );
110+
ExGeoBBoxElement.appendChild( wBoundLongitudeElement );
111+
QDomElement eBoundLongitudeElement = doc.createElement( "eastBoundLongitude" );
112+
QDomText eBoundLongitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.xMaximum() ) );
113+
eBoundLongitudeElement.appendChild( eBoundLongitudeText );
114+
ExGeoBBoxElement.appendChild( eBoundLongitudeElement );
115+
QDomElement sBoundLatitudeElement = doc.createElement( "southBoundLatitude" );
116+
QDomText sBoundLatitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.yMinimum() ) );
117+
sBoundLatitudeElement.appendChild( sBoundLatitudeText );
118+
ExGeoBBoxElement.appendChild( sBoundLatitudeElement );
119+
QDomElement nBoundLatitudeElement = doc.createElement( "northBoundLatitude" );
120+
QDomText nBoundLatitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.yMaximum() ) );
121+
nBoundLatitudeElement.appendChild( nBoundLatitudeText );
122+
ExGeoBBoxElement.appendChild( nBoundLatitudeElement );
123+
}
124+
125+
126+
//BoundingBox element
127+
QDomElement bBoxElement = doc.createElement( "BoundingBox" );
128+
if ( layerCRS.isValid() )
129+
{
130+
bBoxElement.setAttribute( version == "1.1.1" ? "SRS" : "CRS", layerCRS.authid() );
131+
}
132+
133+
QgsRectangle r( layerExtent );
134+
if ( version != "1.1.1" && layerCRS.axisInverted() )
135+
{
136+
r.invert();
137+
}
138+
139+
bBoxElement.setAttribute( "minx", QString::number( r.xMinimum() ) );
140+
bBoxElement.setAttribute( "miny", QString::number( r.yMinimum() ) );
141+
bBoxElement.setAttribute( "maxx", QString::number( r.xMaximum() ) );
142+
bBoxElement.setAttribute( "maxy", QString::number( r.yMaximum() ) );
143+
144+
QDomElement lastCRSElem = layerElem.lastChildElement( version == "1.1.1" ? "SRS" : "CRS" );
145+
if ( !lastCRSElem.isNull() )
146+
{
147+
layerElem.insertAfter( ExGeoBBoxElement, lastCRSElem );
148+
layerElem.insertAfter( bBoxElement, ExGeoBBoxElement );
149+
}
150+
else
151+
{
152+
layerElem.appendChild( ExGeoBBoxElement );
153+
layerElem.appendChild( bBoxElement );
154+
}
155+
}
156+
157+
QStringList QgsConfigParserUtils::createCRSListForLayer( QgsMapLayer* theMapLayer )
158+
{
159+
QStringList crsNumbers;
160+
QString myDatabaseFileName = QgsApplication::srsDbFilePath();
161+
sqlite3 *myDatabase;
162+
const char *myTail;
163+
sqlite3_stmt *myPreparedStatement;
164+
int myResult;
165+
166+
//check the db is available
167+
myResult = sqlite3_open( myDatabaseFileName.toLocal8Bit().data(), &myDatabase );
168+
if ( myResult && theMapLayer )
169+
{
170+
//if the database cannot be opened, add at least the epsg number of the source coordinate system
171+
crsNumbers.push_back( theMapLayer->crs().authid() );
172+
return crsNumbers;
173+
};
174+
QString mySql = "select upper(auth_name||':'||auth_id) from tbl_srs";
175+
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.length(), &myPreparedStatement, &myTail );
176+
if ( myResult == SQLITE_OK )
177+
{
178+
while ( sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
179+
{
180+
crsNumbers.push_back( QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) ) );
181+
}
182+
}
183+
sqlite3_finalize( myPreparedStatement );
184+
sqlite3_close( myDatabase );
185+
return crsNumbers;
186+
}

‎src/mapserver/qgsconfigparserutils.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/***************************************************************************
2+
qgsconfigparserutils.h
3+
------------------------
4+
begin : March 28, 2014
5+
copyright : (C) 2014 by Marco Hugentobler
6+
email : marco dot hugentobler at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSCONFIGPARSERUTILS_H
19+
#define QGSCONFIGPARSERUTILS_H
20+
21+
#include <QStringList>
22+
23+
class QgsCoordinateReferenceSystem;
24+
class QgsMapLayer;
25+
class QgsRectangle;
26+
class QDomDocument;
27+
class QDomElement;
28+
class QString;
29+
30+
class QgsConfigParserUtils
31+
{
32+
public:
33+
static void appendCRSElementsToLayer( QDomElement& layerElement, QDomDocument& doc, const QStringList &crsList,
34+
const QStringList& constrainedCrsList );
35+
static void appendCRSElementToLayer( QDomElement& layerElement, const QDomElement& precedingElement,
36+
const QString& crsText, QDomDocument& doc );
37+
static void appendLayerBoundingBoxes( QDomElement& layerElem, QDomDocument& doc, const QgsRectangle& layerExtent,
38+
const QgsCoordinateReferenceSystem& layerCRS );
39+
/**Returns a list of supported EPSG coordinate system numbers from a layer*/
40+
static QStringList createCRSListForLayer( QgsMapLayer* theMapLayer );
41+
};
42+
43+
#endif // QGSCONFIGPARSERUTILS_H

‎src/mapserver/qgsserverprojectparser.cpp

Lines changed: 3 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgsserverprojectparser.h"
1919
#include "qgsapplication.h"
20+
#include "qgsconfigparserutils.h"
2021
#include "qgscrscache.h"
2122
#include "qgsdatasourceuri.h"
2223
#include "qgsmslayercache.h"
@@ -27,8 +28,6 @@
2728
#include <QStringList>
2829
#include <QUrl>
2930

30-
#include <sqlite3.h>
31-
3231
QgsServerProjectParser::QgsServerProjectParser( QDomDocument* xmlDoc, const QString& filePath ):
3332
mXMLDoc( xmlDoc ), mProjectPath( filePath )
3433
{
@@ -349,7 +348,7 @@ void QgsServerProjectParser::combineExtentAndCrsOfGroupChildren( QDomElement& gr
349348
}
350349
}
351350

352-
appendCRSElementsToLayer( groupElem, doc, combinedCRSSet.toList() );
351+
QgsConfigParserUtils::appendCRSElementsToLayer( groupElem, doc, combinedCRSSet.toList(), supportedOutputCrsList() );
353352

354353
const QgsCoordinateReferenceSystem& groupCRS = projectCRS();
355354
if ( considerMapExtent )
@@ -360,157 +359,7 @@ void QgsServerProjectParser::combineExtentAndCrsOfGroupChildren( QDomElement& gr
360359
combinedBBox = mapRect;
361360
}
362361
}
363-
appendLayerBoundingBoxes( groupElem, doc, combinedBBox, groupCRS );
364-
}
365-
366-
QStringList QgsServerProjectParser::createCRSListForLayer( QgsMapLayer* theMapLayer ) const
367-
{
368-
QStringList crsNumbers;
369-
QString myDatabaseFileName = QgsApplication::srsDbFilePath();
370-
sqlite3 *myDatabase;
371-
const char *myTail;
372-
sqlite3_stmt *myPreparedStatement;
373-
int myResult;
374-
375-
//check the db is available
376-
myResult = sqlite3_open( myDatabaseFileName.toLocal8Bit().data(), &myDatabase );
377-
if ( myResult && theMapLayer )
378-
{
379-
//if the database cannot be opened, add at least the epsg number of the source coordinate system
380-
crsNumbers.push_back( theMapLayer->crs().authid() );
381-
return crsNumbers;
382-
};
383-
QString mySql = "select upper(auth_name||':'||auth_id) from tbl_srs";
384-
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.length(), &myPreparedStatement, &myTail );
385-
if ( myResult == SQLITE_OK )
386-
{
387-
while ( sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
388-
{
389-
crsNumbers.push_back( QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) ) );
390-
}
391-
}
392-
sqlite3_finalize( myPreparedStatement );
393-
sqlite3_close( myDatabase );
394-
return crsNumbers;
395-
}
396-
397-
void QgsServerProjectParser::appendCRSElementsToLayer( QDomElement& layerElement, QDomDocument& doc, const QStringList &crsList ) const
398-
{
399-
if ( layerElement.isNull() )
400-
{
401-
return;
402-
}
403-
404-
//insert the CRS elements after the title element to be in accordance with the WMS 1.3 specification
405-
QDomElement titleElement = layerElement.firstChildElement( "Title" );
406-
QDomElement abstractElement = layerElement.firstChildElement( "Abstract" );
407-
QDomElement CRSPrecedingElement = abstractElement.isNull() ? titleElement : abstractElement; //last element before the CRS elements
408-
409-
//In case the number of advertised CRS is constrained
410-
QStringList constrainedCrsList = supportedOutputCrsList();
411-
if ( constrainedCrsList.size() > 0 )
412-
{
413-
for ( int i = constrainedCrsList.size() - 1; i >= 0; --i )
414-
{
415-
appendCRSElementToLayer( layerElement, CRSPrecedingElement, constrainedCrsList.at( i ), doc );
416-
}
417-
}
418-
else //no crs constraint
419-
{
420-
foreach ( QString crs, crsList )
421-
{
422-
appendCRSElementToLayer( layerElement, CRSPrecedingElement, crs, doc );
423-
}
424-
}
425-
}
426-
427-
void QgsServerProjectParser::appendCRSElementToLayer( QDomElement& layerElement, const QDomElement& precedingElement, const QString& crsText, QDomDocument& doc ) const
428-
{
429-
QString version = doc.documentElement().attribute( "version" );
430-
QDomElement crsElement = doc.createElement( version == "1.1.1" ? "SRS" : "CRS" );
431-
QDomText crsTextNode = doc.createTextNode( crsText );
432-
crsElement.appendChild( crsTextNode );
433-
layerElement.insertAfter( crsElement, precedingElement );
434-
}
435-
436-
void QgsServerProjectParser::appendLayerBoundingBoxes( QDomElement& layerElem,
437-
QDomDocument& doc,
438-
const QgsRectangle& layerExtent,
439-
const QgsCoordinateReferenceSystem& layerCRS ) const
440-
{
441-
if ( layerElem.isNull() )
442-
{
443-
return;
444-
}
445-
446-
const QgsCoordinateReferenceSystem& wgs84 = QgsCRSCache::instance()->crsByAuthId( GEO_EPSG_CRS_AUTHID );
447-
448-
QString version = doc.documentElement().attribute( "version" );
449-
450-
//Ex_GeographicBoundingBox
451-
QDomElement ExGeoBBoxElement;
452-
//transform the layers native CRS into WGS84
453-
QgsCoordinateTransform exGeoTransform( layerCRS, wgs84 );
454-
QgsRectangle wgs84BoundingRect = exGeoTransform.transformBoundingBox( layerExtent );
455-
if ( version == "1.1.1" ) // WMS Version 1.1.1
456-
{
457-
ExGeoBBoxElement = doc.createElement( "LatLonBoundingBox" );
458-
ExGeoBBoxElement.setAttribute( "minx", QString::number( wgs84BoundingRect.xMinimum() ) );
459-
ExGeoBBoxElement.setAttribute( "maxx", QString::number( wgs84BoundingRect.xMaximum() ) );
460-
ExGeoBBoxElement.setAttribute( "miny", QString::number( wgs84BoundingRect.yMinimum() ) );
461-
ExGeoBBoxElement.setAttribute( "maxy", QString::number( wgs84BoundingRect.yMaximum() ) );
462-
}
463-
else // WMS Version 1.3.0
464-
{
465-
ExGeoBBoxElement = doc.createElement( "EX_GeographicBoundingBox" );
466-
QDomElement wBoundLongitudeElement = doc.createElement( "westBoundLongitude" );
467-
QDomText wBoundLongitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.xMinimum() ) );
468-
wBoundLongitudeElement.appendChild( wBoundLongitudeText );
469-
ExGeoBBoxElement.appendChild( wBoundLongitudeElement );
470-
QDomElement eBoundLongitudeElement = doc.createElement( "eastBoundLongitude" );
471-
QDomText eBoundLongitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.xMaximum() ) );
472-
eBoundLongitudeElement.appendChild( eBoundLongitudeText );
473-
ExGeoBBoxElement.appendChild( eBoundLongitudeElement );
474-
QDomElement sBoundLatitudeElement = doc.createElement( "southBoundLatitude" );
475-
QDomText sBoundLatitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.yMinimum() ) );
476-
sBoundLatitudeElement.appendChild( sBoundLatitudeText );
477-
ExGeoBBoxElement.appendChild( sBoundLatitudeElement );
478-
QDomElement nBoundLatitudeElement = doc.createElement( "northBoundLatitude" );
479-
QDomText nBoundLatitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.yMaximum() ) );
480-
nBoundLatitudeElement.appendChild( nBoundLatitudeText );
481-
ExGeoBBoxElement.appendChild( nBoundLatitudeElement );
482-
}
483-
484-
485-
//BoundingBox element
486-
QDomElement bBoxElement = doc.createElement( "BoundingBox" );
487-
if ( layerCRS.isValid() )
488-
{
489-
bBoxElement.setAttribute( version == "1.1.1" ? "SRS" : "CRS", layerCRS.authid() );
490-
}
491-
492-
QgsRectangle r( layerExtent );
493-
if ( version != "1.1.1" && layerCRS.axisInverted() )
494-
{
495-
r.invert();
496-
}
497-
498-
bBoxElement.setAttribute( "minx", QString::number( r.xMinimum() ) );
499-
bBoxElement.setAttribute( "miny", QString::number( r.yMinimum() ) );
500-
bBoxElement.setAttribute( "maxx", QString::number( r.xMaximum() ) );
501-
bBoxElement.setAttribute( "maxy", QString::number( r.yMaximum() ) );
502-
503-
QDomElement lastCRSElem = layerElem.lastChildElement( version == "1.1.1" ? "SRS" : "CRS" );
504-
if ( !lastCRSElem.isNull() )
505-
{
506-
layerElem.insertAfter( ExGeoBBoxElement, lastCRSElem );
507-
layerElem.insertAfter( bBoxElement, ExGeoBBoxElement );
508-
}
509-
else
510-
{
511-
layerElem.appendChild( ExGeoBBoxElement );
512-
layerElem.appendChild( bBoxElement );
513-
}
362+
QgsConfigParserUtils::appendLayerBoundingBoxes( groupElem, doc, combinedBBox, groupCRS );
514363
}
515364

516365
void QgsServerProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocument& doc, QgsMapLayer* currentLayer ) const

‎src/mapserver/qgsserverprojectparser.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,12 @@ class QgsServerProjectParser
5050
@return the maplayer or 0 in case of error*/
5151
QgsMapLayer* createLayerFromElement( const QDomElement& elem, bool useCache = true ) const;
5252

53-
QStringList createCRSListForLayer( QgsMapLayer* theMapLayer ) const;
54-
5553
/**Returns the layer id under a <legendlayer> tag in the QGIS projectfile*/
5654
QString layerIdFromLegendLayer( const QDomElement& legendLayer ) const;
5755

5856
/**@param considerMapExtent Take user-defined map extent instead of data-calculated extent if present in project file*/
5957
void combineExtentAndCrsOfGroupChildren( QDomElement& groupElement, QDomDocument& doc, bool considerMapExtent = false ) const;
6058

61-
void appendCRSElementsToLayer( QDomElement& layerElement, QDomDocument& doc, const QStringList &crsList ) const;
62-
63-
void appendCRSElementToLayer( QDomElement& layerElement, const QDomElement& precedingElement, const QString& crsText, QDomDocument& doc ) const;
64-
65-
void appendLayerBoundingBoxes( QDomElement& layerElem, QDomDocument& doc, const QgsRectangle& layerExtent,
66-
const QgsCoordinateReferenceSystem& layerCRS ) const;
67-
6859
void addLayerProjectSettings( QDomElement& layerElem, QDomDocument& doc, QgsMapLayer* currentLayer ) const;
6960

7061
QgsRectangle layerBoundingBoxInProjectCRS( const QDomElement& layerElem, const QDomDocument &doc ) const;

‎src/mapserver/qgssldconfigparser.cpp

Lines changed: 1407 additions & 0 deletions
Large diffs are not rendered by default.

‎src/mapserver/qgssldconfigparser.h

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/***************************************************************************
2+
qgssldconfigparser.h
3+
--------------------
4+
begin : March 28, 2014
5+
copyright : (C) 2014 by Marco Hugentobler
6+
email : marco dot hugentobler at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSSLDCONFIGPARSER_H
19+
#define QGSSLDCONFIGPARSER_H
20+
21+
#include "qgswmsconfigparser.h"
22+
23+
class QgsFeatureRendererV2;
24+
class QgsVectorLayer;
25+
class QgsRasterLayer;
26+
27+
class QgsSLDConfigParser: public QgsWMSConfigParser
28+
{
29+
public:
30+
/**Constructor takes a dom document as argument. The class takes ownership of the document and deletes it in the destructor
31+
@param doc SLD document
32+
@param parameterMap map containing the wms request parameters*/
33+
QgsSLDConfigParser( QDomDocument* doc, const QMap<QString, QString>& parameters );
34+
virtual ~QgsSLDConfigParser();
35+
36+
void setFallbackParser( QgsWMSConfigParser* p ) { mFallbackParser = p; }
37+
38+
/**Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.
39+
@param fullProjectInformation If true: add extended project information (does not validate against WMS schema)*/
40+
void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc, const QString& version, bool fullProjectSettings = false ) const;
41+
42+
/**Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned*/
43+
QList<QgsMapLayer*> mapLayerFromStyle( const QString& lName, const QString& styleName, bool useCache = true ) const;
44+
45+
/**Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success*/
46+
int layersAndStyles( QStringList& layers, QStringList& styles ) const;
47+
48+
/**Returns the xml fragment of a style*/
49+
QDomDocument getStyle( const QString& styleName, const QString& layerName ) const;
50+
51+
/**Returns the xml fragment of layers styles*/
52+
QDomDocument getStyles( QStringList& layerList ) const;
53+
54+
/**Returns if output are MM or PIXEL*/
55+
QgsMapRenderer::OutputUnits outputUnits() const;
56+
57+
/**Returns an ID-list of layers which are not queryable (comes from <properties> -> <Identify> -> <disabledLayers in the project file*/
58+
QStringList identifyDisabledLayers() const;
59+
60+
/**True if the feature info response should contain the wkt geometry for vector features*/
61+
bool featureInfoWithWktGeometry() const;
62+
63+
/**Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias*/
64+
QHash<QString, QString> featureInfoLayerAliasMap() const;
65+
66+
QString featureInfoDocumentElement( const QString& defaultValue ) const;
67+
68+
QString featureInfoDocumentElementNS() const;
69+
70+
QString featureInfoSchema() const;
71+
72+
/**Return feature info in format SIA2045?*/
73+
bool featureInfoFormatSIA2045() const;
74+
75+
/**Draw text annotation items from the QGIS projectfile*/
76+
void drawOverlays( QPainter* p, int dpi, int width, int height ) const;
77+
78+
//todo: fixme
79+
void loadLabelSettings( QgsLabelingEngineInterface* lbl );
80+
81+
QString serviceUrl() const;
82+
83+
QStringList wfsLayerNames() const;
84+
85+
void owsGeneralAndResourceList( QDomElement& parentElement, QDomDocument& doc, const QString& strHref ) const;
86+
87+
//legend
88+
double legendBoxSpace() const;
89+
double legendLayerSpace() const;
90+
double legendLayerTitleSpace() const;
91+
double legendSymbolSpace() const;
92+
double legendIconLabelSpace() const;
93+
double legendSymbolWidth() const;
94+
double legendSymbolHeight() const;
95+
const QFont& legendLayerFont() const;
96+
const QFont& legendItemFont() const;
97+
98+
double maxWidth() const;
99+
double maxHeight() const;
100+
101+
//printing
102+
103+
/**Creates a print composition, usually for a GetPrint request. Replaces map and label parameters*/
104+
QgsComposition* createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap ) const;
105+
106+
/**Creates a composition from the project file (probably delegated to the fallback parser)*/
107+
QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlFrameList ) const;
108+
109+
/**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
110+
void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
111+
112+
void setScaleDenominator( double denom );
113+
void addExternalGMLData( const QString& layerName, QDomDocument* gmlDoc );
114+
115+
QList< QPair< QString, QgsLayerCoordinateTransform > > layerCoordinateTransforms() const;
116+
117+
private:
118+
119+
/**SLD as dom document*/
120+
QDomDocument* mXMLDoc;
121+
122+
/**Map containing the WMS parameters of the request*/
123+
QMap<QString, QString> mParameterMap;
124+
125+
QString mSLDNamespace;
126+
127+
/**Output units (pixel or mm)*/
128+
QgsMapRenderer::OutputUnits mOutputUnits;
129+
130+
QgsWMSConfigParser* mFallbackParser;
131+
132+
QFont mLegendLayerFont;
133+
134+
QFont mLegendItemFont;
135+
136+
/**Stores pointers to layers that have to be removed after the request*/
137+
mutable QList<QgsMapLayer*> mLayersToRemove;
138+
139+
/**Stores the temporary file objects. The class takes ownership of the objects and deletes them in the destructor*/
140+
mutable QList<QTemporaryFile*> mFilesToRemove;
141+
142+
/**Stores paths of files that need to be removed after each request (necessary because of contours shapefiles that
143+
cannot be handles with QTemporaryFile*/
144+
mutable QList<QString> mFilePathsToRemove;
145+
146+
//default constructor forbidden
147+
QgsSLDConfigParser();
148+
149+
/**Returns a list of all <NamedLayer> element that match the layer name. Returns an empty list if no such layer*/
150+
QList<QDomElement> findNamedLayerElements( const QString& layerName ) const;
151+
152+
/**Returns the <UserStyle> node of a given <UserLayer> or a null node in case of failure*/
153+
QDomElement findUserStyleElement( const QDomElement& userLayerElement, const QString& styleName ) const;
154+
155+
/**Creates a Renderer from a UserStyle SLD node. Returns 0 in case of error*/
156+
QgsFeatureRendererV2* rendererFromUserStyle( const QDomElement& userStyleElement, QgsVectorLayer* vec ) const;
157+
158+
/**Searches for a <TextSymbolizer> element and applies the settings to the vector layer
159+
@return true if settings have been applied, false in case of <TextSymbolizer> element not present or error*/
160+
bool labelSettingsFromUserStyle( const QDomElement& userStyleElement, QgsVectorLayer* vec ) const;
161+
162+
/**Searches for a <RasterSymbolizer> element and applies the settings to the raster layer
163+
@return true if settings have been applied, false in case of error*/
164+
bool rasterSymbologyFromUserStyle( const QDomElement& userStyleElement, QgsRasterLayer* r ) const;
165+
166+
/**Creates a line layer (including renderer) from contour symboliser
167+
@return the layer or 0 if no layer could be created*/
168+
QgsVectorLayer* contourLayerFromRaster( const QDomElement& userStyleElem, QgsRasterLayer* rasterLayer ) const;
169+
170+
/**Returns the <UserLayer> dom node or a null node in case of failure*/
171+
QDomElement findUserLayerElement( const QString& layerName ) const;
172+
173+
/**Creates a vector layer from a <UserLayer> tag.
174+
@param layerName the WMS layer name. This is only necessary for the fallback SLD parser
175+
@return 0 in case of error.
176+
Delegates the work to specific methods for <SendedVDS>, <HostedVDS> or <RemoteOWS>*/
177+
QgsMapLayer* mapLayerFromUserLayer( const QDomElement& userLayerElem, const QString& layerName, bool allowCaching = true ) const;
178+
179+
/**Reads attributes "epsg" or "proj" from layer element and sets specified CRS if present*/
180+
void setCrsForLayer( const QDomElement& layerElem, QgsMapLayer* ml ) const;
181+
};
182+
183+
#endif // QGSSLDCONFIGPARSER_H

‎src/mapserver/qgswmsconfigparser.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,14 @@ class QgsWMSConfigParser
9898
/**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
9999
virtual void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;
100100

101-
virtual void setFallbackParser( QgsWMSConfigParser* p ) {}
102101
virtual void setScaleDenominator( double denom ) = 0;
103102
virtual void addExternalGMLData( const QString& layerName, QDomDocument* gmlDoc ) = 0;
104103

105104
virtual QList< QPair< QString, QgsLayerCoordinateTransform > > layerCoordinateTransforms() const = 0;
105+
#if 0
106+
/**List of GML datasets passed outside SLD (e.g. in a SOAP request). Key of the map is the layer name*/
107+
QMap<QString, QDomDocument*> mExternalGMLDatasets;
108+
#endif //0
106109
};
107110

108111
#endif // QGSWMSCONFIGPARSER_H

‎src/mapserver/qgswmsprojectparser.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
***************************************************************************/
1717

1818
#include "qgswmsprojectparser.h"
19+
#include "qgsconfigparserutils.h"
1920
#include "qgslogger.h"
2021
#include "qgsmaplayer.h"
2122
#include "qgsmapserviceexception.h"
@@ -866,11 +867,11 @@ void QgsWMSProjectParser::addLayers( QDomDocument &doc,
866867
//CRS
867868
if ( geometryLayer )
868869
{
869-
QStringList crsList = mProjectParser.createCRSListForLayer( currentLayer );
870-
mProjectParser.appendCRSElementsToLayer( layerElem, doc, crsList );
870+
QStringList crsList = QgsConfigParserUtils::createCRSListForLayer( currentLayer );
871+
QgsConfigParserUtils::appendCRSElementsToLayer( layerElem, doc, crsList, mProjectParser.supportedOutputCrsList() );
871872

872873
//Ex_GeographicBoundingBox
873-
mProjectParser.appendLayerBoundingBoxes( layerElem, doc, currentLayer->extent(), currentLayer->crs() );
874+
QgsConfigParserUtils::appendLayerBoundingBoxes( layerElem, doc, currentLayer->extent(), currentLayer->crs() );
874875
}
875876

876877
//only one default style in project file mode

‎src/mapserver/qgswmsserver.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "qgsvectorlayer.h"
3535
#include "qgslogger.h"
3636
#include "qgsmapserviceexception.h"
37-
#include "qgssldparser.h"
37+
#include "qgssldconfigparser.h"
3838
#include "qgssymbolv2.h"
3939
#include "qgsrendererv2.h"
4040
#include "qgslegendmodel.h"
@@ -1562,7 +1562,28 @@ int QgsWMSServer::initializeSLDParser( QStringList& layersList, QStringList& sty
15621562
QgsDebugMsg( "Error, could not create DomDocument from SLD" );
15631563
QgsDebugMsg( QString( "The error message is: %1" ).arg( errorMsg ) );
15641564
delete theDocument;
1565-
return 0;
1565+
return 1;
1566+
}
1567+
1568+
QgsSLDConfigParser* userSLDParser = new QgsSLDConfigParser( theDocument, mParameters );
1569+
userSLDParser->setFallbackParser( mConfigParser );
1570+
mConfigParser = userSLDParser;
1571+
//now replace the content of layersList and stylesList (if present)
1572+
layersList.clear();
1573+
stylesList.clear();
1574+
QStringList layersSTDList;
1575+
QStringList stylesSTDList;
1576+
if ( mConfigParser->layersAndStyles( layersSTDList, stylesSTDList ) != 0 )
1577+
{
1578+
QgsDebugMsg( "Error, no layers and styles found in SLD" );
1579+
return 2;
1580+
}
1581+
QStringList::const_iterator layersIt;
1582+
QStringList::const_iterator stylesIt;
1583+
for ( layersIt = layersSTDList.constBegin(), stylesIt = stylesSTDList.constBegin(); layersIt != layersSTDList.constEnd(); ++layersIt, ++stylesIt )
1584+
{
1585+
layersList << *layersIt;
1586+
stylesList << *stylesIt;
15661587
}
15671588

15681589
#if 0 //todo: fixme

0 commit comments

Comments
 (0)
Please sign in to comment.