Skip to content

Commit

Permalink
Fix first range when exporting graduated renderer to sld (fix #15212)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson authored and rldhont committed Oct 1, 2016
1 parent e6b1121 commit 8a28f9b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
9 changes: 8 additions & 1 deletion python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip
Expand Up @@ -29,7 +29,14 @@ class QgsRendererRangeV2
// debugging
QString dump() const;

void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
/** Creates a DOM element representing the range in SLD format.
* @param doc DOM document
* @param element destination DOM element
* @param props graduated renderer properties
* @param firstRange set to true if the range is the first range, where the lower value uses a <= test
* rather than a < test.
*/
void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props, bool firstRange = false ) const;

protected:
// for cpy+swap idiom
Expand Down
14 changes: 9 additions & 5 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
Expand Up @@ -141,7 +141,7 @@ QString QgsRendererRangeV2::dump() const
return QString( "%1 - %2::%3::%4\n" ).arg( mLowerValue ).arg( mUpperValue ).arg( mLabel, mSymbol.data() ? mSymbol->dump() : "(no symbol)" );
}

void QgsRendererRangeV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
void QgsRendererRangeV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props, bool firstRange ) const
{
if ( !mSymbol.data() || props.value( "attribute", "" ).isEmpty() )
return;
Expand All @@ -163,9 +163,11 @@ void QgsRendererRangeV2::toSld( QDomDocument &doc, QDomElement &element, QgsStri
ruleElem.appendChild( descrElem );

// create the ogc:Filter for the range
QString filterFunc = QString( "%1 > %2 AND %1 <= %3" )
.arg( attrName.replace( '\"', "\"\"" ) )
.arg( mLowerValue ).arg( mUpperValue );
QString filterFunc = QString( "%1 %2 %3 AND %1 <= %4" )
.arg( attrName.replace( '\"', "\"\"" ),
firstRange ? ">=" : ">",
qgsDoubleToString( mLowerValue ),
qgsDoubleToString( mUpperValue ) );
QgsSymbolLayerV2Utils::createFunctionElement( doc, ruleElem, filterFunc );

mSymbol->toSld( doc, ruleElem, props );
Expand Down Expand Up @@ -568,10 +570,12 @@ void QgsGraduatedSymbolRendererV2::toSld( QDomDocument& doc, QDomElement &elemen
props[ "scale" ] = mSizeScale->expression();

// create a Rule for each range
bool first = true;
for ( QgsRangeList::const_iterator it = mRanges.constBegin(); it != mRanges.constEnd(); ++it )
{
QgsStringMap catProps( props );
it->toSld( doc, element, catProps );
it->toSld( doc, element, catProps, first );
first = false;
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Expand Up @@ -53,7 +53,14 @@ class CORE_EXPORT QgsRendererRangeV2
// debugging
QString dump() const;

void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
/** Creates a DOM element representing the range in SLD format.
* @param doc DOM document
* @param element destination DOM element
* @param props graduated renderer properties
* @param firstRange set to true if the range is the first range, where the lower value uses a <= test
* rather than a < test.
*/
void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props, bool firstRange = false ) const;

protected:
double mLowerValue, mUpperValue;
Expand Down

0 comments on commit 8a28f9b

Please sign in to comment.