Skip to content
Permalink
Browse files

Activating WMS getStyle REQUEST for .qgs mapfile

A getStyle REQUEST has been developped for SLD mapfile.
qgsVectorLayer has a method writeSld. It was easy to activate getStyle
for .qgsmapfile
  • Loading branch information
rldhont committed May 14, 2013
1 parent 12fe4fa commit 4ac52cff3e85164e48dd3648b5b76c6f365ad329
Showing with 38 additions and 4 deletions.
  1. +38 −4 src/mapserver/qgsprojectparser.cpp
@@ -953,10 +953,44 @@ int QgsProjectParser::layersAndStyles( QStringList& layers, QStringList& styles
}

QDomDocument QgsProjectParser::getStyle( const QString& styleName, const QString& layerName ) const
{
Q_UNUSED( styleName );
Q_UNUSED( layerName );
return QDomDocument();
{
QDomDocument myDocument = QDomDocument();

QDomNode header = myDocument.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" );
myDocument.appendChild( header );

// Create the root element
QDomElement root = myDocument.createElementNS( "http://www.opengis.net/sld", "StyledLayerDescriptor" );
root.setAttribute( "version", "1.1.0" );
root.setAttribute( "xsi:schemaLocation", "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" );
root.setAttribute( "xmlns:ogc", "http://www.opengis.net/ogc" );
root.setAttribute( "xmlns:se", "http://www.opengis.net/se" );
root.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
root.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
myDocument.appendChild( root );

QList<QgsMapLayer*> layerList = mapLayerFromStyle( layerName, styleName );
if ( layerList.size() < 1 )
{
throw QgsMapServiceException( "Error", QString( "The layer for the TypeName '%1' is not found" ).arg( layerName ) );
}

QgsMapLayer* currentLayer = layerList.at( 0 );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( !layer )
{
throw QgsMapServiceException( "Error", QString( "Could not get style because:\n%1" ).arg( "Non-vector layers not supported yet" ) );
}
// Create the NamedLayer element
QDomElement namedLayerNode = myDocument.createElement( "NamedLayer" );
root.appendChild( namedLayerNode );

QString errorMsg;
if ( !layer->writeSld( namedLayerNode, myDocument, errorMsg ) )
{
throw QgsMapServiceException( "Error", QString( "Could not get style because:\n%1" ).arg( errorMsg ) );
}
return myDocument;
}

QgsMapRenderer::OutputUnits QgsProjectParser::outputUnits() const

0 comments on commit 4ac52cf

Please sign in to comment.
You can’t perform that action at this time.