use of au.org.ala.spatial.dto.WKTReducedDTO in project spatial-portal by AtlasOfLivingAustralia.
the class Util method reduceWKT.
public static WKTReducedDTO reduceWKT(String originalWKT) {
String wkt = originalWKT;
String reducedBy = "No reduction.";
if (wkt == null) {
return new WKTReducedDTO(null, null, "Invalid WKT.");
}
try {
WKTReader wktReader = new WKTReader();
Geometry g = wktReader.read(wkt);
int maxPoints = Integer.parseInt(CommonData.getSettings().getProperty("max_q_wkt_points", "200"));
Geometry bestReduction = g;
double distance = 0.0001;
while (maxPoints > 0 && g.getNumPoints() > maxPoints && distance < 10) {
Geometry gsimplified = TopologyPreservingSimplifier.simplify(g, distance);
bestReduction = gsimplified;
reducedBy = "Simplified using distance tolerance " + distance;
distance *= 2;
}
wkt = bestReduction.toText();
LOGGER.info("user WKT of length: " + wkt.length());
} catch (Exception e) {
LOGGER.error("failed to reduce WKT size", e);
}
//webportal (for some reason) does not like these spaces in WKT
return new WKTReducedDTO(originalWKT, wkt.replace(" (", "(").replace(", ", ","), reducedBy);
}
use of au.org.ala.spatial.dto.WKTReducedDTO in project spatial-portal by AtlasOfLivingAustralia.
the class MapComposer method warnForLargeWKT.
public void warnForLargeWKT(MapLayer ml) {
//display warning for large wkt that does not have a facet
if (ml.getFacets() == null) {
WKTReader wktReader = new WKTReader();
try {
Geometry g = wktReader.read(ml.getWKT());
if (g.getNumPoints() > Integer.parseInt(CommonData.getSettings().getProperty("max_q_wkt_points", "200"))) {
WKTReducedDTO reduced = Util.reduceWKT(ml.getWKT());
ml.setWKT(reduced.getReducedWKT());
Geometry gsimplified = wktReader.read(ml.getWKT());
getMapComposer().showMessage("WARNING: The polygon has more than the maximum number of points and has been simplified, " + "\r\n\r\noriginal points: " + g.getNumPoints() + "\r\nmax points: " + CommonData.getSettings().getProperty("max_q_wkt_points", "200") + "\r\nsimplified points: " + gsimplified.getNumPoints());
}
} catch (Exception e) {
LOGGER.error("error testing and reducing WKT", e);
}
}
}
Aggregations