use of com.vividsolutions.jts.geom.Geometry in project spatial-portal by AtlasOfLivingAustralia.
the class UserDataQuery method newWkt.
/**
* Restrict to an area.
* <p/>
* If an area already exists the additional area is applied.
*
* @param wkt
* @return new BiocacheQuery with the additional wkt area applied.
*/
@Override
public UserDataQuery newWkt(String wkt, boolean forMapping) {
if (wkt == null || wkt.equals(CommonData.WORLD_WKT) || wkt.equals(this.wkt)) {
return this;
}
UserDataQuery sq = null;
try {
String newWkt = wkt;
if (this.wkt != null) {
Geometry newGeom = new WKTReader().read(wkt);
Geometry thisGeom = new WKTReader().read(this.wkt);
Geometry intersectionGeom = thisGeom.intersection(newGeom);
newWkt = (new WKTWriter()).write(intersectionGeom).replace(" (", "(").replace(", ", ",").replace(") ", ")");
}
sq = new UserDataQuery(udHeaderId, newWkt, facets);
} catch (Exception e) {
LOGGER.error("failed to filter user uploaded points with WKT: " + udHeaderId + ", " + wkt);
}
return sq;
}
use of com.vividsolutions.jts.geom.Geometry in project series-rest-api by 52North.
the class TransformationService method transformInline.
/**
* @param feature the feature to transform.
* @param query the query containing CRS and how to handle axes order.
*/
protected void transformInline(GeoJSONFeature feature, IoParameters query) {
String crs = query.getCrs();
if (CRSUtils.DEFAULT_CRS.equals(crs)) {
// no need to transform
return;
}
Geometry geometry = transform(feature.getGeometry(), query);
if (geometry != null) {
feature.setGeometry(geometry);
}
}
use of com.vividsolutions.jts.geom.Geometry in project series-rest-api by 52North.
the class GeoJSONTest method readWriteTest.
protected void readWriteTest(final Geometry geom) {
try {
JsonNode json = enc.encodeGeometry(geom);
Geometry parsed = dec.decodeGeometry(json);
JsonNode json2 = enc.encodeGeometry(parsed);
errors.checkThat(geom, is(equalTo(parsed)));
// errors.checkThat(json, is(instanceOf(JSONConstants.GEOMETRY)));
// errors.checkThat(json2, is(instanceOf(JSONConstants.GEOMETRY)));
errors.checkThat(json, is(equalTo(json2)));
} catch (GeoJSONException ex) {
errors.addError(ex);
}
}
use of com.vividsolutions.jts.geom.Geometry in project series-rest-api by 52North.
the class IoParametersTest method when_jsonBbox_then_parsingSpatialFilter.
@Test
public void when_jsonBbox_then_parsingSpatialFilter() throws ParseException {
Map<String, String> map = Collections.singletonMap("bbox", "{\"ll\":{\"type\":\"Point\",\"coordinates\":[6.7,51.7]},\"ur\":{\"type\":\"Point\",\"coordinates\":[7.9,51.9]}}");
IoParameters parameters = createFromSingleValueMap(map);
BoundingBox actual = parameters.getSpatialFilter();
WKTReader wktReader = new WKTReader();
Geometry ll = wktReader.read("POINT (6.7 51.7)");
Geometry ur = wktReader.read("POINT(7.9 51.9)");
Assert.assertTrue(actual.getLowerLeft().equals(ll));
Assert.assertTrue(actual.getUpperRight().equals(ur));
}
use of com.vividsolutions.jts.geom.Geometry in project spatial-portal by AtlasOfLivingAustralia.
the class AreaUploadShapefile method getKMLPolygonAsWKT.
/**
* parse a KML containing a single placemark, or a placemark in a folder, into WKT.
*
* @param kmldata
* @return WKT if valid, null on error, empty string "" when placemark not matched.
*/
private static String getKMLPolygonAsWKT(String kmldata) {
try {
Parser parser = new Parser(new org.geotools.kml.v22.KMLConfiguration());
SimpleFeature f = (SimpleFeature) parser.parse(new StringReader(kmldata));
Collection placemarks = (Collection) f.getAttribute(StringConstants.FEATURE);
Geometry g = null;
SimpleFeature sf = null;
//for <Placemark>
if (!placemarks.isEmpty() && !placemarks.isEmpty()) {
sf = (SimpleFeature) placemarks.iterator().next();
g = (Geometry) sf.getAttribute("Geometry");
}
//for <Folder><Placemark>
if (g == null && sf != null) {
placemarks = (Collection) sf.getAttribute(StringConstants.FEATURE);
if (placemarks != null && !placemarks.isEmpty()) {
g = (Geometry) ((SimpleFeature) placemarks.iterator().next()).getAttribute("Geometry");
} else {
placemarks = (Collection) sf.getAttribute("Folder");
if (placemarks != null && !placemarks.isEmpty()) {
g = (Geometry) ((SimpleFeature) placemarks.iterator().next()).getAttribute("Geometry");
}
}
}
if (g != null) {
WKTWriter wr = new WKTWriter();
String wkt = wr.write(g);
return wkt.replace(" (", "(").replace(", ", ",").replace(") ", ")");
} else {
return "";
}
} catch (SAXException e) {
LOGGER.error("KML spec parse error", e);
} catch (ParserConfigurationException e) {
LOGGER.error("error converting KML to WKT", e);
} catch (Exception e) {
LOGGER.error("error reading KML", e);
}
return null;
}
Aggregations