Search in sources :

Example 16 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project hibernate-orm by hibernate.

the class AbstractExpectationsFactory method getTestPoint.

/**
 * Return a testsuite-suite point (filter, ...)
 *
 * @return a testsuite-suite point
 */
public Point getTestPoint() {
    WKTReader reader = new WKTReader();
    try {
        Point point = (Point) reader.read(TEST_POINT_WKT);
        point.setSRID(getTestSrid());
        return point;
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
Also used : Point(com.vividsolutions.jts.geom.Point) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 17 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project hibernate-orm by hibernate.

the class AbstractExpectationsFactory method getTestPolygon.

/**
 * Return a testsuite-suite polygon (filter, ...)
 *
 * @return a testsuite-suite polygon
 */
public Polygon getTestPolygon() {
    WKTReader reader = new WKTReader();
    try {
        Polygon polygon = (Polygon) reader.read(TEST_POLYGON_WKT);
        polygon.setSRID(getTestSrid());
        return polygon;
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
Also used : ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 18 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project spatial-portal by AtlasOfLivingAustralia.

the class AooEooComposer method onFinish.

@Override
public boolean onFinish() {
    SelectedArea sa = getSelectedArea();
    Query q = getSelectedSpecies();
    q = q.newFacet(new Facet("occurrence_status_s", "absent", false), false);
    Facet f = new Facet("occurrence_status_s", "absent", false);
    q = q.newFacet(f, false);
    Query newQ = QueryUtil.queryFromSelectedArea(q, sa, false, null);
    double gridSize = dResolution.doubleValue();
    // eoo, use actual points
    LegendObject legend = newQ.getLegend("lat_long");
    StringBuilder sb = new StringBuilder();
    int pointCount = processLegend(legend, sb);
    String aooWkt = aooWkt(legend, gridSize);
    // aoo = gridSize * gridSize * number of gridSize by gridSize cells with an occurrence * (approx sq degrees to sq km)
    double aoo = gridSize * gridSize * aooProcess(legend, gridSize) * 10000;
    double eoo = 0;
    WKTReader reader = new WKTReader();
    String metadata = null;
    try {
        Geometry g = reader.read(sb.toString());
        Geometry convexHull = g.convexHull();
        String wkt = convexHull.toText().replace(" (", "(").replace(", ", ",");
        eoo = SpatialUtil.calculateArea(wkt);
        // aoo area
        Geometry a = reader.read(aooWkt(legend, gridSize));
        Geometry aUnion = a.union();
        String aWkt = aUnion.toText().replace(" (", "(").replace(", ", ",");
        if (eoo > 0) {
            String name = "Extent of occurrence (area): " + q.getName();
            MapLayer ml = getMapComposer().addWKTLayer(wkt, name, name);
            name = "Area of occupancy (area): " + q.getName();
            MapLayer mla = getMapComposer().addWKTLayer(aWkt, name, name);
            metadata = "<html><body>" + "<div class='aooeoo'>" + "<div>The Sensitive Data Service may have changed the location of taxa that have a sensitive status." + " It is wise to first map the taxa and examine each record, then filter these records to create the " + "desired subset, then run the tool on the new filtered taxa layer.</div><br />" + "<table >" + "<tr><td>Number of records used for the calculations</td><td>" + newQ.getOccurrenceCount() + "</td></tr>" + "<tr><td>Species</td><td>" + q.getName() + "</td></tr>" + "<tr><td>Area of Occupancy (AOO: " + gridSize + " degree grid)</td><td>" + String.format("%.0f", aoo) + " sq km</td></tr>" + "<tr><td>Extent of Occurrence (EOO: Minimum convex hull)</td><td>" + (String.format("%.2f", eoo / 1000.0 / 1000.0)) + " sq km</td></tr></table></body></html>" + "</div>";
            ml.getMapLayerMetadata().setMoreInfo("Area of Occupancy and Extent of Occurrence\n" + metadata);
            name = "Extent of occurrence (points): " + q.getName();
            MapLayer ml2 = getMapComposer().mapSpecies(newQ, name, StringConstants.SPECIES, newQ.getOccurrenceCount(), LayerUtilitiesImpl.SPECIES, null, 0, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
            ml2.getMapLayerMetadata().setMoreInfo("Area of Occupancy and Extent of Occurrence\n" + metadata);
        } else {
            // trigger eoo unavailable message
            pointCount = 2;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    // show results
    String message = "The Sensitive Data Service may have changed the location of taxa that have a sensitive status. " + "It is wise to first map the taxa and examine each record, then filter these records to create the " + "desired subset, then run the tool on the new filtered taxa layer.\r\n" + "\r\nNumber of records used for the calculations: " + newQ.getOccurrenceCount() + "\r\nSpecies: " + q.getName() + "\r\nArea of Occupancy: " + String.format("%.0f", aoo) + " sq km" + "\r\nExtent of Occurrence: " + (pointCount < 3 ? "insufficient unique occurrence locations" : (String.format("%.2f", eoo / 1000.0 / 1000.0) + " sq km"));
    if (metadata != null) {
        Event ev = new Event(StringConstants.ONCLICK, null, "Area of Occupancy and Extent of Occurrence\n" + metadata);
        getMapComposer().openHTML(ev);
    } else {
        getMapComposer().showMessage(message);
    }
    // download metadata as text
    Filedownload.save(message, "text/plain", "Calculated AOO and EOO.txt");
    this.detach();
    return true;
}
Also used : Query(au.org.ala.spatial.util.Query) SelectedArea(au.org.emii.portal.menu.SelectedArea) MapLayer(au.org.emii.portal.menu.MapLayer) WKTReader(com.vividsolutions.jts.io.WKTReader) Geometry(com.vividsolutions.jts.geom.Geometry) LegendObject(au.org.ala.legend.LegendObject) Event(org.zkoss.zk.ui.event.Event) Facet(au.org.ala.legend.Facet)

Example 19 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project spatial-portal by AtlasOfLivingAustralia.

the class Util method fixWkt.

public static String fixWkt(String wkt) {
    if (wkt == null || !(wkt.startsWith("POLYGON") || wkt.startsWith("MULTIPOLYGON"))) {
        return wkt;
    }
    String newWkt = wkt;
    try {
        WKTReader wktReader = new WKTReader();
        com.vividsolutions.jts.geom.Geometry g = wktReader.read(wkt);
        // NC 20130319: Ensure that the WKT is valid according to the WKT standards.
        // if outside -180 to 180, cut and fit
        Envelope env = g.getEnvelopeInternal();
        if (env.getMinX() < -180 || env.getMaxX() > 180) {
            int minx = -180;
            while (minx > env.getMinX()) {
                minx -= 360;
            }
            int maxx = 180;
            while (maxx < env.getMaxX()) {
                maxx += 360;
            }
            // divide, translate and rejoin
            Geometry newGeometry = null;
            for (int i = minx; i < maxx; i += 360) {
                Geometry cutter = wktReader.read("POLYGON((" + i + " -90," + i + " 90," + (i + 360) + " 90," + (i + 360) + " -90," + i + " -90))");
                Geometry part = cutter.intersection(g);
                // offset cutter
                if (i != -180) {
                    AffineTransformation at = AffineTransformation.translationInstance(-180 - i, 0);
                    part.apply(at);
                }
                if (part.getArea() > 0) {
                    if (newGeometry == null) {
                        newGeometry = part;
                    } else {
                        newGeometry = newGeometry.union(part);
                    }
                }
            }
            newWkt = newGeometry.toText();
        }
        IsValidOp op = new IsValidOp(g);
        if (!op.isValid()) {
            // this will fix some issues
            g = g.buffer(0);
            op = new IsValidOp(g);
        }
        if (!op.isValid()) {
        // give up?
        } else if (g.isRectangle()) {
            // NC 20130319: When the shape is a rectangle ensure that the points a specified in the correct order.
            // get the new WKT for the rectangle will possibly need to change the order.
            com.vividsolutions.jts.geom.Envelope envelope = g.getEnvelopeInternal();
            newWkt = StringConstants.POLYGON + "((" + envelope.getMinX() + " " + envelope.getMinY() + "," + envelope.getMaxX() + " " + envelope.getMinY() + "," + envelope.getMaxX() + " " + envelope.getMaxY() + "," + envelope.getMinX() + " " + envelope.getMaxY() + "," + envelope.getMinX() + " " + envelope.getMinY() + "))";
        }
    } catch (ParseException parseException) {
        LOGGER.error("error fixing WKT", parseException);
    }
    return newWkt;
}
Also used : WKTReader(com.vividsolutions.jts.io.WKTReader) com.vividsolutions.jts.geom(com.vividsolutions.jts.geom) AffineTransformation(com.vividsolutions.jts.geom.util.AffineTransformation) IsValidOp(com.vividsolutions.jts.operation.valid.IsValidOp) ParseException(com.vividsolutions.jts.io.ParseException)

Example 20 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project spatial-portal by AtlasOfLivingAustralia.

the class CommonData method filterJournalMapArticles.

public static List<JSONObject> filterJournalMapArticles(String wkt) {
    List<JSONObject> list = new ArrayList<JSONObject>();
    Set<Integer> set = new HashSet<Integer>();
    try {
        WKTReader wktReader = new WKTReader();
        com.vividsolutions.jts.geom.Geometry g = wktReader.read(wkt);
        for (JournalMapLocation l : journalMapLocations) {
            // only add it once (articles can have >1 location)
            if (!set.contains(l.idx)) {
                if (g.contains(l.point)) {
                    list.add(journalMapArticles.get(l.idx));
                    set.add(l.idx);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("error intersecting wkt with journal map articles", e);
    }
    return list;
}
Also used : JSONObject(org.json.simple.JSONObject) WKTReader(com.vividsolutions.jts.io.WKTReader)

Aggregations

WKTReader (com.vividsolutions.jts.io.WKTReader)71 Geometry (com.vividsolutions.jts.geom.Geometry)51 Test (org.junit.Test)28 ParseException (com.vividsolutions.jts.io.ParseException)23 WKTWriter (com.vividsolutions.jts.io.WKTWriter)9 Metacard (ddf.catalog.data.Metacard)9 Coordinate (com.vividsolutions.jts.geom.Coordinate)6 IsValidOp (com.vividsolutions.jts.operation.valid.IsValidOp)6 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)6 GeometryOperator (org.codice.alliance.libs.klv.GeometryOperator)6 Context (org.codice.alliance.video.stream.mpegts.Context)6 MapLayer (au.org.emii.portal.menu.MapLayer)5 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)4 Polygon (com.vividsolutions.jts.geom.Polygon)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Optional (java.util.Optional)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Before (org.junit.Before)3 Facet (au.org.ala.legend.Facet)2