Thursday, 2 November 2017

geowebcache - Polygon label repeated for each tile


I'm using the standalone GeoWebCache to serve tiles from a remote GeoServer. My problem is that the polygon label is added to each one of the tiles served, instead of only once in the polygon centroid.


I found a post which discusses the issue:
http://osgeo-org.1560.n6.nabble.com/polygon-label-repeated-for-each-tile-td4995203.html


The first reply mentioned a possible solution:




"All in all, I suggest to use a tile rendering engine (GeoWebCache, MapProxy, TileCache) anyway, instead of requesting small image from GeoServer and have the tile rendering engine do the tile slicing afterwards. You will have send fewer requests to GeoServer (1 large image instead of multiple small images), so this speeds up the overall tile cache creation time."



Problem is that I couldn't find how to do that by referring to the GeoWebCache documentation, and the above mentioned post doesn't explain the way to implement that.


I also found a post with an answer that links to the GeoWebCache "Tiled" documentation, but my code allready uses all the necessary attributes and still the label shows up multiple times:


var Layer_1874 = new OpenLayers.Layer.WMS(
'Grundkort',
'/wms10.ashx'
, {
format: 'image/png',
srs: 'EPSG:25832',

layers: 'ballerupkommune_grundkort_bk',
tiled: true,
tilesOrigin: '698804,6173460'
}
, {
displayInLayerSwitcher: true,
isBaseLayer: true,
transitionEffect: 'resize',
displayOutsideMaxExtent: true,
visibility: false

}
);

Anyone has an idea?



Answer



Below is an example of an SLD rule that places a label at the center of a feature's geometry. This uses the ogc:Function called "centroid" to place the label. You can read more about SLD functions in the GeoServer docs, and some examples are given here.



5000




the_geom



LOT_NAME


Arial
11

normal
bold





0.0



0.5



0






1.0


#FFFFFF


true
0
60




Also, the SLD Cookbook is a great reference. One thing that can trip you up is the ordering of tags in the SLD. For the TextSymbolizer rule above you can see required order by looking in the schema definition. Don't worry, it's not too scary! Just search for "textsymbolizer" in that .xsd file, an you should easily find the "sequence" tag. There you'll find that the element references match up with the order in my example. (Note: I didn't use the text symbolizer's "fill" attribute, my fill just applies to the halo.)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...