use of com.vividsolutions.jts.io.WKTWriter in project spatial-portal by AtlasOfLivingAustralia.
the class BiocacheQuery 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 BiocacheQuery newWkt(String wkt, boolean forMapping) {
if (wkt == null || wkt.equals(CommonData.WORLD_WKT) || wkt.equals(this.wkt)) {
if (this.forMapping || !forMapping) {
return this;
} else {
return new BiocacheQuery(lsids, rawNames, wkt, extraParams, facets, forMapping, null, biocacheServer, biocacheWebServer, this.supportsDynamicFacets);
}
}
BiocacheQuery 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 BiocacheQuery(lsids, rawNames, newWkt, extraParams, facets, forMapping, null, biocacheServer, biocacheWebServer, this.supportsDynamicFacets);
} catch (Exception e) {
LOGGER.error("error getting new WKT from an intersection", e);
}
return sq;
}
use of com.vividsolutions.jts.io.WKTWriter 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.io.WKTWriter 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;
}
use of com.vividsolutions.jts.io.WKTWriter in project ddf by codice.
the class GmlGeometryConverter method unmarshal.
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
XmlNode gmlNode = new XmlNode(reader);
GMLReader gmlReader = new GMLReader();
Geometry geo = null;
try {
geo = gmlReader.read(gmlNode.toString(), null);
} catch (SAXException | IOException | ParserConfigurationException e) {
LOGGER.debug(ERROR_PARSING_MSG, e);
}
if (geo != null) {
WKTWriter wktWriter = new WKTWriter();
return wktWriter.write(geo);
}
return null;
}
use of com.vividsolutions.jts.io.WKTWriter in project ddf by codice.
the class GeometryAdapter method unmarshalFrom.
public static Attribute unmarshalFrom(GeometryElement element) throws ConversionFailedException {
AttributeImpl attribute = null;
GML311ToJTSGeometryConverter converter = new GML311ToJTSGeometryConverter();
WKTWriter wktWriter = new WKTWriter();
for (Value xmlValue : element.getValue()) {
JAXBElement<AbstractGeometryType> xmlGeometry = xmlValue.getGeometry();
Geometry geometry = converter.createGeometry(new DefaultRootObjectLocator(xmlValue), xmlGeometry.getValue());
String wkt = wktWriter.write(geometry);
if (attribute == null) {
attribute = new AttributeImpl(element.getName(), wkt);
} else {
attribute.addValue(wkt);
}
}
return attribute;
}
Aggregations