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;
}
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;
}
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);
}
}
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);
}
}
Aggregations