pras k
pras k

Reputation: 27

how to change the color of an svg image in xml file(in geoserver)?is it possible to change in geoserver?

this is my code.i want to change color of svg image here itself. even though I change the color code it is not working.i am getting the black and white color. what is the error in my code?

<se:PointSymbolizer>
<se:Graphic>
<!--Parametric SVG-->
<se:ExternalGraphic>
<se:OnlineResource xlink:href="ForServer/DRY.svg?fill=%23e01987&amp;fill-opacity=1&amp;outline=%23e01987&amp;outline-opacity=1&amp;outline-width=0" xlink:type="simple"/>
<se:Format>image/svg+xml</se:Format>
</se:ExternalGraphic>
<!--Plain SVG fallback, no parameters-->
<se:ExternalGraphic>
<se:OnlineResource xlink:href="ForServer/DRY.svg" xlink:type="simple"/>
<se:Format>image/svg+xml</se:Format>
</se:ExternalGraphic>
<!--Well known marker fallback-->
<se:Mark>
<se:WellKnownName>square</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#e01987</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#e01987</se:SvgParameter>
<se:SvgParameter name="stroke-width">0.5</se:SvgParameter>
</se:Stroke>
</se:Mark>
<se:Size>11</se:Size>
</se:Graphic>
</se:PointSymbolizer>

Upvotes: 1

Views: 1637

Answers (4)

StackUnder
StackUnder

Reputation: 252

It's possible using composition. I made a svg picture with only black colors to use as an alpha mask. Then I made a square Mark bigger than the picture just to apply the color.

<?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" xmlns:gml="http://www.opengis.net/gml" 
                       xsi:schemaLocation="http://www.opengis.net/sld">
  <NamedLayer>
    <UserStyle>
      <FeatureTypeStyle>
        <Rule>
          <PointSymbolizer>
            <Graphic>
              <ExternalGraphic>
                <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="YOUR_SVG_FILE.svg"/>
                <Format>image/svg+xml</Format>
              </ExternalGraphic>
              <Size>45</Size>
            </Graphic>
            <VendorOption name="composite-base">true</VendorOption>
          </PointSymbolizer>
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <Fill>
                  <CssParameter name="fill">#1e9e1e</CssParameter>
                  <CssParameter name="fill-opacity">1</CssParameter>
                </Fill>
              </Mark>
              <Size>50</Size>
            </Graphic>
            <VendorOption name="composite">source-in</VendorOption>
          </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

See also https://docs.geoserver.org/stable/en/user/styling/sld/extensions/composite-blend/syntax.html

Upvotes: 1

pras k
pras k

Reputation: 27

Instead of giving an image as .svg, I have converted SVG to png and gave .png image, It perfectly works!!!

Upvotes: -1

Ian Turton
Ian Turton

Reputation: 10976

GeoServer doesn't (AFAIK) support the colouring of SVG symbols via the SLD file, it will always be the colours that are set in the SVG.

Upvotes: 0

Zucoop
Zucoop

Reputation: 11

You could try 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"
  xmlns:gml="http://www.opengis.net/gml"
  xsi:schemaLocation="http://www.opengis.net/sld
    http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd
">
  <NamedLayer>
    <Name>redflag</Name>
        <UserStyle>
        <Name>burg</Name>
        <Title>A small red flag</Title>
        <Abstract>A sample of how to use an SVG based symbolizer
        </Abstract>
      <FeatureTypeStyle>
       <Rule>
          <PointSymbolizer>
              <Graphic>
                <ExternalGraphic>
                    <OnlineResource xlink:type="simple" xlink:href="burg02.svg" />
                    <Format>image/svg+xml</Format>
                </ExternalGraphic>
                <Size>
                 <ogc:Literal>30</ogc:Literal>
                </Size>
            </Graphic>
         </PointSymbolizer>
        <PolygonSymbolizer>
          <Fill>
            <CssParameter name="fill">#1eff00</CssParameter> <CssParameter name="fill-opacity">0.6</CssParameter>
          </Fill>
          <Stroke>
            <CssParameter name="stroke">#000000</CssParameter> <CssParameter name="stroke-width">0.5</CssParameter>
          </Stroke>
        </PolygonSymbolizer>
      </Rule>
     </FeatureTypeStyle>
    </UserStyle>
    </NamedLayer>
</StyledLayerDescriptor>

And let me know if you face any issues

Upvotes: 1

Related Questions