Pergunta

I am working with Shape files to draw a map on Geoserver. I am able to change the color of a track or line using SLD. can any body tell me how i can divide a line into different colors. if possible then with respect to length. e.g every 1km a different color. Thank you!

Foi útil?

Solução

To get a line composed of different colours is easy enough. Something like

<FeatureTypeStyle>
     <Rule>
       <LineSymbolizer>
         <Stroke>
           <CssParameter name="stroke">#0000FF</CssParameter>
           <CssParameter name="stroke-width">3</CssParameter>
           <CssParameter name="stroke-dasharray">5 5</CssParameter>
         </Stroke>
       </LineSymbolizer>
       <LineSymbolizer>
         <Stroke>
           <CssParameter name="stroke">#FF0000</CssParameter>
           <CssParameter name="stroke-width">3</CssParameter>
           <CssParameter name="stroke-dasharray">5 5</CssParameter>
           <CssParameter name="stroke-dashoffset">5</CssParameter>
         </Stroke>
       </LineSymbolizer>
     </Rule>
   </FeatureTypeStyle>

Now getting this to happen every 1Km rather than by pixels might be a bit harder. I haven't tested this but I image you can do it with something like the following:

<FeatureTypeStyle>
     <Rule>
       <LineSymbolizer uom="http://www.opengeospatial.org/se/units/metre" >
         <Stroke>
           <CssParameter name="stroke">#0000FF</CssParameter>
           <CssParameter name="stroke-width">0.5</CssParameter>
           <CssParameter name="stroke-dasharray">1000 1000</CssParameter>
         </Stroke>
       </LineSymbolizer>
       <LineSymbolizer uom="http://www.opengeospatial.org/se/units/metre" >
         <Stroke>
           <CssParameter name="stroke">#FF0000</CssParameter>
           <CssParameter name="stroke-width">0.5</CssParameter>
           <CssParameter name="stroke-dasharray">1000 1000</CssParameter>
           <CssParameter name="stroke-dashoffset">1000</CssParameter>
         </Stroke>
       </LineSymbolizer>
     </Rule>
   </FeatureTypeStyle>

You may need to play arround with the widths ect to get this looking ok.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top