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 committed Jul 4, 2016
1 parent e102111 commit 5c270eb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 8 additions & 1 deletion python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip
Original file line number Diff line number Diff line change
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
9 changes: 6 additions & 3 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
Original file line number Diff line number Diff line change
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,8 +163,9 @@ 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" )
QString filterFunc = QString( "%1 %2 %3 AND %1 <= %4" )
.arg( attrName.replace( '\"', "\"\"" ),
firstRange ? ">=" : ">",
qgsDoubleToString( mLowerValue ),
qgsDoubleToString( mUpperValue ) );
QgsSymbolLayerV2Utils::createFunctionElement( doc, ruleElem, filterFunc );
Expand Down Expand Up @@ -569,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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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 5c270eb

Please sign in to comment.