6

I have a PostGIS table with geometry column. In this column I have geometries of several types (polygons, points, lines). I publish this this table on GeoServer.

Now I want to create OpenLayers layer with this data. But how to make a style for this data?

I've already read http://docs.geoserver.org/stable/en/user/styling/sld-tipstricks/mixed-geometries.html and don't want to create gtype in PostGIS if this possible.

I try to create new style within GeoServer but I think that do something wrong:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
 xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
 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">
<!-- a Named Layer is the basic building block of an SLD document -->
    <Rule>
     <ogc:PropertyIsEqualTo>
      <ogc:Function name="geometryType">
       <ogc:PropertyName>the_geom</ogc:PropertyName>
      </ogc:Function>
      <ogc:Literal>Polygon</ogc:Literal>
     </ogc:PropertyIsEqualTo>
     <PolygonSymbolizer>
       <Stroke>
          <CssParameter name="stroke">#0000ff</CssParameter>
          <CssParameter name="stroke-width">1</CssParameter>
        </Stroke>
     </PolygonSymbolizer>
    </Rule>
</StyledLayerDescriptor>

And get a error:

line 10: cvc-complex-type.2.4.a: Invalid content was found starting with element 'Rule'. One of '{"http://www.opengis.net/sld":Name, "http://www.opengis.net/sld":Title, "http://www.opengis.net/sld":Abstract, "http://www.opengis.net/sld":NamedLayer, "http://www.opengis.net/sld":UserLayer}' is expected.
line 11: cvc-complex-type.2.4.a: Invalid content was found starting with element 'ogc:PropertyIsEqualTo'. One of '{"http://www.opengis.net/sld":Name, "http://www.opengis.net/sld":Title, "http://www.opengis.net/sld":Abstract, "http://www.opengis.net/sld":LegendGraphic, "http://www.opengis.net/ogc":Filter, "http://www.opengis.net/sld":ElseFilter, "http://www.opengis.net/sld":MinScaleDenominator, "http://www.opengis.net/sld":MaxScaleDenominator, "http://www.opengis.net/sld":Symbolizer}' is expected.

What am I doing wrong?

UPDATE

I try to show a points and make this rule for this geom type:

 <Rule>
        <ogc:Filter>        
            <ogc:PropertyIsEqualTo>
                <ogc:Function name="geometryType">
                    <ogc:PropertyName>the_geom</ogc:PropertyName>
                </ogc:Function>
                <ogc:Literal>Point</ogc:Literal>
            </ogc:PropertyIsEqualTo>
        </ogc:Filter>    
        <PolygonSymbolizer>
        <Stroke>
            <CssParameter name="stroke">#0000ff</CssParameter>
            <CssParameter name="stroke-width">2</CssParameter>
        </Stroke>
        </PolygonSymbolizer>
    </Rule>

But not see then on my map. What's wrong?

  • Sorry last UPDATE is my fail. I tryd to use </PolygonSymbolizer> for Points. – Kliver Max Oct 9 '12 at 12:28
4

The first validation error is because you are missing Name, Title, Abstract, NamedLayer and UserLayer elements in your SLD. The second validation error refers to the missing filter element inside your Rule element. So if you add the filter element and the standard elements in the sld elemet your SLD should validate fine. Finally our SLD should look like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0" 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"
  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  <NamedLayer>
    <Name></Name>
    <UserStyle>
      <Title></Title>
      <Abstract></Abstract>
      <FeatureTypeStyle>
        <Rule>
            <ogc:Filter>        
                <ogc:PropertyIsEqualTo>
                    <ogc:Function name="geometryType">
                        <ogc:PropertyName>the_geom</ogc:PropertyName>
                    </ogc:Function>
                    <ogc:Literal>Polygon</ogc:Literal>
                </ogc:PropertyIsEqualTo>
            </ogc:Filter>    
            <PolygonSymbolizer>
            <Stroke>
                <CssParameter name="stroke">#0000ff</CssParameter>
                <CssParameter name="stroke-width">1</CssParameter>
            </Stroke>
            </PolygonSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

If you want to style other geometrytypes - just create a new rule with the symbolizer and geometrytype filter you want to style.

UPDATE

Your point rule should have a PointSymbolizer element instead of the PolygonSymbolizer. So your point rule look like this:

 <Rule>
        <ogc:Filter>        
            <ogc:PropertyIsEqualTo>
                <ogc:Function name="geometryType">
                    <ogc:PropertyName>the_geom</ogc:PropertyName>
                </ogc:Function>
                <ogc:Literal>Point</ogc:Literal>
            </ogc:PropertyIsEqualTo>
        </ogc:Filter>    
        <PointSymbolizer>
        <Graphic>
              <Mark>
                <WellKnownName>circle</WellKnownName>
                <Stroke>
                  <CssParameter name="stroke">#0000ff</CssParameter>
                  <CssParameter name="stroke-width">2</CssParameter>
                </Stroke>
              </Mark>
              <Size>6</Size>
            </Graphic>
        </PointSymbolizer>
    </Rule>

See more on how to style points in the GeoServer SLD Cookbook

  • Its really works thanks you!!! But can you tell me one thing. My Geoserver 2.2 work very slow, if i will use Geoserver 2.1 this style will work? – Kliver Max Oct 9 '12 at 11:52
  • I am pretty sure that the geometryType function works fine in GeoServer 2.1 and I even think it will work in 2.0 as well. – taudorf Oct 9 '12 at 12:17
  • And another problem with style for points type. Please look at UPDATE in question. – Kliver Max Oct 9 '12 at 12:18
  • Sorry last comment is my fail. I tryd to use </PolygonSymbolizer> for Points. – Kliver Max Oct 9 '12 at 12:27
  • No worries - I updated my answer as well. But you are right with the PolygonSymbolizer:-) – taudorf Oct 9 '12 at 12:35

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.