Search in sources :

Example 36 with Coordinate

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);
    }
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 37 with Coordinate

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()));
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Coordinate(org.openforis.idm.model.Coordinate) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 38 with Coordinate

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Coordinate(org.openforis.idm.model.Coordinate) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) ArrayList(java.util.ArrayList) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 39 with Coordinate

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

Example 40 with Coordinate

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

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