use of com.vividsolutions.jts.io.WKTReader 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.WKTReader 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);
}
use of com.vividsolutions.jts.io.WKTReader in project OpenTripPlanner by opentripplanner.
the class AddTripPatternTest method getAddTripPattern.
private AddTripPattern getAddTripPattern(RouteSelector sel) throws Exception {
AddTripPattern atp = new AddTripPattern();
WKTReader wr = new WKTReader();
atp.geometry = sel.getGeometry();
atp.name = "Broad High Express";
atp.stops = new BitSet();
// or on East Broad, depending on geometry chosen
for (int i = 0; i < 6; i++) {
if (i == 3)
atp.stops.clear(i);
else
atp.stops.set(i);
}
atp.timetables = Lists.newArrayList();
return atp;
}
use of com.vividsolutions.jts.io.WKTReader in project alliance by codice.
the class NitfGmtiTransformer method transformAircraftLocation.
private void transformAircraftLocation(Metacard metacard) {
String aircraftLocation = formatAircraftLocation(metacard);
try {
LOGGER.debug("Formatted Aircraft Location = {}", aircraftLocation);
if (aircraftLocation != null) {
// validate the wkt
WKTReader wktReader = new WKTReader(geometryFactory);
wktReader.read(aircraftLocation);
MtirpbAttribute.AIRCRAFT_LOCATION_ATTRIBUTE.getAttributeDescriptors().forEach(descriptor -> setMetacardAttribute(metacard, descriptor.getName(), aircraftLocation));
}
} catch (ParseException e) {
LOGGER.debug(e.getMessage(), e);
}
}
use of com.vividsolutions.jts.io.WKTReader in project alliance by codice.
the class NitfGmtiTransformer method transformTargetLocation.
private void transformTargetLocation(Metacard metacard) {
String locationString = formatTargetLocation(metacard);
try {
LOGGER.debug("Formatted Target Location(s) = {}", locationString);
if (locationString != null) {
// validate the wkt
WKTReader wktReader = new WKTReader(geometryFactory);
Geometry geometry = wktReader.read(locationString);
LOGGER.debug("Setting the metacard attribute [{}, {}]", Core.LOCATION, geometry.toText());
IndexedMtirpbAttribute.INDEXED_TARGET_LOCATION_ATTRIBUTE.getAttributeDescriptors().forEach(descriptor -> setMetacardAttribute(metacard, descriptor.getName(), geometry.toText()));
}
} catch (ParseException e) {
LOGGER.debug(e.getMessage(), e);
}
}
Aggregations