|
$webwork.htmlEncode($page.space.name) : ComplexLabelingExample
This page last changed on Jul 05, 2006 by yecarrillo.
Labeling Example using InlineFeatureWe're going to build a mini-application of a world map; with labeled countries, cities, and a "Dave is Here" label. 1. A red "Dave is Here" label. I'm currently on Phu Quoc Island, in VietNam. This should always be on the map. We'll be implementing this with an inline feature with SLD-POST (see below). I've processed two datasets for this: a) Country Outlines ("countries")
b) World Cities ("gnis_pop")
The polybnda layer from VMAP0 is (c) ESRI and for non-commercial use – see the attached VMAP0_readme1.txt. The population data is (c) by Stefan Helders www.world-gazetteer.com The countries dataset looks like: Column | Type | Remark
--------------+-------------------------------
na2 | character varying| 2 letter name code (VMAP0)
gen1 | geometry | geometry - generalized (VMAP0)
country_name | text | country name (long) - from GNIS
approx_pop | integer | population from world-gazetteer
The gnis_pop dataset looks like: Column | Type | Remark
------------+----------+-----------
the_geom | geometry | geometry (point)
population | integer | approximate population
country | text | country name
type | text | "place"
name | text | ASCII version of name (ND)
Setting up the countries dataset SLDFor the countries data, we want to:
<StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <NamedLayer> <Name> world_poly </Name> <UserStyle> <FeatureTypeStyle> <FeatureTypeName>Feature</FeatureTypeName> <!-- first rule is the actual polygons. We always want them on the screen--> <Rule> <PolygonSymbolizer> <Fill> <CssParameter name="fill"> <ogc:Literal>#EBF8C4</ogc:Literal> </CssParameter> <CssParameter name="fill-opacity"> <ogc:Literal>1.0</ogc:Literal> </CssParameter> </Fill> <Stroke> <CssParameter name="fill">#A1CE18</CssParameter> </Stroke> </PolygonSymbolizer> </Rule> <!-- second rule is the country names a) we went them centered on the polygon centroid b) we want a 'halo' around them so they are easier to read c) we put a little space around them so the map isnt cluttered d) priority is based on the population of the country e) we dont display labels if we are really zoomed out or too zoomed in --> <Rule> <MaxScaleDenominator>52000000</MaxScaleDenominator> <MinScaleDenominator>800000</MinScaleDenominator> <TextSymbolizer> <Label> <ogc:PropertyName>COUNTRY_NA</ogc:PropertyName> </Label> <Font> <CssParameter name="font-family">Times New Roman</CssParameter> <CssParameter name="font-style">Normal</CssParameter> <CssParameter name="font-size">18</CssParameter> <CssParameter name="font-weight">bold</CssParameter> </Font> <!-- this centers the label on the polygon's centroid--> <LabelPlacement> <PointPlacement> <AnchorPoint> <AnchorPointX> 0.5 </AnchorPointX> <AnchorPointY> 0.5 </AnchorPointY> </AnchorPoint> </PointPlacement> </LabelPlacement> <!-- make the label easy to read--> <Halo> <Radius> <ogc:Literal>2</ogc:Literal> </Radius> <Fill> <CssParameter name="fill">#FFFFFF</CssParameter> <CssParameter name="fill-opacity">0.85</CssParameter> </Fill> </Halo> <Fill> <CssParameter name="fill">#749A00</CssParameter> </Fill> <!-- render high population countries in preference to low-population countries --> <Priority> <ogc:PropertyName>APPROX_POP</ogc:PropertyName> </Priority> <VendorOption name="group">no</VendorOption> <!-- add a little extra space around the labels so the map isnt cluttered --> <VendorOption name="spaceAround">5</VendorOption> </TextSymbolizer> </Rule> </FeatureTypeStyle> </UserStyle> </NamedLayer> </StyledLayerDescriptor>
Setting up the gnis_pop dataset SLDFor this dataset we want to have:
<?xml version="1.0" encoding="ISO-8859-1"?> <StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <!-- a named layer is the basic building block of an sld document --> <NamedLayer><Name>normal</Name> <UserStyle> <!-- again they have names, titles and abstracts --> <Title>A boring default style</Title> <Abstract>A sample style that just prints out a black line for everything</Abstract> <!-- FeatureTypeStyles describe how to render different features --> <!-- a feature type for polygons --> <FeatureTypeStyle> <FeatureTypeName>Feature</FeatureTypeName> <Rule> <MaxScaleDenominator>17000000</MaxScaleDenominator> <!-- only for cities with > 1,000,000 population--> <Filter> <PropertyIsGreaterThan> <PropertyName>POPULATION</PropertyName> <Literal>1000000</Literal> </PropertyIsGreaterThan> </Filter> <!--double large dot - red and magenta --> <PointSymbolizer> <Graphic> <Mark> <WellKnownName>circle</WellKnownName> <Fill> <CssParameter name="fill">#ff0000</CssParameter> </Fill> </Mark> <Size>15.0</Size> </Graphic> </PointSymbolizer> <PointSymbolizer> <Graphic> <Mark> <WellKnownName>circle</WellKnownName> <Fill> <CssParameter name="fill">#ff00ff</CssParameter> </Fill> </Mark> <Size>12.0</Size> </Graphic> </PointSymbolizer> <TextSymbolizer> <Label> <ogc:PropertyName>NAME</ogc:PropertyName> </Label> <Font> <CssParameter name="font-family">Times New Roman</CssParameter> <CssParameter name="font-style">Normal</CssParameter> <CssParameter name="font-size">18</CssParameter> <CssParameter name="font-weight">bold</CssParameter> </Font> <!-- move label a little to the left so that its 'beside' the dot--> <LabelPlacement> <PointPlacement> <Displacement> <DisplacementX> 8 </DisplacementX> <DisplacementY> 0 </DisplacementY> </Displacement> </PointPlacement> </LabelPlacement> <VendorOption name="group">no</VendorOption> <!-- add a little space around the label so that the map isnt too cluttered--> <VendorOption name="spaceAround">3</VendorOption> <Fill> <CssParameter name="fill">#FB3C09</CssParameter> </Fill> <!-- give priority to high-population cities--> <Priority> <PropertyName>POPULATION</PropertyName> </Priority> </TextSymbolizer> </Rule> <Rule> <MaxScaleDenominator>5000000</MaxScaleDenominator> <!-- for cities between 180,000 and 1,000,000 --> <Filter> <And> <PropertyIsLessThan> <PropertyName>POPULATION</PropertyName> <Literal>1000000</Literal> </PropertyIsLessThan> <PropertyIsGreaterThan> <PropertyName>POPULATION</PropertyName> <Literal>180000</Literal> </PropertyIsGreaterThan> </And> </Filter> <!-- single red dot --> <PointSymbolizer> <Graphic> <Mark> <WellKnownName>circle</WellKnownName> <Fill> <CssParameter name="fill">#ff0000</CssParameter> </Fill> </Mark> <Size>8.0</Size> </Graphic> </PointSymbolizer> <TextSymbolizer> <Label> <ogc:PropertyName>NAME</ogc:PropertyName> </Label> <Font> <CssParameter name="font-family">Times New Roman</CssParameter> <CssParameter name="font-style">Normal</CssParameter> <CssParameter name="font-size">10</CssParameter> </Font> <!-- move label a little to the left so that its 'beside' the dot--> <LabelPlacement> <PointPlacement> <Displacement> <DisplacementX> 5 </DisplacementX> <DisplacementY> 0 </DisplacementY> </Displacement> </PointPlacement> </LabelPlacement> <Fill> <CssParameter name="fill">#000000</CssParameter> </Fill> <VendorOption name="group">no</VendorOption> <!-- add a tiny bit of extra space around the label so the map isnt too cluttered--> <VendorOption name="spaceAround">1</VendorOption> <!-- give large population cities priority over low-population cities --> <Priority> <PropertyName>POPULATION</PropertyName> </Priority> </TextSymbolizer> </Rule> </FeatureTypeStyle> </UserStyle> </NamedLayer> </StyledLayerDescriptor>
Combining the two layersWhen these two layers are combined, the resulting map is relatively easy to read at any scale.
Adding "Dave is Here" label
We implement a "Dave is Here" label by extending the above. We will use an inline feature that describes my location: <InlineFeature> <FeatureCollection> <featureMember> <POI> <Label>Dave is Here!</Label> <pointProperty> <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"> <gml:coord><gml:X>103.91</gml:X><gml:Y>10.29</gml:Y></gml:coord> </gml:Point> </pointProperty> </POI> </featureMember> </FeatureCollection> </InlineFeature> And this simple style (very much like the above). <UserStyle> <FeatureTypeStyle> <Rule> <PointSymbolizer> <Graphic> <Mark> <WellKnownName>star</WellKnownName> <Fill> <CssParameter name="fill">#FD6435</CssParameter> </Fill> </Mark> <Size>12.0</Size> </Graphic> </PointSymbolizer> <TextSymbolizer> <Label> <ogc:PropertyName>Label</ogc:PropertyName> </Label> <Font> <CssParameter name="font-family">Times New Roman</CssParameter> <CssParameter name="font-style">Normal</CssParameter> <CssParameter name="font-size">18</CssParameter> <CssParameter name="font-weight">bold</CssParameter> </Font> <LabelPlacement> <PointPlacement> <Displacement> <DisplacementX> 8 </DisplacementX> <DisplacementY> 0 </DisplacementY> </Displacement> </PointPlacement> </LabelPlacement> <Halo> <Radius> <ogc:Literal>2</ogc:Literal> </Radius> <Fill> <CssParameter name="fill">#FFFFFF</CssParameter> <CssParameter name="fill-opacity">0.85</CssParameter> </Fill> </Halo> <Fill> <CssParameter name="fill">#FD6435</CssParameter> </Fill> <Priority> <Literal>100000000</Literal> </Priority> <VendorOption name="group">no</VendorOption> <VendorOption name="spaceAround">3</VendorOption> </TextSymbolizer> </Rule> </FeatureTypeStyle> </UserStyle> NOTE: we use a very high priority so that this label will take presidence over all other labels.
The <GetMap> request looks like, in outline: <ogc:GetMap ...> <StyledLayerDescriptor ...> <!-- draw the above two layers --> <NamedLayer> <Name>topp:countries_gen1</Name> <NamedStyle> <Name>world_poly</Name> </NamedStyle> </NamedLayer> <NamedLayer> <Name>topp:gnis_pop</Name> <NamedStyle> <Name>world_pop</Name> </NamedStyle> </NamedLayer> <!-- now the dave is here label--> <UserLayer> <Name>Inline</Name> <InlineFeature> ... as above ... </InlineFeature> <UserStyle> ... as above ... </UserStyle> </UserLayer> </StyledLayerDescriptor> <!-- normal get map parameters --> <BoundingBox> <gml:coord><gml:X>102.78575527315321</gml:X><gml:Y>8.358632381881332</gml:Y></gml:coord> <gml:coord><gml:X>109.06006786373088</gml:X><gml:Y>11.51749910135899</gml:Y></gml:coord> </BoundingBox> <Output> <Format>image/png</Format> <Transparent>false</Transparent> <Size> <Width>578</Width> <Height>291</Height> </Size> </Output> <Exceptions>application/vnd.ogc.se+xml</Exceptions> </ogc:GetMap> Find attached 3 example .XML <GetMap> requests, used to generate the above 3 images. Running this from your server
|
| Document generated by Confluence on Jan 16, 2008 23:27 |