Skip to content
Permalink
Browse files

Fixes #16706, categorized symbology matching lack of value is not pro…

…perly encoded in SLD
  • Loading branch information
aaime authored and nyalldawson committed Jun 13, 2017
1 parent b56f113 commit c923d5b63fee17d3ce24a707c7bdf77fe113fc23
@@ -131,9 +131,20 @@ void QgsRendererCategory::toSld( QDomDocument &doc, QDomElement &element, QgsStr
ruleElem.appendChild( descrElem );

// create the ogc:Filter for the range
QString filterFunc = QStringLiteral( "%1 = '%2'" )
.arg( attrName.replace( '\"', QLatin1String( "\"\"" ) ),
mValue.toString().replace( '\'', QLatin1String( "''" ) ) );
QString filterFunc;
if ( mValue.isNull() || mValue.toString().isEmpty() )
{
filterFunc = QStringLiteral( "%1 = '%2' or %1 is null" )
.arg( attrName.replace( '\"', QLatin1String( "\"\"" ) ),
mValue.toString().replace( '\'', QLatin1String( "''" ) ) );
}
else
{
filterFunc = QStringLiteral( "%1 = '%2'" )
.arg( attrName.replace( '\"', QLatin1String( "\"\"" ) ),
mValue.toString().replace( '\'', QLatin1String( "''" ) ) );
}

QgsSymbolLayerUtils::createFunctionElement( doc, ruleElem, filterFunc );

// add the mix/max scale denoms if we got any from the callers
@@ -1195,6 +1195,23 @@ def assertVendorOption(self, container, expectedName, allowMissing=False):
else:
self.fail('Could not find a se:VendorOption named ' + expectedName + ' in ' + container.nodeName())

def testRuleBaseEmptyFilter(self):
layer = QgsVectorLayer("Point", "addfeat", "memory")

mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.qml' % (unitTestDataPath(), "categorizedEmptyValue"))
status = layer.loadNamedStyle(mFilePath) # NOQA

dom, root = self.layerToSld(layer)
# print("Rule based, with last rule checking against empty value:" + dom.toString())

# get the third rule
rule = root.elementsByTagName('se:Rule').item(2).toElement()
filter = rule.elementsByTagName('Filter').item(0).toElement()
filter = filter.firstChild().toElement()
self.assertEqual("ogc:Or", filter.nodeName())
self.assertEqual(1, filter.elementsByTagName('ogc:PropertyIsEqualTo').size())
self.assertEqual(1, filter.elementsByTagName('ogc:PropertyIsNull').size())

def assertScaleDenominator(self, root, expectedMinScale, expectedMaxScale, index=0):
rule = root.elementsByTagName('se:Rule').item(index).toElement()

0 comments on commit c923d5b

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