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);
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations