sld label displacement

506 views
Skip to first unread message

Hailey Eckstrand

unread,
Mar 1, 2012, 4:07:34 PM3/1/12
to Mapnik to GeoTools Style Conversion
Hello David,
I've noticed that in some of the labeling SLD (example, city-1.sld,
line 35 - 57), the PointPlacement options 'Displacement' and
'AnchorPoint' are being used and it moves the text label correctly,
however it also moves the city symbol graphic to be in the center of
the text .... essentially moving the actual city symbol to an
incorrect location.
I think it is because in the Rule, the point placement of the
TextSymbolizer is also used for the actual graphic of the city symbol.
However, I know that the labeling also relies on the
VendorOption:SpaceAround. I'm not sure how to keep the city symbol in
the correct location as well as move the label placement not directly
over the city (x=0.5, y=0.5) & use the SpaceAround option so their
aren't overlapping labels & city symbols. The specific Rule am
referring to is in city-1.sld, line 10 - 149 (copied into discussion
below).

Is there a solution or should I just alter all the displacement to be
0 & the anchors to be 0.5?
Thanks,
Hailey

<sld:Rule>
<ogc:Filter>
<ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>place</ogc:PropertyName>
<ogc:Literal>city</ogc:Literal>
</ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>place</ogc:PropertyName>
<ogc:Literal>metropolis</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
</ogc:Filter>
<sld:MinScaleDenominator>3000000.0</sld:MinScaleDenominator>
<sld:MaxScaleDenominator>1.25E7</sld:MaxScaleDenominator>
<sld:TextSymbolizer>
<sld:Label>
<ogc:PropertyName>name</ogc:PropertyName>
</sld:Label>
<sld:Font>
<sld:CssParameter name="font-family">unifont Medium</
sld:CssParameter>
<sld:CssParameter name="font-size">11</sld:CssParameter>
<sld:CssParameter name="font-style">normal</
sld:CssParameter>
<sld:CssParameter name="font-weight">bold</
sld:CssParameter>
</sld:Font>
<sld:LabelPlacement>
<sld:PointPlacement>
<sld:AnchorPoint>
<sld:AnchorPointX>
<ogc:Literal>0.5</ogc:Literal>
</sld:AnchorPointX>
<sld:AnchorPointY>
<ogc:Literal>0.5</ogc:Literal>
</sld:AnchorPointY>
</sld:AnchorPoint>
<sld:Displacement>
<sld:DisplacementX>
<ogc:Literal>0</ogc:Literal>
</sld:DisplacementX>
<sld:DisplacementY>
<ogc:Literal>-12</ogc:Literal>
</sld:DisplacementY>
</sld:Displacement>
<sld:Rotation>
<ogc:Literal>0</ogc:Literal>
</sld:Rotation>
</sld:PointPlacement>
</sld:LabelPlacement>
<sld:Halo>
<sld:Radius>
<ogc:Literal>2</ogc:Literal>
</sld:Radius>
<sld:Fill>
<sld:CssParameter name="fill">#ffffff</
sld:CssParameter>
<sld:CssParameter name="fill-opacity">0.25</
sld:CssParameter>
</sld:Fill>
</sld:Halo>
<sld:Fill>
<sld:CssParameter name="fill">#2b2b2b</sld:CssParameter>
</sld:Fill>
<sld:Graphic>
<sld:ExternalGraphic>
<sld:OnlineResource xmlns:xlink="http://www.w3.org/
1999/xlink" xlink:type="simple" xlink:href="file:/var/lib/tomcat6/
webapps/geoserver/geoserver_data/styles/small-city.svg"/>
<sld:Format>image/svg+xml</sld:Format>
</sld:ExternalGraphic>
</sld:Graphic>
<sld:VendorOption name="autoWrap">0</sld:VendorOption>
<sld:VendorOption name="spaceAround">5</sld:VendorOption>
</sld:TextSymbolizer>
</sld:Rule>
<sld:Rule>
<ogc:Filter>
<ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>place</ogc:PropertyName>
<ogc:Literal>city</ogc:Literal>
</ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>place</ogc:PropertyName>
<ogc:Literal>metropolis</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
</ogc:Filter>
<sld:MinScaleDenominator>750000.0</sld:MinScaleDenominator>
<sld:MaxScaleDenominator>3000000.0</sld:MaxScaleDenominator>
<sld:TextSymbolizer>
<sld:Label>
<ogc:PropertyName>name</ogc:PropertyName>
</sld:Label>
<sld:Font>
<sld:CssParameter name="font-family">unifont Medium</
sld:CssParameter>
<sld:CssParameter name="font-size">13</sld:CssParameter>
<sld:CssParameter name="font-style">normal</
sld:CssParameter>
<sld:CssParameter name="font-weight">bold</
sld:CssParameter>
</sld:Font>
<sld:LabelPlacement>
<sld:PointPlacement>
<sld:AnchorPoint>
<sld:AnchorPointX>
<ogc:Literal>0.5</ogc:Literal>
</sld:AnchorPointX>
<sld:AnchorPointY>
<ogc:Literal>0.5</ogc:Literal>
</sld:AnchorPointY>
</sld:AnchorPoint>
<sld:Displacement>
<sld:DisplacementX>
<ogc:Literal>0</ogc:Literal>
</sld:DisplacementX>
<sld:DisplacementY>
<ogc:Literal>-13</ogc:Literal>
</sld:DisplacementY>
</sld:Displacement>
<sld:Rotation>
<ogc:Literal>0</ogc:Literal>
</sld:Rotation>
</sld:PointPlacement>
</sld:LabelPlacement>
<sld:Halo>
<sld:Radius>
<ogc:Literal>2</ogc:Literal>
</sld:Radius>
<sld:Fill>
<sld:CssParameter name="fill">#ffffff</
sld:CssParameter>
<sld:CssParameter name="fill-opacity">0.25</
sld:CssParameter>
</sld:Fill>
</sld:Halo>
<sld:Fill>
<sld:CssParameter name="fill">#2b2b2b</sld:CssParameter>
</sld:Fill>
<sld:Graphic>
<sld:ExternalGraphic>
<sld:OnlineResource xmlns:xlink="http://www.w3.org/
1999/xlink" xlink:type="simple" xlink:href="file:/var/lib/tomcat6/
webapps/geoserver/geoserver_data/styles/large-city.svg"/>
<sld:Format>image/svg+xml</sld:Format>
</sld:ExternalGraphic>
</sld:Graphic>
<sld:VendorOption name="autoWrap">0</sld:VendorOption>
<sld:VendorOption name="spaceAround">5</sld:VendorOption>
</sld:TextSymbolizer>
</sld:Rule>

David Winslow

unread,
Mar 1, 2012, 4:18:10 PM3/1/12
to Hailey Eckstrand, Mapnik to GeoTools Style Conversion
In GeoTools/GeoServer SLD, including an icon inside a TextSymbolizer marks it for use as a "shield" graphic, displayed behind the label like (for example) a highway shield.  If you make a separate PointSymbolizer with the icon instead, it should be rendered on top of the feature as normal. For example:

          <sld:VendorOption name="autoWrap">0</sld:VendorOption>
           <sld:VendorOption name="spaceAround">5</sld:VendorOption>
         </sld:TextSymbolizer>
         <sld:PointSymbolizer>
           <sld:Graphic>
             <sld:ExternalGraphic>
               <sld:OnlineResource xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:type="simple" xlink:href="file:/var/lib/tomcat6/
webapps/geoserver/geoserver_data/styles/small-city.svg"/>
               <sld:Format>image/svg+xml</sld:Format>
             </sld:ExternalGraphic>
           </sld:Graphic>
         </sld:PointSymbolizer>
       </sld:Rule>

Note that if you do that you might end up with a lot more graphics on the map - shield graphics are hidden when GeoServer's label collision detection determines that they would overlap, but PointSymbolizer marks don't have any such collision prevention.

--
David Winslow
Reply all
Reply to author
Forward
0 new messages