Search in sources :

Example 56 with ParseException

use of com.vividsolutions.jts.io.ParseException 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)

Example 57 with ParseException

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

the class ResultDAGConverter method addSpatialGeoRefBoxAttribute.

private static void addSpatialGeoRefBoxAttribute(DirectedAcyclicGraph<Node, Edge> graph, Metacard metacard, ORB orb, List<String> resultAttributes, List<String> addedAttributes, String attribute, Node coverageNode) {
    if (shouldAdd(buildAttr(attribute, NsiliConstants.SPATIAL_GEOGRAPHIC_REF_BOX), resultAttributes)) {
        Attribute geoAttr = metacard.getAttribute(Core.LOCATION);
        if (geoAttr != null) {
            String wktGeo = String.valueOf(geoAttr.getValue());
            try {
                Geometry boundingGeo = WKTUtil.getWKTBoundingRectangle(wktGeo);
                Rectangle rect = NsiliGeomUtil.getRectangle(boundingGeo);
                addGeomAttribute(graph, coverageNode, NsiliConstants.SPATIAL_GEOGRAPHIC_REF_BOX, rect, orb);
                addedAttributes.add(buildAttr(attribute, NsiliConstants.SPATIAL_GEOGRAPHIC_REF_BOX));
            } catch (ParseException pe) {
                LOGGER.debug("Unable to parse WKT for bounding box: {}", wktGeo, pe);
            }
        }
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Attribute(ddf.catalog.data.Attribute) Rectangle(org.codice.alliance.nsili.common.UCO.Rectangle) ParseException(com.vividsolutions.jts.io.ParseException)

Example 58 with ParseException

use of com.vividsolutions.jts.io.ParseException in project teiid by teiid.

the class GeometryUtils method snapToGrid.

public static GeometryType snapToGrid(GeometryType geom, double size) throws FunctionExecutionException {
    if (size == 0) {
        return geom;
    }
    Geometry g1 = getGeometry(geom);
    PrecisionModel precisionModel = new PrecisionModel(1 / size);
    GeometryPrecisionReducer reducer = new GeometryPrecisionReducer(precisionModel);
    reducer.setPointwise(true);
    reducer.setChangePrecisionModel(true);
    Geometry result = reducer.reduce(g1);
    // since the wkb writer doesn't consider precision, we have to first write/read through wkt
    WKTWriter writer = new WKTWriter();
    String val = writer.write(result);
    WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
    try {
        result = reader.read(new StringReader(val));
    } catch (ParseException e) {
        throw new FunctionExecutionException(e);
    }
    result.setSRID(geom.getSrid());
    return getGeometryType(result);
}
Also used : WKTWriter(com.vividsolutions.jts.io.WKTWriter) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) GeometryPrecisionReducer(com.vividsolutions.jts.precision.GeometryPrecisionReducer) StringReader(java.io.StringReader) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 59 with ParseException

use of com.vividsolutions.jts.io.ParseException in project teiid by teiid.

the class GeometryUtils method geometryFromClob.

public static GeometryType geometryFromClob(ClobType wkt, Integer srid, boolean allowEwkt) throws FunctionExecutionException {
    Reader r = null;
    try {
        WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
        r = wkt.getCharacterStream();
        if (allowEwkt) {
            PushbackReader pbr = new PushbackReader(r, 1);
            r = pbr;
            char[] expected = new char[] { 's', 'r', 'i', 'd', '=' };
            int expectedIndex = 0;
            StringBuilder sridBuffer = null;
            for (int i = 0; i < 100000; i++) {
                int charRead = pbr.read();
                if (charRead == -1) {
                    break;
                }
                if (expectedIndex == expected.length) {
                    // parse srid
                    if (sridBuffer == null) {
                        sridBuffer = new StringBuilder(4);
                    }
                    if (charRead == ';') {
                        if (sridBuffer.length() == 0) {
                            pbr.unread(charRead);
                        }
                        break;
                    }
                    sridBuffer.append((char) charRead);
                    continue;
                }
                if (expectedIndex == 0 && Character.isWhitespace(charRead)) {
                    continue;
                }
                if (expected[expectedIndex] != Character.toLowerCase(charRead)) {
                    pbr.unread(charRead);
                    break;
                }
                expectedIndex++;
            }
            if (sridBuffer != null) {
                srid = Integer.parseInt(sridBuffer.toString());
            }
        }
        Geometry jtsGeometry = reader.read(r);
        if (jtsGeometry == null) {
            // for some reason io and parse exceptions are caught in their logic if they occur on the first word, then null is returned
            throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31203));
        }
        if (!allowEwkt && (jtsGeometry.getSRID() != GeometryType.UNKNOWN_SRID || (jtsGeometry.getCoordinate() != null && !Double.isNaN(jtsGeometry.getCoordinate().z)))) {
            // $NON-NLS-1$
            throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31160, "EWKT"));
        }
        if (srid == null) {
            srid = jtsGeometry.getSRID();
        }
        return getGeometryType(jtsGeometry, srid);
    } catch (ParseException e) {
        throw new FunctionExecutionException(e);
    } catch (SQLException e) {
        throw new FunctionExecutionException(e);
    } catch (IOException e) {
        throw new FunctionExecutionException(e);
    } finally {
        if (r != null) {
            try {
                r.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) SQLException(java.sql.SQLException) GeoJSONReader(org.wololo.jts2geojson.GeoJSONReader) WKBReader(com.vividsolutions.jts.io.WKBReader) Reader(java.io.Reader) WKTReader(com.vividsolutions.jts.io.WKTReader) StringReader(java.io.StringReader) PushbackReader(java.io.PushbackReader) ParseException(com.vividsolutions.jts.io.ParseException) IOException(java.io.IOException) WKTReader(com.vividsolutions.jts.io.WKTReader) PushbackReader(java.io.PushbackReader)

Example 60 with ParseException

use of com.vividsolutions.jts.io.ParseException in project tests by datanucleus.

the class JtsGeometryMappingTest method testUserDataMappingWithObject.

public void testUserDataMappingWithObject() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    Point point = (Point) wktReader.read("POINT(10 10)");
    point.setSRID(-1);
    Object userData = new Object();
    point.setUserData(userData);
    SamplePoint samplePoint;
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        samplePoint = new SamplePoint(11001, "UserDataWithObject", point);
        em.persist(samplePoint);
        tx.commit();
        fail("Persisted spatial field with non-serializable user-data but should have failed");
    } catch (Exception e) {
    // Expected : should fail since Object is not Serializable
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}
Also used : SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) Point(com.vividsolutions.jts.geom.Point) ParseException(com.vividsolutions.jts.io.ParseException) SQLException(java.sql.SQLException) PersistenceException(javax.persistence.PersistenceException)

Aggregations

ParseException (com.vividsolutions.jts.io.ParseException)64 Geometry (com.vividsolutions.jts.geom.Geometry)28 WKTReader (com.vividsolutions.jts.io.WKTReader)21 ConverterException (ch.ehi.ili2db.converter.ConverterException)17 RyaStatement (org.apache.rya.api.domain.RyaStatement)7 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 Statement (org.openrdf.model.Statement)7 Wkb2iox (ch.interlis.iox_j.wkb.Wkb2iox)6 IsValidOp (com.vividsolutions.jts.operation.valid.IsValidOp)6 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)6 IoxException (ch.interlis.iox.IoxException)5 MapLayer (au.org.emii.portal.menu.MapLayer)4 WKBReader (com.vividsolutions.jts.io.WKBReader)4 IOException (java.io.IOException)4 Literal (org.openrdf.model.Literal)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 Point (com.vividsolutions.jts.geom.Point)3 Polygon (com.vividsolutions.jts.geom.Polygon)3 WKTWriter (com.vividsolutions.jts.io.WKTWriter)3 SQLException (java.sql.SQLException)3