2

I am trying to create an SLD to style a polygon; the goal is a simple block fill along with a single point image added to the most northern edge of the polygon. Something like this:

Example polygon styling

This example SLD code will add a symbol to the start point of a polygon:

<PolygonSymbolizer>
<Fill>
    <CssParameter name="fill">#000000</CssParameter>
</Fill>
</PolygonSymbolizer>
<PointSymbolizer>
    <Geometry>
        <ogc:Function name="startPoint">
            <ogc:PropertyName>the_geom</ogc:PropertyName>
        </ogc:Function>
     </Geometry>   
    <Graphic>
        <Mark>
            <WellKnownName>square</WellKnownName>
        <Fill>
            <CssParameter name="fill">#00FFFF</CssParameter>
        </Fill>                    
        </Mark>
        <Size>5</Size>
    </Graphic>
</PointSymbolizer>  

However I can't work out how to show the point symbol to the most northern edge of the polygon?

One more thing I tried: Using QGIS I can create styles and export to SLD, and using the geometry generator as follows: closest_point( $geometry, make_point( x($geometry), y( $geometry)+20000)) This works. However when exporting this to SLD it fails due to 'not implemented yet'.

1

This is similar (but slightly harder) than a previous question - find the centre of the polygon is easy, and extracting X is OK:

 <Geometry>
  <ogc:Function name="geomFromWKT">
   <ogc:Function name="Concatenate">
    <ogc:Literal>POINT(</ogc:Literal>
    <ogc:Function name="getX"> 
      <ogc:Function name="centroid">
         <ogc:PropertyName>the_geom</ogc:PropertyName>
      </ogc:Function>
    </ogc:Function>
    <Literal><![CDATA[ ]]></Literal>
     <!-- Extract 1/2 height here -->
      <ogc:Function name="envelope">
         <ogc:PropertyName>the_geom</ogc:PropertyName>
      </ogc:Function>
    </ogc:Function>
     <Literal>)</Literal>

    </ogc:Function>
      </ogc:Function>

 </Geometry>   

I can't see a way to extract half the height of the polygon here (and that assumes that all your polygons are rectangular). I think at this point the best plan is to write a custom geotools function to generate the point you require from a polygon.

0

Thank you very much for your assistance, and for pointing me in the right direction! With the use of the geoserver function reference (here) I think I have cracked it. But it will only be valid for the case of rectangular polygons. It's not pretty, but it does work:

<PolygonSymbolizer>
    <Fill>
        <CssParameter name="fill">#000000</CssParameter>
    </Fill>
</PolygonSymbolizer>
<PointSymbolizer>
    <Geometry>
        <ogc:Function name="offset">
            <ogc:Function name="centroid">
                <ogc:PropertyName>the_geom</ogc:PropertyName>
            </ogc:Function>
            <ogc:Literal>0.0</ogc:Literal>
            <ogc:Sub>
                <!-- distance between far north point and centroid -->
                <ogc:Function name="distance">
                    <ogc:Function name="offset">
                        <ogc:Function name="centroid">
                            <ogc:PropertyName>the_geom</ogc:PropertyName>
                        </ogc:Function>
                        <ogc:Literal>0.0</ogc:Literal>                                            
                        <ogc:Literal>99999.0</ogc:Literal>                                            
                    </ogc:Function>
                    <ogc:Function name="centroid">
                        <ogc:PropertyName>the_geom</ogc:PropertyName>
                    </ogc:Function>  
                </ogc:Function>
                <!-- distance between far north point and polygon -->
                <ogc:Function name="distance">
                    <ogc:Function name="offset">
                        <ogc:Function name="centroid">
                            <ogc:PropertyName>the_geom</ogc:PropertyName>
                        </ogc:Function>
                        <ogc:Literal>0.0</ogc:Literal>                                            
                        <ogc:Literal>99999.0</ogc:Literal>                                            
                    </ogc:Function>                                                
                    <ogc:PropertyName>the_geom</ogc:PropertyName>
                </ogc:Function>
            </ogc:Sub>
        </ogc:Function>                                        
    </Geometry>   
    <Graphic>
        <Mark>
            <WellKnownName>square</WellKnownName>
            <Fill>
                <CssParameter name="fill">#00FFFF</CssParameter>
            </Fill>                    
        </Mark>
        <Size>5</Size>
    </Graphic>
</PointSymbolizer>  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.