use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class SamplingPointsController method convertTo.
private SamplingDesignItem convertTo(SamplingDesignItem item, String targetSrsId) {
try {
SamplingDesignItem newItem = new SamplingDesignItem();
BeanUtils.copyProperties(newItem, item);
Coordinate newCoordinate = coordinateOperations.convertTo(item.getCoordinate(), targetSrsId);
newItem.setCoordinate(newCoordinate);
return newItem;
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class DistanceCheckTest method testValidMaxDistance.
@Test
public void testValidMaxDistance() {
String coordStr = "SRID=EPSG:21035;POINT(805750 9333820)";
Coordinate coord = Coordinate.parseCoordinate(coordStr);
EntityBuilder.addValue(cluster, "id", new Code("001"));
CoordinateAttribute vehicleLocation = EntityBuilder.addValue(cluster, "vehicle_location", coord);
ValidationResults results = validate(vehicleLocation);
Assert.assertFalse(containsDistanceCheck(results.getErrors()));
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class GeoDataController method loadCoordinateValues.
@RequestMapping(value = "survey/{surveyId}/data/coordinatevalues.json", method = GET)
@ResponseBody
public List<CoordinateAttributePoint> loadCoordinateValues(@PathVariable int surveyId, @RequestParam int coordinateAttributeId, @RequestParam String srsId, @RequestParam int recordOffset, @RequestParam int maxNumberOfRecords) throws Exception {
final List<CoordinateAttributePoint> result = new ArrayList<CoordinateAttributePoint>();
CollectSurvey survey = surveyManager.loadSurvey(surveyId);
extractAllRecordCoordinates(survey, recordOffset, maxNumberOfRecords, coordinateAttributeId, srsId, new CoordinateProcessor() {
public void process(CollectRecord record, CoordinateAttribute coordAttr, Coordinate coordinate) {
CoordinateAttributePoint point = new CoordinateAttributePoint(coordAttr, coordinate);
result.add(point);
}
});
return result;
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class GeoFunctions method distance.
/**
* Calculates the orthodromic distance between 2 coordinates (in meters)
*/
protected static Double distance(ExpressionContext context, Object from, Object to) {
if (from == null || to == null) {
return null;
}
Coordinate fromC = from instanceof Coordinate ? (Coordinate) from : Coordinate.parseCoordinate(from);
if (fromC == null || !fromC.isComplete()) {
return null;
}
Coordinate toC = to instanceof Coordinate ? (Coordinate) to : Coordinate.parseCoordinate(to);
if (toC == null || !toC.isComplete()) {
return null;
}
CoordinateOperations coordinateOperations = getSurvey(context).getContext().getCoordinateOperations();
if (coordinateOperations == null) {
return null;
} else {
try {
double distance = coordinateOperations.orthodromicDistance(fromC, toC);
return distance;
} catch (CoordinateOperationException e) {
return null;
}
}
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class GeoFunctions method toListOfCoordinates.
private Collection<Coordinate> toListOfCoordinates(Object obj) {
if (obj instanceof Collection) {
@SuppressWarnings("unchecked") Collection<Object> list = (Collection<Object>) obj;
Collection<Coordinate> coordinates = new ArrayList<Coordinate>(list.size());
for (Object c : list) {
if (c instanceof Coordinate) {
coordinates.add((Coordinate) c);
} else {
Coordinate coord = Coordinate.parseCoordinate(c);
if (coord != null) {
coordinates.add(coord);
}
}
}
return coordinates;
} else if (obj instanceof Coordinate) {
return Arrays.asList((Coordinate) obj);
} else {
Coordinate coord = Coordinate.parseCoordinate(obj);
if (coord == null) {
return Collections.emptyList();
} else {
return Arrays.asList(coord);
}
}
}
Aggregations