GeoTools

Ability to change the threshold for the goodness fit algorithm for polygon labels

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 2.5.5
  • Component/s: render
  • Labels:
    None

Description

We have a case where several labels for polygon geometries are not rendered due to the fact that they don't score high enough in the goodness fit algorithm. Since spaceAround and group can be changed via options (by VendorOption) the goodness fit threshold value should too imho. Not able to post a proper patch unfortunately but the changes are pretty small:

  • Add variable, getter and setter for the threshold value in LabelCacheItem.java.
  • Add a method to get the value in LabelCacheDefault similar to isGrouping/getSpaceAround:

private double getMinGoodnessFit(TextSymbolizer symbolizer) {
String value = symbolizer.getOption("minGoodnessFit");
if (value == null)
return DEFAULT_MIN_GOODNESS_FIT;
try { return Double.parseDouble(value); } catch (Exception e) { return DEFAULT_MIN_GOODNESS_FIT; }
}

  • set the value on the labelItem in the put()-method:
    item.setMinGoodnessFit(getMinGoodnessFit(symbolizer));
  • Change the check in the end()-method to something like:

double minGoodnessFit = labelItem.getMinGoodnessFit();
// <= 0 means no check for goodness fit
if (minGoodnessFit > 0 && goodnessOfFit(glyphVector, tempTransform,
representativeGeom) < minGoodnessFit)
continue;

Issue Links

Activity

Hide
Andrea Aime added a comment -
Solving this by adding a new vendor parameter for labels, "minGoodnessOfFit", meant to be a double between 0 and 1, default value is 0.7. (0 -> label always shown, 1 -> shown only if the sample points used to check the label extents relative to the polygon are all inside the polygon).
Show
Andrea Aime added a comment - Solving this by adding a new vendor parameter for labels, "minGoodnessOfFit", meant to be a double between 0 and 1, default value is 0.7. (0 -> label always shown, 1 -> shown only if the sample points used to check the label extents relative to the polygon are all inside the polygon).
Hide
Andrea Aime added a comment -
Fixed on 2.5.x and trunk
Show
Andrea Aime added a comment - Fixed on 2.5.x and trunk
Hide
Andrea Aime added a comment -
Ah, btw, on 2.5.x the fix is available only when using the new label cache org.geotools.renderer.label.LabelCacheImpl (that provides curved label support and a raft of other goodies)
Show
Andrea Aime added a comment - Ah, btw, on 2.5.x the fix is available only when using the new label cache org.geotools.renderer.label.LabelCacheImpl (that provides curved label support and a raft of other goodies)

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: