Search in sources :

Example 16 with WKTWriter

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;
}
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 17 with WKTWriter

use of com.vividsolutions.jts.io.WKTWriter in project alliance by codice.

the class LocationKlvProcessor method setLocationFromAttribute.

private void setLocationFromAttribute(Metacard metacard, Attribute attribute, GeometryOperator.Context geometryOperatorContext) {
    WKTReader wktReader = new WKTReader();
    WKTWriter wktWriter = new WKTWriter();
    GeometryUtility.createUnionOfGeometryAttribute(wktReader, wktWriter, attribute, postUnionGeometryOperator, preUnionGeometryOperator, geometryOperatorContext).ifPresent(location -> setAttribute(metacard, location));
}
Also used : WKTWriter(com.vividsolutions.jts.io.WKTWriter) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 18 with WKTWriter

use of com.vividsolutions.jts.io.WKTWriter in project alliance by codice.

the class LineStringMetacardUpdater method setAttribute.

private void setAttribute(Metacard parent, Geometry lineString) {
    WKTWriter wktWriter = new WKTWriter();
    parent.setAttribute(createAttribute(wktWriter.write(lineString)));
}
Also used : WKTWriter(com.vividsolutions.jts.io.WKTWriter)

Example 19 with WKTWriter

use of com.vividsolutions.jts.io.WKTWriter in project alliance by codice.

the class LocationMetacardUpdater method locationUnion.

private Optional<String> locationUnion(Metacard metacard1, Metacard metacard2, GeometryOperator.Context geometryOperatorContext) {
    WKTReader wktReader = new WKTReader();
    WKTWriter wktWriter = new WKTWriter();
    Optional<Geometry> parentGeometry = GeometryUtility.wktToGeometry(metacard1.getLocation(), wktReader);
    Optional<Geometry> childGeometry = GeometryUtility.wktToGeometry(metacard2.getLocation(), wktReader);
    return Stream.of(parentGeometry, childGeometry).filter(Optional::isPresent).map(Optional::get).map(geometry -> preUnionGeometryOperator.apply(geometry, geometryOperatorContext)).reduce(Geometry::union).map(geometry -> postUnionGeometryOperator.apply(geometry, geometryOperatorContext)).map(wktWriter::write);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Stream(java.util.stream.Stream) Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) Optional(java.util.Optional) GeometryUtility(org.codice.alliance.libs.klv.GeometryUtility) Context(org.codice.alliance.video.stream.mpegts.Context) WKTReader(com.vividsolutions.jts.io.WKTReader) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) WKTWriter(com.vividsolutions.jts.io.WKTWriter) Optional(java.util.Optional) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 20 with WKTWriter

use of com.vividsolutions.jts.io.WKTWriter in project alliance by codice.

the class LocationUpdateField method setLocation.

private void setLocation(Metacard parentMetacard, Geometry geometry) {
    WKTWriter wktWriter = new WKTWriter();
    parentMetacard.setAttribute(new AttributeImpl(Core.LOCATION, wktWriter.write(geometry)));
}
Also used : WKTWriter(com.vividsolutions.jts.io.WKTWriter) AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Aggregations

WKTWriter (com.vividsolutions.jts.io.WKTWriter)23 Geometry (com.vividsolutions.jts.geom.Geometry)11 WKTReader (com.vividsolutions.jts.io.WKTReader)7 ParseException (com.vividsolutions.jts.io.ParseException)5 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)4 ValueFactory (org.openrdf.model.ValueFactory)4 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)4 Metacard (ddf.catalog.data.Metacard)2 File (java.io.File)2 Optional (java.util.Optional)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Resource (org.openrdf.model.Resource)2 URI (org.openrdf.model.URI)2 Value (org.openrdf.model.Value)2 StatementImpl (org.openrdf.model.impl.StatementImpl)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 LineString (com.vividsolutions.jts.geom.LineString)1 LinearRing (com.vividsolutions.jts.geom.LinearRing)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1