Search in sources :

Example 1 with MovementTypeComparator

use of eu.europa.ec.fisheries.ers.fa.utils.MovementTypeComparator 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) {
            faReportGeom = null;
        } else if (nextMovement == null) {
            faReportGeom = GeometryMapper.INSTANCE.wktToGeometry(previousMovement.getWkt()).getValue();
            faReportGeom.setSRID(dialect.defaultSRID());
        } else if (previousMovement == null) {
            faReportGeom = GeometryMapper.INSTANCE.wktToGeometry(nextMovement.getWkt()).getValue();
            faReportGeom.setSRID(dialect.defaultSRID());
        } else {
            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)

Aggregations

Geometry (com.vividsolutions.jts.geom.Geometry)1 ParseException (com.vividsolutions.jts.io.ParseException)1 MovementTypeComparator (eu.europa.ec.fisheries.ers.fa.utils.MovementTypeComparator)1 MovementType (eu.europa.ec.fisheries.schema.movement.v1.MovementType)1 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)1