Search in sources :

Example 51 with WKTReader

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;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) WKTReader(com.vividsolutions.jts.io.WKTReader) IOException(java.io.IOException)

Example 52 with WKTReader

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);
}
Also used : WKTReader(com.vividsolutions.jts.io.WKTReader) WKTReducedDTO(au.org.ala.spatial.dto.WKTReducedDTO) ParseException(com.vividsolutions.jts.io.ParseException)

Example 53 with WKTReader

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;
}
Also used : BitSet(java.util.BitSet) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 54 with WKTReader

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);
    }
}
Also used : ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 55 with WKTReader

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);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader)

Aggregations

WKTReader (com.vividsolutions.jts.io.WKTReader)70 Geometry (com.vividsolutions.jts.geom.Geometry)50 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 File (java.io.File)3 Before (org.junit.Before)3