Search in sources :

Example 16 with Coordinate

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

Example 17 with Coordinate

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) Coordinate(org.openforis.idm.model.Coordinate) RecordBuilder(org.openforis.idm.testfixture.RecordBuilder) GregorianCalendar(java.util.GregorianCalendar) NumberAttribute(org.openforis.idm.model.NumberAttribute) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) RecordUpdater(org.openforis.collect.model.RecordUpdater) Date(org.openforis.idm.model.Date)

Example 18 with Coordinate

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

Example 19 with Coordinate

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();
    }
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) SamplingPointLevelGenerationSettings(org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings)

Example 20 with Coordinate

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;
}
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