Search in sources :

Example 61 with ParseException

use of com.vividsolutions.jts.io.ParseException in project UVMS-ActivityModule-APP by UnionVMS.

the class FluxMessageServiceBean method interpolatePointFromMovements.

private Geometry interpolatePointFromMovements(List<MovementType> movements, Date activityDate) throws ServiceException {
    if (movements == null || movements.isEmpty()) {
        return null;
    }
    Geometry faReportGeom;
    Collections.sort(movements, new MovementTypeComparator());
    Map<String, MovementType> movementTypeMap = getPreviousAndNextMovement(movements, activityDate);
    MovementType nextMovement = movementTypeMap.get(NEXT);
    MovementType previousMovement = movementTypeMap.get(PREVIOUS);
    try {
        if (previousMovement == null && nextMovement == null) {
            // If nothing found return null
            faReportGeom = null;
        } else if (nextMovement == null) {
            // if no next movement then the last previous movement is the position
            faReportGeom = GeometryMapper.INSTANCE.wktToGeometry(previousMovement.getWkt()).getValue();
            faReportGeom.setSRID(dialect.defaultSRID());
        } else if (previousMovement == null) {
            // if no previous movement then the first next movement is the position
            faReportGeom = GeometryMapper.INSTANCE.wktToGeometry(nextMovement.getWkt()).getValue();
            faReportGeom.setSRID(dialect.defaultSRID());
        } else {
            // ideal scenario, find the intersecting position
            faReportGeom = calculateIntermediatePoint(previousMovement, nextMovement, activityDate);
        }
    } catch (ParseException e) {
        throw new ServiceException(e.getMessage(), e);
    }
    return faReportGeom;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) MovementTypeComparator(eu.europa.ec.fisheries.ers.fa.utils.MovementTypeComparator) ParseException(com.vividsolutions.jts.io.ParseException) MovementType(eu.europa.ec.fisheries.schema.movement.v1.MovementType)

Example 62 with ParseException

use of com.vividsolutions.jts.io.ParseException in project UVMS-ActivityModule-APP by UnionVMS.

the class FluxMessageServiceBean method calculateIntermediatePoint.

private Geometry calculateIntermediatePoint(MovementType previousMovement, MovementType nextMovement, Date acceptedDate) throws ServiceException {
    // starting point = A, end point = B, calculated point = C
    Geometry point;
    Long durationAB = nextMovement.getPositionTime().getTime() - previousMovement.getPositionTime().getTime();
    Long durationAC = acceptedDate.getTime() - previousMovement.getPositionTime().getTime();
    Long durationBC = nextMovement.getPositionTime().getTime() - acceptedDate.getTime();
    try {
        if (durationAC == 0) {
            log.info("The point is same as the start point");
            point = GeometryMapper.INSTANCE.wktToGeometry(previousMovement.getWkt()).getValue();
        } else if (durationBC == 0) {
            log.info("The point is the same as end point");
            point = GeometryMapper.INSTANCE.wktToGeometry(nextMovement.getWkt()).getValue();
        } else {
            log.info("The point is between start and end point");
            LengthIndexedLine lengthIndexedLine = GeometryUtils.createLengthIndexedLine(previousMovement.getWkt(), nextMovement.getWkt());
            // Calculate the index to find the intersecting point
            Double index = durationAC * (lengthIndexedLine.getEndIndex() - lengthIndexedLine.getStartIndex()) / durationAB;
            point = GeometryUtils.calculateIntersectingPoint(lengthIndexedLine, index);
        }
    } catch (ParseException e) {
        throw new ServiceException(e.getMessage(), e);
    }
    point.setSRID(dialect.defaultSRID());
    return point;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) LengthIndexedLine(com.vividsolutions.jts.linearref.LengthIndexedLine) ParseException(com.vividsolutions.jts.io.ParseException)

Example 63 with ParseException

use of com.vividsolutions.jts.io.ParseException in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityServiceBean method getRestrictedAreaGeometry.

private Geometry getRestrictedAreaGeometry(List<Dataset> datasets) throws ServiceException {
    if (datasets == null || datasets.isEmpty()) {
        return null;
    }
    try {
        List<AreaIdentifierType> areaIdentifierTypes = UsmUtils.convertDataSetToAreaId(datasets);
        String areaWkt = spatialModule.getFilteredAreaGeom(areaIdentifierTypes);
        Geometry geometry = GeometryMapper.INSTANCE.wktToGeometry(areaWkt).getValue();
        geometry.setSRID(GeometryUtils.DEFAULT_EPSG_SRID);
        return geometry;
    } catch (ParseException e) {
        throw new ServiceException(e.getMessage(), e);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) ParseException(com.vividsolutions.jts.io.ParseException) AreaIdentifierType(eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType)

Example 64 with ParseException

use of com.vividsolutions.jts.io.ParseException in project activityinfo by bedatadriven.

the class WkbGeometryProvider method getGeometries.

@Override
@LogSlow(threshold = 200)
public List<AdminGeo> getGeometries(int adminLevelId) {
    try {
        List<AdminGeo> list = Lists.newArrayList();
        DataInputStream in = new DataInputStream(storage.openWkb(adminLevelId));
        WKBReader wkbReader = new WKBReader(geometryFactory);
        int count = in.readInt();
        for (int i = 0; i != count; ++i) {
            int id = in.readInt();
            LOGGER.info("Reading geometry for admin entity " + id);
            Geometry geometry = wkbReader.read(new DataInputInStream(in));
            list.add(new AdminGeo(id, geometry));
        }
        return list;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) IOException(java.io.IOException) ParseException(com.vividsolutions.jts.io.ParseException) DataInputStream(java.io.DataInputStream) WKBReader(com.vividsolutions.jts.io.WKBReader) LogSlow(org.activityinfo.server.util.logging.LogSlow)

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