Search in sources :

Example 6 with CoordinateOperations

use of org.openforis.idm.geospatial.CoordinateOperations in project collect by openforis.

the class DistanceCheck method evaluate.

@Override
public ValidationResultFlag evaluate(CoordinateAttribute coordinateAttr) {
    CoordinateOperations coordinateOperations = getCoordinateOperations(coordinateAttr);
    if (coordinateOperations == null) {
        return ValidationResultFlag.OK;
    }
    try {
        ExpressionEvaluator expressionEvaluator = getExpressionEvaluator(coordinateAttr);
        boolean valid = expressionEvaluator.evaluateBoolean(coordinateAttr.getParent(), coordinateAttr, getExpression());
        return ValidationResultFlag.valueOf(valid, this.getFlag());
    } catch (InvalidExpressionException e) {
        if (LOG.isInfoEnabled()) {
            LOG.info("Unable to evaluate distance check ", e);
        }
        return ValidationResultFlag.OK;
    }
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator)

Example 7 with CoordinateOperations

use of org.openforis.idm.geospatial.CoordinateOperations in project collect by openforis.

the class GeoDataController method createCoordinateValuesKML.

@RequestMapping(value = "survey/{surveyId}/data/coordinatesvalues.kml", method = GET, produces = KML_CONTENT_TYPE)
public void createCoordinateValuesKML(@PathVariable("surveyId") int surveyId, @RequestParam int stepNum, @RequestParam int coordinateAttributeId, HttpServletResponse response) throws Exception {
    CollectSurvey survey = surveyManager.getById(surveyId);
    CoordinateAttributeDefinition nodeDef = (CoordinateAttributeDefinition) survey.getSchema().getDefinitionById(coordinateAttributeId);
    RecordCoordinatesKmlGeneratorJob job = new RecordCoordinatesKmlGeneratorJob();
    job.setRecordManager(recordManager);
    RecordFilter filter = new RecordFilter(survey);
    job.setRecordFilter(filter);
    job.setNodeDefinition(nodeDef);
    job.setOutput(response.getOutputStream());
    CoordinateOperations coordinateOperations = survey.getContext().getCoordinateOperations();
    coordinateOperations.registerSRS(survey.getSpatialReferenceSystems());
    job.setCoordinateOperations(coordinateOperations);
    jobManager.start(job, false);
}
Also used : CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordCoordinatesKmlGeneratorJob(org.openforis.collect.model.RecordCoordinatesKmlGeneratorJob) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with CoordinateOperations

use of org.openforis.idm.geospatial.CoordinateOperations 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;
        }
    }
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) Coordinate(org.openforis.idm.model.Coordinate) CoordinateOperationException(org.openforis.idm.geospatial.CoordinateOperationException)

Example 9 with CoordinateOperations

use of org.openforis.idm.geospatial.CoordinateOperations in project collect by openforis.

the class GeoFunctions method latLong.

protected static Coordinate latLong(ExpressionContext expressionContext, Coordinate coordinate) {
    if (coordinate == null || !coordinate.isComplete()) {
        return null;
    }
    Survey survey = getSurvey(expressionContext);
    CoordinateOperations coordinateOperations = survey.getContext().getCoordinateOperations();
    if (coordinateOperations == null) {
        return null;
    } else {
        return coordinateOperations.convertToWgs84(coordinate);
    }
}
Also used : Survey(org.openforis.idm.metamodel.Survey) CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations)

Aggregations

CoordinateOperations (org.openforis.idm.geospatial.CoordinateOperations)9 Coordinate (org.openforis.idm.model.Coordinate)4 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 CollectSurveyContext (org.openforis.collect.model.CollectSurveyContext)2 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 FileNotFoundException (java.io.FileNotFoundException)1 Feature (org.geojson.Feature)1 FeatureCollection (org.geojson.FeatureCollection)1 LngLatAlt (org.geojson.LngLatAlt)1 MultiPoint (org.geojson.MultiPoint)1 LngLat (org.openforis.collect.model.LngLat)1 RecordCoordinatesKmlGeneratorJob (org.openforis.collect.model.RecordCoordinatesKmlGeneratorJob)1 RecordFilter (org.openforis.collect.model.RecordFilter)1 SamplingDesignSummaries (org.openforis.collect.model.SamplingDesignSummaries)1 CoordinateOperationException (org.openforis.idm.geospatial.CoordinateOperationException)1 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)1 Survey (org.openforis.idm.metamodel.Survey)1 SurveyContext (org.openforis.idm.metamodel.SurveyContext)1 ExpressionEvaluator (org.openforis.idm.model.expression.ExpressionEvaluator)1