Search in sources :

Example 31 with WKTReader

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

the class NsiliFilterFactory method convertWktToBqs.

public String convertWktToBqs(String wkt) {
    WKTReader wktReader = new WKTReader(GEOMETRY_FACTORY);
    Geometry geometry;
    try {
        geometry = wktReader.read(wkt);
    } catch (ParseException e) {
        LOGGER.debug("Unable to parse WKT String {}", wkt, e);
        return NsiliFilterDelegate.EMPTY_STRING;
    }
    if (geometry.getCoordinates() == null || StringUtils.isBlank(geometry.getGeometryType())) {
        return NsiliFilterDelegate.EMPTY_STRING;
    }
    StringBuilder result = new StringBuilder(geometry.getGeometryType().toUpperCase() + LP);
    Coordinate[] coordinates = geometry.getCoordinates();
    for (Coordinate coordinate : coordinates) {
        result.append(coordinate.y + COMMA + coordinate.x + COMMA);
    }
    return result.toString().substring(0, result.toString().length() - 1) + RP;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 32 with WKTReader

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

the class ChipServiceImplTest method setUp.

@Before
public void setUp() throws IOException, ParseException {
    this.chipService = new ChipServiceImpl();
    this.inputImage = ImageIO.read(getInputStream(OVERVIEW_FILE));
    this.wktReader = new WKTReader();
}
Also used : WKTReader(com.vividsolutions.jts.io.WKTReader) Before(org.junit.Before)

Example 33 with WKTReader

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

the class ImagingChipActionProvider method hasValidLocation.

private boolean hasValidLocation(String location) {
    if (StringUtils.isNotBlank(location)) {
        try {
            // parse the WKT location to determine if it has valid format
            final WKTReader wktReader = new WKTReader(geometryFactory);
            wktReader.read(location);
            return true;
        } catch (ParseException e) {
            LOGGER.debug("Location [{}] is invalid. Cannot chip this image", location);
        }
    }
    return false;
}
Also used : ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 34 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project hibernate-spatial-tutorials by maesenka.

the class EventManager method wktToGeometry.

private Geometry wktToGeometry(String wktPoint) {
    WKTReader fromText = new WKTReader();
    Geometry geom = null;
    try {
        geom = fromText.read(wktPoint);
    } catch (ParseException e) {
        throw new RuntimeException("Not a WKT string:" + wktPoint);
    }
    return geom;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 35 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project spatial-portal by AtlasOfLivingAustralia.

the class Util method getBoundingBox.

public static List<Double> getBoundingBox(String wkt) {
    try {
        WKTReader wktReader = new WKTReader();
        com.vividsolutions.jts.geom.Geometry g = wktReader.read(wkt);
        List<Double> bbox = new ArrayList<Double>();
        bbox.add(g.getEnvelopeInternal().getMinX());
        bbox.add(g.getEnvelopeInternal().getMinY());
        bbox.add(g.getEnvelopeInternal().getMaxX());
        bbox.add(g.getEnvelopeInternal().getMaxY());
        return bbox;
    } catch (Exception e) {
        return Util.getBoundingBox(CommonData.WORLD_WKT);
    }
}
Also used : WKTReader(com.vividsolutions.jts.io.WKTReader) com.vividsolutions.jts.geom(com.vividsolutions.jts.geom) ParseException(com.vividsolutions.jts.io.ParseException)

Aggregations

WKTReader (com.vividsolutions.jts.io.WKTReader)71 Geometry (com.vividsolutions.jts.geom.Geometry)51 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 Before (org.junit.Before)3 Facet (au.org.ala.legend.Facet)2