1

I have a shapefile that includes a color HEX value in the hex_col column in the attribute table.

index count bin hex_col
86bc1b29fffffff 1 Bin 1 #fee5d9
86bc51407ffffff 2 Bin 1 #fee5d9
86bcc2427ffffff 37 Bin 3 #fb6a4a
86bcc242fffffff 1 Bin 1 #fee5d9
86bcc2437ffffff 36 Bin 3 #fb6a4a
86bcc244fffffff 82 Bin 5 #a50f15
86bcc245fffffff 26 Bin 2 #fcae91
86bcc2467ffffff 23 Bin 2 #fcae91

Is it possible to dynamically style the layer using the value from the "hex_col" column to fill the individual polygons?

1 Answer 1

0

I have a shapefile with the text column hexcolor:

enter image description here

Use PropertyName to extract the value from the column:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/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">

  <NamedLayer>
    <Name>polyhex</Name>
    <UserStyle>
      <Title>A polygon style</Title>
      <FeatureTypeStyle>
        <Rule>
          <Title>Color by attribute</Title>
          <PolygonSymbolizer>
            <Fill>
              <CssParameter name="fill">
                <ogc:PropertyName>hexcolor</ogc:PropertyName>
              </CssParameter>              
            </Fill>
            <Stroke>
              <CssParameter name="stroke">#000000</CssParameter>
              <CssParameter name="stroke-width">0.5</CssParameter>
            </Stroke>
          </PolygonSymbolizer>

        </Rule>

      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

enter image description here

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.