Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've trying to use OpenLayers to construct an SLD element to include in a WMS layer's parameters.

This SLD document can contain a number of filters. This works fine and resultant SLD does work to filter the layer.

However, the matchCase=false property of the filter(s) are being stripped out on formatting the SLD.

Example:

var filter    = new OpenLayers.Filter.Comparison(
{
  type:       OpenLayers.Filter.Comparison.EQUAL_TO,
  property:   'my_property',
  value:      'A Value',
  matchCase:  false
});

var rule = new OpenLayers.Rule({
  filter: filter,
  symbolizer: {"Polygon": {}}
});

var style = new OpenLayers.Style();

style.addRules([rule]);

// Create the SLD
var sld_body = new OpenLayers.Format.SLD().write({
  namedLayers: [
    {
      name: 'myLayer',
      userStyles: [style]
    }
  ]
});

I think I know what the problem is, but I have no idea how to fix it.

If I check the output of OpenLayers.Format.Filter({version: "1.1.0"}).write( filter ); then I see correctly formatted XML, which includes my matchedCase property.

If I do the same with version 1.0 (the default), I see the same XML but without the matchedCase parameter.

The documentation for OpenLayers.Format.SLD states that it inherits from OpenLayers.Format.Filter.v1_0_0, which explains why it won't read the matchedCase parameter.

I'd hoped using OpenLayers.Format.SLD({version: "1.1.0}).write() would work, but it just throws an error about a driver not being available for that version.

So, how should I deal with this? I need to generate an SLD document and it needs to acknowledge the matchedCase property.

Thanks,

Tom

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Officially, OpenLayers only supports SLD version 1.0.0 for now (patch welcome). I'm not sure this version of the SLD standard officially supports Filters version 1.1.0. That's the official standard point of view.

In the real world however, your WMS service probably do support it. So to force OpenLayers SLD version 1.0.0 to use Filters version 1.1.0, you can overwrite them like this:

var filter    = new OpenLayers.Filter.Comparison(
{
  type:       OpenLayers.Filter.Comparison.EQUAL_TO,
  property:   'my_property',
  value:      'A Value',
  matchCase:  false
});

var rule = new OpenLayers.Rule({
  filter: filter,
  symbolizer: {"Polygon": {}}
});

var style = new OpenLayers.Style();

style.addRules([rule]);

// Create the SLD
OpenLayers.Format.SLD.v1.prototype.readers = OpenLayers.Util.applyDefaults(
    OpenLayers.Format.Filter.v1_1_0.prototype.readers, 
    OpenLayers.Format.SLD.v1.prototype.readers);
OpenLayers.Format.SLD.v1.prototype.writers = OpenLayers.Util.applyDefaults(
    OpenLayers.Format.Filter.v1_1_0.prototype.writers, 
    OpenLayers.Format.SLD.v1.prototype.writers);
OpenLayers.Format.SLD.v1.prototype.writeSpatial = OpenLayers.Util.applyDefaults(
    OpenLayers.Format.Filter.v1_1_0.prototype.writeSpatial, 
    OpenLayers.Format.SLD.v1.prototype.writeSpatial);
var sld_body = new OpenLayers.Format.SLD().write({
  namedLayers: [
    {
      name: 'myLayer',
      userStyles: [style]
    }
  ]
});

The code highlighted below replace all the Filter1.0.0 writing functions by Filter1.1.0 in the SLD class.

OpenLayers.Format.SLD.v1.prototype.writers = OpenLayers.Util.applyDefaults(
    OpenLayers.Format.Filter.v1_1_0.prototype.writers, 
    OpenLayers.Format.SLD.v1.prototype.writers);
share|improve this answer
    
Worked a treat. I'd upvote but not enough rep... Thanks :) –  user2889370 Oct 30 '13 at 17:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.