use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class IDMDistanceFunctionTest method testLatlong.
// @Test
public void testLatlong() throws InvalidExpressionException {
String expr = ExpressionFactory.IDM_PREFIX + ":latlong(vehicle_location)";
EntityBuilder.addValue(cluster, "vehicle_location", new Coordinate(-721008.49d, 14741405.45d, "EPSG:21035"));
Object object = evaluateExpression(expr);
Assert.assertEquals(new Coordinate(12.302697080672786d, 41.87118824208946d, "EPSG:4326"), object);
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class DataMarshallerTest method createTestRecord.
private CollectRecord createTestRecord(CollectSurvey survey) throws RecordPersistenceException {
RecordBuilder recordBuilder = record(attribute("id", "123_456"), attribute("gps_realtime", "true"), attribute("region", "001"), attribute("district", "XXX"), attribute("crew_no", 10), attribute("map_sheet", "value 1"), attribute("map_sheet", "value 2"), attribute("vehicle_location", new Coordinate(432423423d, 4324324d, "srs")), attribute("gps_model", "TomTom 1.232"), attribute("remarks", "Remarks with UTF-8 character: Í"), entity("time_study", attribute("date", new Date(2011, 2, 14)), attribute("start_time", new Time(8, 15)), attribute("end_time", new Time(15, 29))), entity("time_study", attribute("date", new Date(2011, 2, 15)), attribute("start_time", new Time(8, 32)), attribute("end_time", new Time(11, 20))), entity("plot", attribute("no", new Code("1")), entity("tree", attribute("tree_no", 1), attribute("dbh", 54.2), attribute("total_height", 2.0), attribute("bole_height", (Double) null)), entity("tree", attribute("tree_no", 2), attribute("dbh", 82.8), attribute("total_height", 3.0))), entity("plot", attribute("no", new Code("2")), entity("tree", attribute("tree_no", 1), attribute("dbh", 34.2), attribute("total_height", 2.0)), entity("tree", attribute("tree_no", 2), attribute("dbh", 85.8), attribute("total_height", 4.0))));
CollectRecord record = recordBuilder.build(survey, "cluster", "2.0");
record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
record.setStep(Step.ENTRY);
record.updateSummaryFields();
RecordUpdater recordUpdater = new RecordUpdater();
recordUpdater.initializeRecord(record);
Entity cluster = record.getRootEntity();
recordUpdater.confirmError((Attribute<?, ?>) record.findNodeByPath("/cluster/district"));
recordUpdater.approveMissingValue(cluster, "accessibility");
NumberAttribute<?, ?> boleHeight = (NumberAttribute<?, ?>) record.findNodeByPath("/cluster/plot[1]/tree[1]/bole_height");
recordUpdater.updateAttribute(boleHeight, FieldSymbol.BLANK_ON_FORM);
recordUpdater.updateRemarks(boleHeight.getNumberField(), "No value specified");
return record;
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class GeoFunctions method coordinatesToString.
private String coordinatesToString(Collection<Coordinate> coordinates, CoordinateOperations coordinateOperations) {
StringBuilder coordinatesSb = new StringBuilder();
for (Coordinate coordinate : coordinates) {
if (coordinate.isComplete()) {
Coordinate latLonCoord = coordinateOperations.convertToWgs84(coordinate);
coordinatesSb.append(latLonCoord.getX());
coordinatesSb.append(',');
coordinatesSb.append(latLonCoord.getY());
coordinatesSb.append('\n');
}
}
return coordinatesSb.toString();
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class SamplingPointDataGenerator method calculateAoiWidth.
private double calculateAoiWidth(int levelIdx) {
switch(levelIdx) {
case 0:
List<Coordinate> aoiBoundary = configuration.getAoiBoundary();
List<Coordinate> reprojectedAoiBoundary = reprojectToWebMercator(aoiBoundary);
double[] longitudes = new double[reprojectedAoiBoundary.size()];
for (int i = 0; i < reprojectedAoiBoundary.size(); i++) {
Coordinate c = reprojectedAoiBoundary.get(i);
longitudes[i] = c.getX();
}
double minBoundaryLongitude = NumberUtils.min(longitudes);
double maxBoundaryLongitude = NumberUtils.max(longitudes);
return maxBoundaryLongitude - minBoundaryLongitude;
default:
SamplingPointLevelGenerationSettings previousLevelConfiguration = configuration.getLevelsSettings().get(levelIdx - 1);
return previousLevelConfiguration.getPointWidth();
}
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class SamplingPointDataGenerator method generateLocationsInSquare.
private List<Coordinate> generateLocationsInSquare(Coordinate webMercatorAoiCenter, List<Coordinate> aoiBoundary, SamplingPointLevelGenerationSettings c) {
List<Coordinate> result = new ArrayList<Coordinate>();
List<Coordinate> reprojectedAoiBoundary = reprojectToWebMercator(aoiBoundary);
double[] latitudes = new double[reprojectedAoiBoundary.size()];
double[] longitudes = new double[reprojectedAoiBoundary.size()];
for (int i = 0; i < reprojectedAoiBoundary.size(); i++) {
Coordinate coord = reprojectedAoiBoundary.get(i);
latitudes[i] = coord.getY();
longitudes[i] = coord.getX();
}
double pointRadius = c.getPointWidth() / 2;
double minBoundaryLatitude = NumberUtils.min(latitudes) + pointRadius;
double maxBoundaryLatitude = NumberUtils.max(latitudes) - pointRadius;
double minBoundaryLongitude = NumberUtils.min(longitudes) + pointRadius;
double maxBoundaryLongitude = NumberUtils.max(longitudes) - pointRadius;
switch(c.getDistribution()) {
case RANDOM:
for (int i = 0; i < c.getNumPoints(); i++) {
double x = minBoundaryLongitude + (maxBoundaryLongitude - minBoundaryLongitude) * Math.random();
double y = minBoundaryLatitude + (maxBoundaryLatitude - minBoundaryLatitude) * Math.random();
result.add(new Coordinate(x, y, webMercatorAoiCenter.getSrsId()));
}
break;
case GRIDDED:
for (double lat = maxBoundaryLatitude; lat >= minBoundaryLatitude; lat -= c.getResolution()) {
for (double lon = minBoundaryLongitude; lon <= maxBoundaryLongitude; lon += c.getResolution()) {
result.add(new Coordinate(lon, lat, webMercatorAoiCenter.getSrsId()));
}
}
break;
case CSV:
// do nothing
break;
}
return result;
}
Aggregations