I've done quite a few changes to the labeler in lite renderer. See
examples of TIGER at the bottom of this email.
1.The old version of the labeler, if given a *set* of points, lines,
or polygons justed labels the first item in the set. The sets are
formed when you want to only put a single "Main St" on the map even if
you have a bunch of small "Main St" segments.
I changed this to be much much wiser.
Basically, the new way looks at the set of geometries that its going
to put a label on and find the "best" one that represents it. That
geometry is then labeled (see below for details on where that label is
placed).
Here's the javadocs, but please note the details are actually quite
complex. They all try to handle robustness issue, sets of basic and
MULTI* geometries as well as mixed geometries, and do geometry
clipping.
I spent a lot of time getting the line merger to work "smart" to build a
nice representative line from the set of input lines.
/**
*
* 1. get a list of points from the input geometries that are inside
the displayGeom
* NOTE: lines and polygons are reduced to their centroids (you
shouldnt really calling this with lines and polys)
* 2. choose the most "central" of the points
* METRIC - choose anyone
* TODO: change metric to be "closest to the centoid of the
possible points"
*
* @param geoms list of Point or MultiPoint (any other geometry types
are rejected
* @param displayGeometry
* @return a point or null (if there's nothing to draw)
*/
Point getPointSetRepresentativeLocation(List geoms, Geometry
displayGeometry)
/**
* 1. make a list of all the geoms (not clipped)
* NOTE: reject points, convert polygons to their exterior ring
(you shouldnt be calling this function with points and polys)
* 2. join the lines together
* 3. clip resulting lines to display geometry
* 4. return longest line
*
* NOTE: the joining has multiple solution. For example, consider a
Y (3 lines):
* * *
* 1 2
* * *
* *
* 3
* *
* solutions are:
* 1->2 and 3
* 1->3 and 2
* 2->3 and 1
*
* (see mergeLines() below for detail of the algorithm; its basically
a greedy
* algorithm that should form the 'longest' possible route through
the linework)
*
* NOTE: we clip after joining because there could be connections
"going on" outside the display bbox
*
*
* @param geoms
* @param displayGeometry must be poly
*/
LineString getLineSetRepresentativeLocation(List geoms, Geometry
displayGeometry)
/**
* 1. make a list of all the polygons clipped to the displayGeometry
* NOTE: reject any points or lines
* 2. choose the largest of the clipped geometries
*
* @param geoms
* @param displayGeometry
* @return
*/
Polygon getPolySetRepresentativeLocation(List geoms, Geometry
displayGeometry)
2. I changed the actual drawing routines;
1. get the "representative geometry" (as above)
2. for points, label as before
3. for lines, find the middle point on the line (old version just
averaged start and end points) and centre label on that point (rotated)
4. for polygons, put the label in the middle of the polygon
3. TODO: For polygons and lines, the labeler should look at multiple
locations and choose the best:
ie. for lines, try the label at the 1/3, 1/2, and 2/3 location.
Metric is how close the label bounding box is to the line.
ie. for polygons, bisect the polygon (about the centroid) into
North, South, East and West polygons. Use the location that has the
label best inside the polygon.
After this is done, you can start doing constraint relaxation to
figure out which set of a labels to actually draw and where (use other
information to help decide this like priority - label Hwys over
sidestreets).
4. TODO: deal with labels going off the edge of the screen (much reduced
now).
5. TODO: add a "minimum quality" parameter (ie. if you're labeling a
tiny polygon with a tiny label, dont bother). Metrics are descibed in
#3.
6. TODO: add ability for SLD to tweak parameters (ie. "always label").
I will probably not do these for quite a while (if ever), except perhaps
adding the parameters into SLD so users can do some tweaking.
I'll fix up the java docs tomorrow after I've done a bit more testing.
See attached pics (from TIGER in Downtown NY).
dave
----------------------------------------------------------
This mail sent through IMP: https://webmail.limegroup.com/