2

I am passing this SLD to geoserver:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd">
<NamedLayer>
    <Name>cite:test</Name>
    <UserStyle>
      <Title>Test</Title>
        <FeatureTypeStyle>
          <Rule>
            <PointSymbolizer>
              <Graphic>
                <ExternalGraphic>
                  <OnlineResource xlink:type="simple" xlink:href="http://localhost/icons/river"/>
                    <Format>image/png</Format>
                </ExternalGraphic>
              <Size>35</Size>
            </Graphic>
          </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

That works great, but will get the my 'river' icon for ever feature. Say there is a property called icon.type in for the data source that lives behind this layer. Is there a way to use the value of that property for each features OnlineResource? In that way I would only have to define one PointSymbolizer.

IE, something like this:

<ExternalGraphic>
  <OnlineResource xlink:type="simple" xlink:href="http://localhost/icons/{icon.type}"/>
  <Format>image/png</Format>
</ExternalGraphic>

EDIT:

Turns out you can indeed use a dynamic property by using CQL in the url:

<ExternalGraphic>
  <OnlineResource xlink:type="simple" xlink:href="http://localhost/icons/${icon.type}"/>
  <Format>image/png</Format>
</ExternalGraphic>

However I am using a mongodb store and the extension does not seem to query the backend mongo store correctly for that property.

3

You got pretty close to the actual syntax (it's a GeoServer extension mind, not part of the OGC standards): http://blog.geoserver.org/2008/12/08/dynamic-symbolizers-part-1/

  • thanks! I am having a little trouble getting this working with properties that are created by the mongo store extension. I end up with a property like 'icon.type'. However when trying localhost/icons{icon.type}" I get an exception from geoserver: The requested Style can not be used with this layer. The style specifies an attribute of icon/type and the layer is: cite:test – lostintranslation Jun 29 '16 at 21:34
  • Ah, it's because the . in CQL is interpreted as a path separator and turned internally in "icon/type" Try with ${"icon.type"} instead – Andrea Aime Jun 30 '16 at 12:13
  • thanks so much for the response. I did try quoting the string however it needs to be escaped properly in the xml. Sending this: xlink:href="localhost/icons{&quot;icon.type&quot;}" with no luck. Is CQL missing this? Is there a different way to encode those inner quotes on the href attribute? – lostintranslation Jun 30 '16 at 13:54
  • After a little more research (see edit) I do not think that cql is missing this. I think that mongo is being queried incorrectly. Not sure where to go from here... – lostintranslation Jun 30 '16 at 17:13
  • You might ask on the geoserver users list and see if any developer active on the mongo community module has a clue. Mind, the module is unsupported and help is provided on a volountary basis, so don't assume you'll get an answer. If worst comes to worst the code is there, or you can look at commercial support providers. – Andrea Aime Jul 1 '16 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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