use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class IDMFunctions method samplingPointCoordinateLookup.
private static Coordinate samplingPointCoordinateLookup(ExpressionContext context, String... keys) {
if (validateSamplingPointKeys(keys)) {
LookupProvider lookupProvider = getLookupProvider(context);
Survey survey = getSurvey(context);
Coordinate coordinate = lookupProvider.lookupSamplingPointCoordinate(survey, keys);
return coordinate;
} else {
return null;
}
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class IDMFunctions method lookup.
private static Object lookup(ExpressionContext context, String name, String attribute, String... keys) {
LookupProvider lookupProvider = getLookupProvider(context);
Survey survey = getSurvey(context);
Object result = lookupProvider.lookup(survey, name, attribute, (Object[]) keys);
if (result == null) {
return null;
} else if (LOCATION_ATTRIBUTE.equalsIgnoreCase(attribute)) {
// convert to Coordinate
Coordinate coordinate = Coordinate.parseCoordinate(result.toString());
return coordinate;
} else {
return result;
}
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class IDMDistanceFunctionTest method testSameLocation.
@Test
public void testSameLocation() throws InvalidExpressionException {
String expr = ExpressionFactory.IDM_PREFIX + ":distance(vehicle_location, vehicle_location)";
EntityBuilder.addValue(cluster, "vehicle_location", new Coordinate(592340d, 9293450d, "EPSG:21036"));
Object distance = evaluateExpression(expr);
Assert.assertEquals(Double.valueOf(0.0d), distance);
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class SamplingPointDataGenerator method generateSquareBoundary.
private List<Coordinate> generateSquareBoundary(Coordinate latLonCenter, double width) {
Coordinate webMercatorCenter = reprojectFromLatLonToWebMercator(latLonCenter);
List<Coordinate> latLonBoundary = new ArrayList<Coordinate>(4);
double halfWidth = width / 2;
latLonBoundary.add(new Coordinate(webMercatorCenter.getX() - halfWidth, webMercatorCenter.getY() + halfWidth, WEB_MERCATOR_SRS_ID));
latLonBoundary.add(new Coordinate(webMercatorCenter.getX() + halfWidth, webMercatorCenter.getY() + halfWidth, WEB_MERCATOR_SRS_ID));
latLonBoundary.add(new Coordinate(webMercatorCenter.getX() - halfWidth, webMercatorCenter.getY() - halfWidth, WEB_MERCATOR_SRS_ID));
latLonBoundary.add(new Coordinate(webMercatorCenter.getX() + halfWidth, webMercatorCenter.getY() - halfWidth, WEB_MERCATOR_SRS_ID));
return reprojectToWebMercator(latLonBoundary);
}
use of org.openforis.idm.model.Coordinate in project collect by openforis.
the class SamplingPointDataGenerator method generateLocationsInCircle.
private List<Coordinate> generateLocationsInCircle(Coordinate center, double circleRadius, SamplingPointLevelGenerationSettings c) {
List<Coordinate> result = new ArrayList<Coordinate>(c.getNumPoints());
double radiusSquared = circleRadius * circleRadius;
double locationRadius = c.getPointWidth() / 2;
switch(c.getDistribution()) {
case RANDOM:
for (int i = 0; i < c.getNumPoints(); i++) {
double offsetAngle = Math.random() * Math.PI * 2;
double offsetMagnitude = Math.random() * circleRadius;
double xOffset = offsetMagnitude * Math.cos(offsetAngle);
double yOffset = offsetMagnitude * Math.sin(offsetAngle);
double x = center.getX() + xOffset;
double y = center.getY() + yOffset;
result.add(new Coordinate(x, y, center.getSrsId()));
}
break;
case GRIDDED:
double left = center.getX() - circleRadius;
double top = center.getY() - circleRadius;
double numberOfSteps = Math.floor(2 * circleRadius / c.getResolution());
for (int xStep = 0; xStep < numberOfSteps; xStep++) {
double x = left + xStep * c.getResolution() + locationRadius;
for (int yStep = 0; yStep < numberOfSteps; yStep++) {
double y = top + yStep * c.getResolution() + locationRadius;
if (squareDistance(x, y, center.getX(), center.getY()) < radiusSquared) {
result.add(new Coordinate(x, y, center.getSrsId()));
}
}
}
break;
case CSV:
// do nothing
break;
}
return result;
}
Aggregations