Search in sources :

Example 41 with Coordinate

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;
    }
}
Also used : Survey(org.openforis.idm.metamodel.Survey) Coordinate(org.openforis.idm.model.Coordinate) LookupProvider(org.openforis.idm.metamodel.validation.LookupProvider)

Example 42 with Coordinate

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;
    }
}
Also used : Survey(org.openforis.idm.metamodel.Survey) Coordinate(org.openforis.idm.model.Coordinate) SurveyObject(org.openforis.idm.metamodel.SurveyObject) LookupProvider(org.openforis.idm.metamodel.validation.LookupProvider)

Example 43 with Coordinate

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);
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) AbstractExpressionTest(org.openforis.idm.model.expression.AbstractExpressionTest) Test(org.junit.Test)

Example 44 with Coordinate

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);
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) ArrayList(java.util.ArrayList)

Example 45 with Coordinate

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;
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) ArrayList(java.util.ArrayList)

Aggregations

Coordinate (org.openforis.idm.model.Coordinate)46 Code (org.openforis.idm.model.Code)14 Test (org.junit.Test)8 Date (org.openforis.idm.model.Date)8 Time (org.openforis.idm.model.Time)8 ArrayList (java.util.ArrayList)7 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)7 CoordinateAttribute (org.openforis.idm.model.CoordinateAttribute)7 Entity (org.openforis.idm.model.Entity)7 CollectRecord (org.openforis.collect.model.CollectRecord)5 GregorianCalendar (java.util.GregorianCalendar)4 SamplingPointLevelGenerationSettings (org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings)4 CollectSurvey (org.openforis.collect.model.CollectSurvey)4 CoordinateOperations (org.openforis.idm.geospatial.CoordinateOperations)4 RealAttribute (org.openforis.idm.model.RealAttribute)4 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)3 ValidationResults (org.openforis.idm.metamodel.validation.ValidationResults)3 NumberAttribute (org.openforis.idm.model.NumberAttribute)3 RecordBuilder (org.openforis.idm.testfixture.RecordBuilder)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2