Skip to content

Commit

Permalink
Merge pull request #3549 from rldhont/release-2_14-aaime_sld
Browse files Browse the repository at this point in the history
Cherry-picking @aaime works on SLD to release-2_14
  • Loading branch information
rldhont committed Oct 1, 2016
2 parents 26d5c6b + da67550 commit d463ddd
Show file tree
Hide file tree
Showing 51 changed files with 3,702 additions and 110 deletions.
7 changes: 7 additions & 0 deletions python/core/qgsogcutils.sip
Expand Up @@ -59,5 +59,12 @@ class QgsOgcUtils
*/
static QDomElement expressionToOgcFilter( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage /Out/ );

/** Creates an OGC expression XML element.
* @return valid OGC expression QDomElement on success,
* otherwise null QDomElement
* @note added in 2.14.8
*/
static QDomElement expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );

};

19 changes: 17 additions & 2 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -733,7 +733,23 @@ class QgsVectorLayer : QgsMapLayer
*/
bool writeSymbology( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;

bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
/**
* Writes the symbology of the layer into the document provided in SLD 1.1 format
* @param node the node that will have the style element added to it.
* @param doc the document that will have the QDomNode added.
* @param errorMessage reference to string that will be updated with any error messages
* @param props a open ended set of properties that can drive/inform the SLD encoding
* @return true in case of success
*/
bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage, const QgsStringMap& props = QgsStringMap() ) const;

/**
* Read the symbology of the layer according to the information contained in
* the UserStyle element of a SLD style document
* @param node the node that have the style element in it.
* @param errorMessage reference to string that will be updated with any error messages
* @return true in case of success
*/
bool readSld( const QDomNode& node, QString& errorMessage );

/**
Expand Down Expand Up @@ -1820,4 +1836,3 @@ class QgsVectorLayer : QgsMapLayer


};

10 changes: 9 additions & 1 deletion python/core/symbology-ng/qgscategorizedsymbolrendererv2.sip
Expand Up @@ -28,7 +28,12 @@ class QgsRendererCategoryV2
// debugging
QString dump() const;

void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
/** Creates a DOM element representing the category in SLD format.
* @param doc DOM document
* @param element destination DOM element
* @param props graduated renderer properties
*/
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

protected:

Expand Down Expand Up @@ -65,7 +70,10 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2

virtual QgsCategorizedSymbolRendererV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities();
Expand Down
1 change: 1 addition & 0 deletions python/core/symbology-ng/qgsellipsesymbollayerv2.sip
Expand Up @@ -18,6 +18,7 @@ class QgsEllipseSymbolLayerV2 : QgsMarkerSymbolLayerV2
virtual QgsEllipseSymbolLayerV2* clone() const /Factory/;
QgsStringMap properties() const;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;
void writeSldMarker( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

Expand Down
5 changes: 5 additions & 0 deletions python/core/symbology-ng/qgsfillsymbollayerv2.sip
Expand Up @@ -32,6 +32,7 @@ class QgsSimpleFillSymbolLayerV2 : QgsFillSymbolLayerV2

virtual QgsSimpleFillSymbolLayerV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
Expand Down Expand Up @@ -661,6 +662,7 @@ class QgsSVGFillSymbolLayer: QgsImageFillSymbolLayer

virtual QgsSVGFillSymbolLayer* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

//getters and setters
Expand Down Expand Up @@ -720,6 +722,7 @@ class QgsLinePatternFillSymbolLayer: QgsImageFillSymbolLayer

virtual QgsLinePatternFillSymbolLayer* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

double estimateMaxBleed() const;
Expand Down Expand Up @@ -791,6 +794,7 @@ class QgsPointPatternFillSymbolLayer : QgsImageFillSymbolLayer

virtual QgsPointPatternFillSymbolLayer* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

double estimateMaxBleed() const;
Expand Down Expand Up @@ -879,6 +883,7 @@ class QgsCentroidFillSymbolLayerV2 : QgsFillSymbolLayerV2

virtual QgsCentroidFillSymbolLayerV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

void setColor( const QColor& color );
Expand Down
3 changes: 3 additions & 0 deletions python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip
Expand Up @@ -108,7 +108,10 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2

virtual QgsGraduatedSymbolRendererV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities();
Expand Down
2 changes: 2 additions & 0 deletions python/core/symbology-ng/qgslinesymbollayerv2.sip
Expand Up @@ -31,6 +31,7 @@ class QgsSimpleLineSymbolLayerV2 : QgsLineSymbolLayerV2

virtual QgsSimpleLineSymbolLayerV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
Expand Down Expand Up @@ -142,6 +143,7 @@ class QgsMarkerLineSymbolLayerV2 : QgsLineSymbolLayerV2

virtual QgsMarkerLineSymbolLayerV2* clone() const;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

void setColor( const QColor& color );
Expand Down
3 changes: 3 additions & 0 deletions python/core/symbology-ng/qgspointdisplacementrenderer.sip
Expand Up @@ -18,7 +18,10 @@ class QgsPointDisplacementRenderer : QgsFeatureRendererV2

virtual QgsPointDisplacementRenderer* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

/** Reimplemented from QgsFeatureRendererV2*/
bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
Expand Down
5 changes: 5 additions & 0 deletions python/core/symbology-ng/qgsrendererv2.sip
Expand Up @@ -205,6 +205,9 @@ class QgsFeatureRendererV2
//! create the SLD UserStyle element following the SLD v1.1 specs with the given name
//! @note added in 2.8
virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
//! create the SLD UserStyle element following the SLD v1.1 specs with the given name
//! @note added in 2.14.8
virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName, const QgsStringMap& props ) const;

/** Create a new renderer according to the information contained in
* the UserStyle element of a SLD style document
Expand All @@ -220,6 +223,8 @@ class QgsFeatureRendererV2

//! used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

//! return a list of symbology items for the legend
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
Expand Down
12 changes: 10 additions & 2 deletions python/core/symbology-ng/qgsrulebasedrendererv2.sip
Expand Up @@ -82,7 +82,7 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
*/
QSet<QString> usedAttributes();

//! @note available in python bindings as symbol2
//! @note available in python bindings as symbol2
QgsSymbolV2List symbols( const QgsRenderContext& context = QgsRenderContext() ) /PyName=symbols2/;

//! @note not available in python bindings
Expand Down Expand Up @@ -198,7 +198,12 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
//! clone this rule, return new instance
QgsRuleBasedRendererV2::Rule* clone() const /Factory/;

void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props );
/** Creates a DOM element representing the rule in SLD format.
* @param doc DOM document
* @param element destination DOM element
* @param props graduated renderer properties
*/
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props = QgsStringMap() );
static QgsRuleBasedRendererV2::Rule* createFromSld( QDomElement& element, QGis::GeometryType geomType ) /Factory/;

QDomElement save( QDomDocument& doc, QgsSymbolV2Map& symbolMap );
Expand Down Expand Up @@ -359,7 +364,10 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2

virtual QgsRuleBasedRendererV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

static QgsFeatureRendererV2* createFromSld( QDomElement& element, QGis::GeometryType geomType ) /Factory/;

Expand Down
3 changes: 3 additions & 0 deletions python/core/symbology-ng/qgssinglesymbolrendererv2.sip
Expand Up @@ -37,7 +37,10 @@ class QgsSingleSymbolRendererV2 : QgsFeatureRendererV2

virtual QgsSingleSymbolRendererV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;
static QgsFeatureRendererV2* createFromSld( QDomElement& element, QGis::GeometryType geomType );

//! returns bitwise OR-ed capabilities of the renderer
Expand Down
2 changes: 2 additions & 0 deletions python/core/symbology-ng/qgssymbollayerv2.sip
Expand Up @@ -107,6 +107,7 @@ class QgsSymbolLayerV2
*/
virtual QgsSymbolLayerV2* clone() const = 0 /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

virtual QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
Expand Down Expand Up @@ -377,6 +378,7 @@ class QgsMarkerSymbolLayerV2 : QgsSymbolLayerV2
void setOffset( QPointF offset );
QPointF offset();

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;
Expand Down
31 changes: 31 additions & 0 deletions python/core/symbology-ng/qgssymbollayerv2utils.sip
Expand Up @@ -204,6 +204,7 @@ class QgsSymbolLayerV2Utils
static void createGeometryElement( QDomDocument &doc, QDomElement &element, const QString& geomFunc );
static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );

static bool createExpressionElement( QDomDocument &doc, QDomElement &element, const QString& function );
static bool createFunctionElement( QDomDocument &doc, QDomElement &element, const QString& function );
static bool functionFromSldElement( QDomElement &element, QString &function );

Expand Down Expand Up @@ -412,4 +413,34 @@ class QgsSymbolLayerV2Utils
*/
static QList<double> prettyBreaks( double minimum, double maximum, int classes );

/** Rescales the given size based on the uomScale found in the props, if any is found, otherwise
* returns the value un-modified
* @note added in 2.14.8
*/
static double rescaleUom( double size, QgsSymbolV2::OutputUnit unit, const QgsStringMap& props );

/** Rescales the given point based on the uomScale found in the props, if any is found, otherwise
* returns a copy of the original point
* @note added in 2.14.8
*/
static QPointF rescaleUom( const QPointF& point, QgsSymbolV2::OutputUnit unit, const QgsStringMap& props ) /PyName=rescalePointUom/;

/** Rescales the given array based on the uomScale found in the props, if any is found, otherwise
* returns a copy of the original point
* @note added in 2.14.8
*/
static QVector<qreal> rescaleUom( const QVector<qreal>& array, QgsSymbolV2::OutputUnit unit, const QgsStringMap& props ) /PyName=rescaleArrayUom/;

/**
* Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into the SE Rule element
* @note added in 2.14.8
*/
static void applyScaleDependency( QDomDocument& doc, QDomElement& ruleElem, QgsStringMap& props );

/**
* Merges the local scale limits, if any, with the ones already in the map, if any
* @note added in 2.14.8
*/
static void mergeScaleDependencies( int mScaleMinDenom, int mScaleMaxDenom, QgsStringMap& props );

};
3 changes: 2 additions & 1 deletion python/core/symbology-ng/qgssymbolv2.sip
Expand Up @@ -152,7 +152,8 @@ class QgsSymbolV2

virtual QgsSymbolV2* clone() const = 0 /Factory/;

void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

OutputUnit outputUnit() const;
void setOutputUnit( OutputUnit u );
Expand Down
1 change: 1 addition & 0 deletions python/core/symbology-ng/qgsvectorfieldsymbollayer.sip
Expand Up @@ -44,6 +44,7 @@ class QgsVectorFieldSymbolLayer : QgsMarkerSymbolLayerV2
virtual QgsVectorFieldSymbolLayer* clone() const /Factory/;
QgsStringMap properties() const;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
Expand Down
9 changes: 7 additions & 2 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -1452,7 +1452,6 @@ void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg )
// Create the root element
QDomElement root = myDocument.createElementNS( "http://www.opengis.net/sld", "StyledLayerDescriptor" );
root.setAttribute( "version", "1.1.0" );
root.setAttribute( "units", "mm" ); // default qgsmaprenderer is Millimeters
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" );
Expand All @@ -1472,7 +1471,13 @@ void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg )
return;
}

if ( !vlayer->writeSld( namedLayerNode, myDocument, errorMsg ) )
QgsStringMap props;
if ( hasScaleBasedVisibility() )
{
props[ "scaleMinDenom" ] = QString::number( mMinScale );
props[ "scaleMaxDenom" ] = QString::number( mMaxScale );
}
if ( !vlayer->writeSld( namedLayerNode, myDocument, errorMsg, props ) )
{
errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
return;
Expand Down
44 changes: 44 additions & 0 deletions src/core/qgsogcutils.cpp
Expand Up @@ -2030,6 +2030,12 @@ QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp, QDomDo
"geometry", QString(), false, false, errorMessage );
}

QDomElement QgsOgcUtils::expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage )
{
return expressionToOgcExpression( exp, doc, GML_2_1_2, FILTER_OGC_1_0,
"geometry", QString(), false, false, errorMessage );
}

QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp,
QDomDocument& doc,
GMLVersion gmlVersion,
Expand Down Expand Up @@ -2067,6 +2073,44 @@ QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp,
return filterElem;
}

QDomElement QgsOgcUtils::expressionToOgcExpression( const QgsExpression& exp,
QDomDocument& doc,
GMLVersion gmlVersion,
FilterVersion filterVersion,
const QString& geometryName,
const QString& srsName,
bool honourAxisOrientation,
bool invertAxisOrientation,
QString* errorMessage )
{
const QgsExpression::Node* node = exp.rootNode();
if ( !node )
return QDomElement();

switch ( node->nodeType() )
{
case QgsExpression::ntFunction:
case QgsExpression::ntLiteral:
case QgsExpression::ntColumnRef:
{
QgsOgcUtilsExprToFilter utils( doc, gmlVersion, filterVersion, geometryName, srsName, honourAxisOrientation, invertAxisOrientation );
QDomElement exprRootElem = utils.expressionNodeToOgcFilter( node );

if ( errorMessage )
*errorMessage = utils.errorMessage();

if ( !exprRootElem.isNull() )
{
return exprRootElem;
}
break;
}
default:
*errorMessage = QObject::tr( "Node type not supported in expression translation: %1" ).arg( node->nodeType() );
}
// got an error
return QDomElement();
}

QDomElement QgsOgcUtilsExprToFilter::expressionNodeToOgcFilter( const QgsExpression::Node* node )
{
Expand Down

0 comments on commit d463ddd

Please sign in to comment.