You are here

Use different Symbol style in one layer (Geoserver)

I have one layer in Geoserver, the data query is one table with geometry, there is one column named 'TYPE', which has 3 different type: 'rest', 'park', 'hotel'.
I need set 3 different color for this layer depends on 'TYPE', so custom SLD style should be defined in Geoserver like this:

  1. <?xml version="1.0" encoding="ISO-8859-1" ?>
  2. <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">
  3. <NamedLayer>
  4. <Name>City</Name>
  5. <UserStyle>
  6. <Title>City Poi</Title>
  7. <FeatureTypeStyle>
  8.  
  9. <Rule>
  10. <ogc:Filter>
  11. <PropertyIsEqualTo>
  12. <PropertyName>TYPE</PropertyName>
  13. <Literal>rest</Literal>
  14. </PropertyIsEqualTo>
  15. </ogc:Filter>
  16. <PointSymbolizer>
  17. <Graphic>
  18. <Mark>
  19. <WellKnownName>circle</WellKnownName>
  20. <Fill>
  21. <CssParameter name="fill">#FFFF00</CssParameter>
  22. </Fill>
  23. </Mark>
  24. <Size>6</Size>
  25. </Graphic>
  26. </PointSymbolizer>
  27. </Rule>
  28.  
  29. <Rule>
  30. <ogc:Filter>
  31. <PropertyIsEqualTo>
  32. <PropertyName>TYPE</PropertyName>
  33. <Literal>Hotel</Literal>
  34. </PropertyIsEqualTo>
  35. </ogc:Filter>
  36. <PointSymbolizer>
  37. <Graphic>
  38. <Mark>
  39. <WellKnownName>circle</WellKnownName>
  40. <Fill>
  41. <CssParameter name="fill">#FF0000</CssParameter>
  42. </Fill>
  43. </Mark>
  44. <Size>6</Size>
  45. </Graphic>
  46. </PointSymbolizer>
  47. </Rule>
  48.  
  49. <Rule>
  50. <ogc:Filter>
  51. <PropertyIsEqualTo>
  52. <PropertyName>TYPE</PropertyName>
  53. <Literal>Park</Literal>
  54. </PropertyIsEqualTo>
  55. </ogc:Filter>
  56. <PointSymbolizer>
  57. <Graphic>
  58. <Mark>
  59. <WellKnownName>circle</WellKnownName>
  60. <Fill>
  61. <CssParameter name="fill">#0000FF</CssParameter>
  62. </Fill>
  63. </Mark>
  64. <Size>6</Size>
  65. </Graphic>
  66. </PointSymbolizer>
  67. </Rule>
  68.  
  69. </FeatureTypeStyle>
  70.  
  71. </UserStyle>
  72. </NamedLayer>
  73. </StyledLayerDescriptor>

Ref:
http://docs.geoserver.org/latest/en/user/styling/sld-reference/filters.html#examples
http://gis.stackexchange.com/questions/20966/geoserver-sld-using-propertyisequalto-and-propertyislike