Skip to content

Commit

Permalink
WMS server: Support <NamedStyle> in SLD
Browse files Browse the repository at this point in the history
When using <NamedStyle> make sure the passed SLD XML has attribute units="mm"
in the root <StyledLayerDescriptor> tag. Otherwise the WMS server applies scaling
as if all sizes were in pixels. The correct approach would be to just scale
sizes when loading symbols from SLD - not to apply such scaling globally

This code has been funded by Tuscany Region (Italy) - SITA (CIG: 6002233F59) and commissioned to Gis3W s.a.s.
  • Loading branch information
wonder-sk committed Jan 14, 2015
1 parent 2e4c7c9 commit 8ab4472
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/server/qgssldconfigparser.cpp
Expand Up @@ -256,6 +256,18 @@ QList<QgsMapLayer*> QgsSLDConfigParser::mapLayerFromStyle( const QString& lName,
}
}
}

// try with a predefined named style
QDomElement namedStyleElement = findNamedStyleElement( namedLayerElemList[i], styleName );
if ( !namedStyleElement.isNull() )
{
fallbackLayerList = mFallbackParser->mapLayerFromStyle( lName, styleName, false );
if ( fallbackLayerList.size() > 0 )
{
resultList << fallbackLayerList;
return resultList;
}
}
}

QDomElement userLayerElement = findUserLayerElement( lName );
Expand Down Expand Up @@ -799,6 +811,27 @@ QDomElement QgsSLDConfigParser::findUserStyleElement( const QDomElement& userLay
return defaultResult;
}

QDomElement QgsSLDConfigParser::findNamedStyleElement( const QDomElement& layerElement, const QString& styleName ) const
{
QDomElement defaultResult;
if ( !layerElement.isNull() )
{
QDomNodeList styleList = layerElement.elementsByTagName( "NamedStyle" );
for ( int i = 0; i < styleList.size(); ++i )
{
QDomNodeList nameList = styleList.item( i ).toElement().elementsByTagName( "Name" );
if ( nameList.size() > 0 )
{
if ( nameList.item( 0 ).toElement().text() == styleName )
{
return styleList.item( i ).toElement();
}
}
}
}
return defaultResult;
}

QgsFeatureRendererV2* QgsSLDConfigParser::rendererFromUserStyle( const QDomElement& userStyleElement, QgsVectorLayer* vec ) const
{
if ( !vec || userStyleElement.isNull() )
Expand Down
3 changes: 3 additions & 0 deletions src/server/qgssldconfigparser.h
Expand Up @@ -159,6 +159,9 @@ class QgsSLDConfigParser : public QgsWMSConfigParser
/**Returns the <UserStyle> node of a given <UserLayer> or a null node in case of failure*/
QDomElement findUserStyleElement( const QDomElement& userLayerElement, const QString& styleName ) const;

/**Returns the <NamedStyle> node of a given <NamedLayer> or a null node in case of failure*/
QDomElement findNamedStyleElement( const QDomElement& layerElement, const QString& styleName ) const;

/**Creates a Renderer from a UserStyle SLD node. Returns 0 in case of error*/
QgsFeatureRendererV2* rendererFromUserStyle( const QDomElement& userStyleElement, QgsVectorLayer* vec ) const;

Expand Down

0 comments on commit 8ab4472

Please sign in to comment.