Geoserver slice string values using SLD for label manipulation


I have an attribute column in my PostGIS polygon table and want to only show the first 2 characters of this text field on my label using SLD in Geoserver.  My goal is to place the label at the center of the polygon so here it goes in SLD xml syntax as usual very verbose and ugly.

<TextSymbolizer>
            <Geometry>
              <ogc:Function name="centroid">
                <ogc:PropertyName>geom</ogc:PropertyName>
              </ogc:Function>
            </Geometry>

          <Label>
              <ogc:Function name="strSubstring">
                  <ogc:PropertyName>short_name</ogc:PropertyName>
                  <ogc:Function name="parseInt">
                    <ogc:Literal>0</ogc:Literal>
                  </ogc:Function>
                  <ogc:Function name="parseInt">                            
                      <ogc:Literal>2</ogc:Literal>
                  </ogc:Function>
              </ogc:Function>
          </Label>
                   
</TextSymbolizer>

My table column name is "short_name"  and the geometry column name is "geom".  This works and creates my label in the center of the polygon only drawing the first 2 characters from the field "short_name".

I hope this helps :)
cheers
Michael

Comments

Popular Posts