2

I rendert a beautiful with QGIS based on OSM data. Now I want to publish it via GeoServer. I am new to GeoServer but as far as I it does not accept SLD files created by QGIS.

My GeoServer cannot validate my code.

Does someone has a clue how to change the style so that GeoServer recognizes it?

The SLD content is:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:se="http://www.opengis.net/se">
<NamedLayer>
<se:Name>bahn</se:Name>
<UserStyle>
  <se:Name>bahn</se:Name>
  <se:FeatureTypeStyle>
    <se:Rule>
      <se:Name>Railway</se:Name>
      <se:Description>
        <se:Title>Railway</se:Title>
      </se:Description>
      <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
        <ogc:Not>
          <ogc:PropertyIsNull>
            <ogc:PropertyName>type</ogc:PropertyName>
          </ogc:PropertyIsNull>
        </ogc:Not>
      </ogc:Filter>
      <se:MinScaleDenominator>1</se:MinScaleDenominator>
      <se:MaxScaleDenominator>10000</se:MaxScaleDenominator>
      <se:LineSymbolizer>
        <se:Stroke>
          <se:SvgParameter name="stroke">#e4e4e4</se:SvgParameter>
          <se:SvgParameter name="stroke-width">0.26</se:SvgParameter>
          <se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
          <se:SvgParameter name="stroke-linecap">square</se:SvgParameter>
        </se:Stroke>
      </se:LineSymbolizer>
      <se:LineSymbolizer>
        <se:Stroke>
          <se:GraphicStroke>
            <se:Graphic>
              <se:Mark>
                <se:WellKnownName>line</se:WellKnownName>
                <se:Fill>
                  <se:SvgParameter name="fill">#e4e4e4</se:SvgParameter>
                </se:Fill>
                <se:Stroke>
                  <se:SvgParameter name="stroke">#e4e4e4</se:SvgParameter>
                </se:Stroke>
              </se:Mark>
              <se:Size>1</se:Size>
            </se:Graphic>
            <se:Gap>
              <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
                <ogc:Literal>5</ogc:Literal>
              </ogc:Filter>
            </se:Gap>
          </se:GraphicStroke>
        </se:Stroke>
      </se:LineSymbolizer>
    </se:Rule>
  </se:FeatureTypeStyle>
</UserStyle>

7
  • possible duplicate of Issues with datasets when custom SLD loaded into geoserver
    – user30184
    Sep 13, 2014 at 12:47
  • I've read that before and tried to do the changes. But without success. Therefore I posted this question.
    – hoge6b01
    Sep 13, 2014 at 13:34
  • I would perhaps create a style that reminds your QGIS style with uDig and compare the two SLDs.
    – user30184
    Sep 13, 2014 at 14:31
  • thanks. But that's what I want to avoid. I've got lots of layers with that problem. Anybody knows if this will be integrated in future versions of GeoServer?
    – hoge6b01
    Sep 13, 2014 at 16:45
  • 1
    could you mention what the error is?
    – Ian Turton
    Sep 13, 2014 at 19:53

2 Answers 2

3

OK - I pasted the SLD you supplied in to GeoServer - first it helpfully points out that you are missing the closing tags for

  </NamedLayer>
  </StyledLayerDescriptor>

at the end.

Once the XML is complete it complains about

line 46: cvc-complex-type.2.4.a: Invalid content was found starting with element 'ogc:Filter'. One of '{"http://www.opengis.net/ogc":expression}' is expected.
line 47: cvc-complex-type.2.4.a: Invalid content was found starting with element 'ogc:Literal'. One of '{"http://www.opengis.net/ogc":spatialOps, "http://www.opengis.net/ogc":comparisonOps, "http://www.opengis.net/ogc":logicOps, "http://www.opengis.net/ogc":_Id}' is expected.

So there is a problem at line 46 - it seems that it was expecting an expression (Literal, PropertyName etc) in the se:Gap element and you have a Filter (which is badly formed). If you delete the Filter and the /Filter elements everything validates.

However you will notice that the style is not showing up in the preview - this is because line is not a Well Known Name for a mark (see this list) so replacing it with shape://vertline fixes all your issues.

This looks like the SLD is invalid as generated so you may want to file a bug report with the QGIS folks.

1
1

Here´s what worked out for me: Basically it´s just 3 steps, using the "search and replace" tool:

1- i replaced the first line with one from an existing geoserver sld:

2- Also copy the first lines raplacing the "****" with your own

<sld:NamedLayer>
         <sld:Name>****** </sld:Name>
               <sld:UserStyle>
                    <sld:Name>*****</sld:Name>
                    <sld:Title>******</sld:Title>
                    <sld:Abstract>******</sld:Abstract>
                      <sld:FeatureTypeStyle>
                        <sld:Name>name</sld:Name>

and do the same with the closings

                       </sld:FeatureTypeStyle>
                </sld:UserStyle>
        </sld:NamedLayer>

3- Use the search and replace tool: replace <se: and </se: with <sld: and </sld: respectivly. And replace SvgParameter with CssParameter

Sorry if i don´t use correct vocabulary, i´m not so much into coding, neather into english language. Please someone improve my answer.

A co-worker made a script to do the steps before automatically with RStudio and made it even simpler for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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