Geographic Information Systems Asked by Viktor on January 29, 2021
In QGIS both in line, point and polygon type layers (for rivers, settlements, lakes..) I created labels for the objects – I created a field X and Y (Decimal Number), so that I define their location (look at picture) – manually. Basically I move every label separately from one another, and that label has it’s specific coordinates. This is 2 years work now, so the new QGIS easy-fast option for manually moving labels was not yet created.
Now the question is this:
I invested a lot time now and I can not find a solution, inside or outside GeoServer documentation – I use SLD style export for all of the layers in GeoServer, that I have no problems styling. However, I can not find a way to style the labels as such different positions, that they are visualized for every specific location with X and Y in GeoServer. So I can not get the same result that I have in QGIS – in GeoServer.
I manage to use all of the other SLD styles – so that they are offset from the point in many different ways, but every single label is offest the same way as the others.
Here are 2 SLD examples for point type that is exported from QGIS where I use this manual placement of labels. .
1 Is the basic one, pure export from QGIS. But it won’t load, because of map units. So >>2>> fixed one>>
2 Is modiffied with a line or two,so that it works – because of map units and projection.
And in the end, I show you a picture: How all 3 labels in GeoServer are on the right.
1 ORIGINAL ONE
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" version="1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:se="http://www.opengis.net/se" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ogc="http://www.opengis.net/ogc">
<NamedLayer>
<se:Name>LabelsTest</se:Name>
<UserStyle>
<se:Name>LabelsTest</se:Name>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>Cities</se:Name>
<se:Description>
<se:Title>Cities</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>code</ogc:PropertyName>
<ogc:Literal>1001</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<se:PointSymbolizer uom="http://www.opengeospatial.org/se/units/metre">
<se:Graphic>
<se:Mark>
<se:WellKnownName>circle</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#ffffff</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#000000</se:SvgParameter>
<se:SvgParameter name="stroke-width">0.5</se:SvgParameter>
</se:Stroke>
</se:Mark>
<se:Size>4999.1999999999998181</se:Size>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
<se:Rule>
<se:Name>Capital</se:Name>
<se:Description>
<se:Title>Capital</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>fclass</ogc:PropertyName>
<ogc:Literal>national_capital</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<se:PointSymbolizer uom="http://www.opengeospatial.org/se/units/metre">
<se:Graphic>
<se:Mark>
<se:WellKnownName>circle</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#ea3600</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#232323</se:SvgParameter>
<se:SvgParameter name="stroke-width">0.5</se:SvgParameter>
</se:Stroke>
</se:Mark>
<se:Size>7000</se:Size>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
<se:Rule>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>fclass</ogc:PropertyName>
<ogc:Literal>city</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<se:TextSymbolizer>
<se:Label>
<ogc:PropertyName>name_old</ogc:PropertyName>
</se:Label>
<se:Font>
<se:SvgParameter name="font-family">Oranienbaum</se:SvgParameter>
<se:SvgParameter name="font-size">10000</se:SvgParameter>
</se:Font>
<se:LabelPlacement>
<se:PointPlacement>
<se:AnchorPoint>
<se:AnchorPointX>0</se:AnchorPointX>
<se:AnchorPointY>0.5</se:AnchorPointY>
</se:AnchorPoint>
<se:Displacement>
<se:DisplacementX>3555</se:DisplacementX>
<se:DisplacementY>0</se:DisplacementY>
</se:Displacement>
</se:PointPlacement>
</se:LabelPlacement>
<se:Fill>
<se:SvgParameter name="fill">#000000</se:SvgParameter>
</se:Fill>
<se:VendorOption name="conflictResolution">false</se:VendorOption>
</se:TextSymbolizer>
</se:Rule>
<se:Rule>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>fclass</ogc:PropertyName>
<ogc:Literal>national_capital</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<se:TextSymbolizer>
<se:Label>
<ogc:Function name="strToUpperCase">
<ogc:PropertyName>name_old</ogc:PropertyName>
</ogc:Function>
</se:Label>
<se:Font>
<se:SvgParameter name="font-family">Oranienbaum</se:SvgParameter>
<se:SvgParameter name="font-size">12000</se:SvgParameter>
</se:Font>
<se:LabelPlacement>
<se:PointPlacement>
<se:AnchorPoint>
<se:AnchorPointX>0</se:AnchorPointX>
<se:AnchorPointY>0.5</se:AnchorPointY>
</se:AnchorPoint>
</se:PointPlacement>
</se:LabelPlacement>
<se:Fill>
<se:SvgParameter name="fill">#000000</se:SvgParameter>
</se:Fill>
<se:VendorOption name="underlineText">true</se:VendorOption>
<se:VendorOption name="conflictResolution">false</se:VendorOption>
</se:TextSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
2 CHANGED ONE so it loads (of map units)
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" version="1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:se="http://www.opengis.net/se" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ogc="http://www.opengis.net/ogc">
<NamedLayer>
<se:Name>LabelsTest</se:Name>
<UserStyle>
<se:Name>LabelsTest</se:Name>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>Cities</se:Name>
<se:Description>
<se:Title>Cities</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>code</ogc:PropertyName>
<ogc:Literal>1001</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<se:PointSymbolizer uom="http://www.opengeospatial.org/se/units/metre">
<se:Graphic>
<se:Mark>
<se:WellKnownName>circle</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#ffffff</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#000000</se:SvgParameter>
<se:SvgParameter name="stroke-width">0.5</se:SvgParameter>
</se:Stroke>
</se:Mark>
<se:Size>4999.1999999999998181</se:Size>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
<se:Rule>
<se:Name>Capital</se:Name>
<se:Description>
<se:Title>Capital</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>fclass</ogc:PropertyName>
<ogc:Literal>national_capital</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<se:PointSymbolizer uom="http://www.opengeospatial.org/se/units/metre">
<se:Graphic>
<se:Mark>
<se:WellKnownName>circle</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#ea3600</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#232323</se:SvgParameter>
<se:SvgParameter name="stroke-width">0.5</se:SvgParameter>
</se:Stroke>
</se:Mark>
<se:Size>7000</se:Size>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
<se:Rule>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>fclass</ogc:PropertyName>
<ogc:Literal>city</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<se:TextSymbolizer uom="http://www.opengeospatial.org/se/units/metre">
<se:Label>
<ogc:PropertyName>name_old</ogc:PropertyName>
</se:Label>
<se:Font>
<se:SvgParameter name="font-family">Oranienbaum</se:SvgParameter>
<se:SvgParameter name="font-size">10000</se:SvgParameter>
</se:Font>
<se:LabelPlacement>
<se:PointPlacement>
<se:AnchorPoint>
<se:AnchorPointX>0</se:AnchorPointX>
<se:AnchorPointY>0.5</se:AnchorPointY>
</se:AnchorPoint>
<se:Displacement>
<se:DisplacementX>3555</se:DisplacementX>
<se:DisplacementY>0</se:DisplacementY>
</se:Displacement>
</se:PointPlacement>
</se:LabelPlacement>
<se:Fill>
<se:SvgParameter name="fill">#000000</se:SvgParameter>
</se:Fill>
<se:VendorOption name="conflictResolution">false</se:VendorOption>
</se:TextSymbolizer>
</se:Rule>
<se:Rule>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>fclass</ogc:PropertyName>
<ogc:Literal>national_capital</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<se:TextSymbolizer uom="http://www.opengeospatial.org/se/units/metre">
<se:Label>
<ogc:Function name="strToUpperCase">
<ogc:PropertyName>name_old</ogc:PropertyName>
</ogc:Function>
</se:Label>
<se:Font>
<se:SvgParameter name="font-family">Oranienbaum</se:SvgParameter>
<se:SvgParameter name="font-size">12000</se:SvgParameter>
</se:Font>
<se:LabelPlacement>
<se:PointPlacement>
<se:AnchorPoint>
<se:AnchorPointX>0</se:AnchorPointX>
<se:AnchorPointY>0.5</se:AnchorPointY>
</se:AnchorPoint>
</se:PointPlacement>
</se:LabelPlacement>
<se:Fill>
<se:SvgParameter name="fill">#000000</se:SvgParameter>
</se:Fill>
<se:VendorOption name="underlineText">true</se:VendorOption>
<se:VendorOption name="conflictResolution">false</se:VendorOption>
</se:TextSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
I link a sample point lable file, styles and pictures.
[Sample point shapefile – styled. Same style is in SLD above](https://dox.abv.bg/download?id=35498f44f2# – Линк за сваляне)
You need to construct the point you would like the label to appear from your X and Y columns and then tell the TextSymbolizer
to use that geometry to place the label.
I would use something like:
<se:TextSymbolizer>
<se:Geometry>
<ogc:Function name="geomFromWKT">
<ogc:Function name="Concatenate">"Point(",ogc:PropertyName(X)," ", ogc:PropertyName(Y),")"</ogc:Function>
</ogc:Function>
</se:Geometry>
<se:Label>
<ogc:Function name="strToUpperCase">
<ogc:PropertyName>name_old</ogc:PropertyName>
</ogc:Function>
</se:Label>
A full list and description of the available functions is here.
Answered by Ian Turton on January 29, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP