0

How to define the style of objects in a collection for one record via SLD. For example, lines are separate, polygons are separate.

For instance

<Rule>
   <ogc:PropertyIsEqualTo>
      <ogc:Function name="geometryType">
         <ogc:PropertyName>geom</ogc:PropertyName>
      </ogc:Function>
      <ogc:Literal>GeometryCollection</ogc:Literal>
   </ogc:PropertyIsEqualTo>
   <PolygonSymbolizer> -- ONLY POLIGON
     ...
   </PolygonSymbolizer>
   <LineSymbolizer>    -- ONLY LINES
     ...
   </LineSymbolizer>
</Rule>

So far, it turns out that the first style is used for all sub-objects of the recording, and the lines are displayed as polygons. https://i.stack.imgur.com/RoHBZ.png

1 Answers1

0

A Rule will apply all of its Symbolizers to all features that match its filter, so this SLD is behaving exactly as expected.

You need to have multiple rules with different filters:

<Rule>
   <ogc:PropertyIsEqualTo>
      <ogc:Function name="geometryType">
         <ogc:PropertyName>geom</ogc:PropertyName>
      </ogc:Function>
      <ogc:Literal>Polygon</ogc:Literal>
   </ogc:PropertyIsEqualTo>
   <PolygonSymbolizer> -- ONLY POLIGON
     ...
   </PolygonSymbolizer>
 </Rule>
 <Rule>
   <ogc:PropertyIsEqualTo>
      <ogc:Function name="geometryType">
         <ogc:PropertyName>geom</ogc:PropertyName>
      </ogc:Function>
      <ogc:Literal>LineString</ogc:Literal>
   </ogc:PropertyIsEqualTo>
   <LineSymbolizer>    -- ONLY LINES
     ...
   </LineSymbolizer>
</Rule> 

There are more details in the GeoServer manual, however, none of these techniques will work with a GeometryCollection so you will probably need to rework your data flow to avoid ending up with these.

Ian Turton
  • 10,018
  • 1
  • 28
  • 47
  • With regard to individual types, everything is very clear. The conversation is about collections. Apparently you need to study the source code. – user2110017 Mar 15 '21 at 03:51
  • I think I wrote the source code :-) The question is more why are you working with collections? – Ian Turton Mar 15 '21 at 08:18
  • A large number of objects have this structure. These are various designs that are grouped together. There is, of course, an option to divide the object into parts, but why not implement the function of a separate coloring of objects? In addition, a filter on the collection already exists. – user2110017 Mar 16 '21 at 04:59