Search in sources :

Example 1 with WKTReducedDTO

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);
}
Also used : WKTReader(com.vividsolutions.jts.io.WKTReader) WKTReducedDTO(au.org.ala.spatial.dto.WKTReducedDTO) ParseException(com.vividsolutions.jts.io.ParseException)

Example 2 with WKTReducedDTO

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);
        }
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) WKTReducedDTO(au.org.ala.spatial.dto.WKTReducedDTO) ParseException(org.json.simple.parser.ParseException)

Aggregations

WKTReducedDTO (au.org.ala.spatial.dto.WKTReducedDTO)2 WKTReader (com.vividsolutions.jts.io.WKTReader)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 ParseException (com.vividsolutions.jts.io.ParseException)1 ParseException (org.json.simple.parser.ParseException)1