Search in sources :

Example 1 with Coordinate

use of org.openforis.idm.model.Coordinate in project collect by openforis.

the class RecordDaoTest method createRecord.

private CollectRecord createRecord(CollectSurvey survey, int sequenceNumber) {
    int skippedCount = new Double(Math.ceil((double) (Math.random() * 40))).intValue();
    int missingCount = new Double(Math.ceil((double) (Math.random() * 50))).intValue();
    int errorsCount = new Double(Math.ceil((double) (Math.random() * 10))).intValue();
    int warningsCount = new Double(Math.ceil((double) (Math.random() * 30))).intValue();
    int numberOfPlots = new Double(Math.ceil((double) (Math.random() * 20))).intValue();
    int numberOfTrees = new Double(Math.ceil((double) (Math.random() * 30))).intValue();
    ;
    CollectRecord record = new CollectRecord(recordManager, survey, "2.0");
    record.setCreationDate(new GregorianCalendar(2011, 0, sequenceNumber, 8, 30).getTime());
    // record.setCreatedBy("ModelDaoIntegrationTest");
    record.setStep(Step.ENTRY);
    record.setModifiedDate(new GregorianCalendar(2011, 1, sequenceNumber, 8, 30).getTime());
    record.setSkipped(skippedCount);
    record.setMissing(missingCount);
    record.setErrors(errorsCount);
    record.setWarnings(warningsCount);
    Entity cluster = record.createRootEntity("cluster");
    String keyId = Integer.toString(sequenceNumber);
    EntityBuilder.addValue(cluster, "id", new Code(keyId));
    EntityBuilder.addValue(cluster, "gps_realtime", Boolean.TRUE);
    EntityBuilder.addValue(cluster, "region", new Code("001"));
    EntityBuilder.addValue(cluster, "district", new Code("002"));
    EntityBuilder.addValue(cluster, "vehicle_location", new Coordinate(432423423l, 4324324l, "srs"));
    EntityBuilder.addValue(cluster, "gps_model", "TomTom 1.232");
    {
        Entity ts = EntityBuilder.addEntity(cluster, "time_study");
        ts.addValue("date", new Date(2011, 2, 14));
        ts.addValue("start_time", new Time(8, 15));
        ts.addValue("end_time", new Time(15, 29));
    }
    {
        Entity ts = EntityBuilder.addEntity(cluster, "time_study");
        ts.addValue("date", new Date(2011, 2, 15));
        ts.addValue("start_time", new Time(8, 32));
        ts.addValue("end_time", new Time(11, 20));
    }
    for (int i = 0; i < numberOfPlots; i++) {
        Entity plot = EntityBuilder.addEntity(cluster, "plot");
        EntityBuilder.addValue(plot, "no", new Code(Integer.toString(i + 1)));
        for (int j = 0; j < numberOfTrees; j++) {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            tree.addValue("dbh", 54.2);
            tree.addValue("total_height", 2.0);
            RealAttribute boleHeight = tree.addValue("bole_height", (Double) null);
            boleHeight.getField().setSymbol('*');
            boleHeight.getField().setRemarks("No value specified");
        // .setMetadata(new CollectAttributeMetadata('*',null,"No value specified"));
        }
    }
    // set counts
    record.getEntityCounts().add(numberOfPlots);
    // set keys
    record.getRootEntityKeys().add(keyId);
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) Coordinate(org.openforis.idm.model.Coordinate) RealAttribute(org.openforis.idm.model.RealAttribute) GregorianCalendar(java.util.GregorianCalendar) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date)

Example 2 with Coordinate

use of org.openforis.idm.model.Coordinate in project collect by openforis.

the class CoordinateAttributeMapper method addNode.

@Override
Node<?> addNode(NodeDefinition defn, Record r, Entity parent) {
    Long x = r.getValueAsLong(DATA.NUMBER1);
    Long y = r.getValueAsLong(DATA.NUMBER2);
    // Long z = r.getValueAsLong(DATA.NUMBER3);
    String srsId = r.getValueAsString(DATA.TEXT1);
    Coordinate c = new Coordinate(x, y, srsId);
    return parent.addValue(defn.getName(), c);
}
Also used : Coordinate(org.openforis.idm.model.Coordinate)

Example 3 with Coordinate

use of org.openforis.idm.model.Coordinate in project collect by openforis.

the class SamplingPointsController method loadSamplingPointDataFeatures.

private FeatureCollection loadSamplingPointDataFeatures(CollectSurvey survey) {
    FeatureCollection featureCollection = new FeatureCollection();
    Feature feature = new Feature();
    feature.setProperty("letter", "o");
    feature.setProperty("color", "blue");
    feature.setProperty("rank", "15");
    MultiPoint multiPoint = new MultiPoint();
    CoordinateOperations coordinateOperations = getCoordinateOperations(survey);
    List<SamplingDesignItem> samplingDesignItems = loadSamplingDesignItems(survey);
    for (SamplingDesignItem item : samplingDesignItems) {
        Coordinate coordinate = new Coordinate(item.getX(), item.getY(), item.getSrsId());
        multiPoint.add(createLngLatAlt(coordinateOperations, coordinate));
    }
    feature.setGeometry(multiPoint);
    featureCollection.add(feature);
    return featureCollection;
}
Also used : MultiPoint(org.geojson.MultiPoint) CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) FeatureCollection(org.geojson.FeatureCollection) Coordinate(org.openforis.idm.model.Coordinate) Feature(org.geojson.Feature) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 4 with Coordinate

use of org.openforis.idm.model.Coordinate in project collect by openforis.

the class SamplingPointsController method loadSamplingPointBounds.

@RequestMapping(value = "survey/{surveyId}/sampling_point_bounds.json", method = GET)
@ResponseBody
public Bounds loadSamplingPointBounds(@PathVariable int surveyId) {
    CollectSurvey survey = surveyManager.loadSurvey(surveyId);
    CollectSurveyContext surveyContext = survey.getContext();
    CoordinateOperations coordinateOperations = surveyContext.getCoordinateOperations();
    SamplingDesignSummaries samplingDesignSummaries = samplingDesignManager.loadBySurvey(survey.getId());
    List<SamplingDesignItem> samplingDesignItems = samplingDesignSummaries.getRecords();
    Bounds bounds = new Bounds();
    for (SamplingDesignItem item : samplingDesignItems) {
        Coordinate coordinate = new Coordinate(item.getX(), item.getY(), item.getSrsId());
        LngLatAlt lngLatAlt = createLngLatAlt(coordinateOperations, coordinate);
        if (lngLatAlt != null) {
            if (bounds.topLeft == null) {
                bounds.topLeft = bounds.topRight = bounds.bottomLeft = bounds.bottomRight = lngLatAlt;
            } else {
                if (lngLatAlt.getLatitude() < bounds.topLeft.getLatitude() && lngLatAlt.getLongitude() < bounds.topLeft.getLongitude()) {
                    bounds.topLeft = lngLatAlt;
                } else if (lngLatAlt.getLatitude() < bounds.topRight.getLatitude() && lngLatAlt.getLongitude() > bounds.topRight.getLongitude()) {
                    bounds.topRight = lngLatAlt;
                } else if (lngLatAlt.getLatitude() > bounds.bottomRight.getLatitude() && lngLatAlt.getLongitude() > bounds.bottomRight.getLongitude()) {
                    bounds.bottomRight = lngLatAlt;
                } else if (lngLatAlt.getLatitude() > bounds.bottomLeft.getLatitude() && lngLatAlt.getLongitude() > bounds.bottomLeft.getLongitude()) {
                    bounds.bottomLeft = lngLatAlt;
                }
            }
        }
    }
    return bounds;
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) Coordinate(org.openforis.idm.model.Coordinate) CollectSurveyContext(org.openforis.collect.model.CollectSurveyContext) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) CollectSurvey(org.openforis.collect.model.CollectSurvey) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) LngLatAlt(org.geojson.LngLatAlt) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with Coordinate

use of org.openforis.idm.model.Coordinate in project collect by openforis.

the class SamplingPointDataGeneratorTest method griddedPlotsGenerationTest.

@Test
public void griddedPlotsGenerationTest() {
    Coordinate topLeftCoordinate = new Coordinate(12.369192d, 41.987927d, LAT_LON_SRS_ID);
    Coordinate topRightCoordinate = new Coordinate(12.621191d, 41.987927d, LAT_LON_SRS_ID);
    Coordinate bottomLeftCoordinate = new Coordinate(12.369192d, 41.802904d, LAT_LON_SRS_ID);
    Coordinate bottomRightCoordinate = new Coordinate(12.621191d, 41.802904d, LAT_LON_SRS_ID);
    int numPlots = 25;
    int samplesPerPlot = 10;
    int plotWidth = 1000;
    SamplingPointLevelGenerationSettings plotPointsConfig = new SamplingPointLevelGenerationSettings(numPlots, Shape.CIRCLE, Distribution.GRIDDED, 5000, plotWidth);
    SamplingPointLevelGenerationSettings samplePointsConfig = new SamplingPointLevelGenerationSettings(samplesPerPlot, Shape.CIRCLE, Distribution.RANDOM, 20, 10);
    CollectSurvey survey = createTestSurvey();
    SamplingPointGenerationSettings conf = new SamplingPointGenerationSettings();
    conf.setAoiBoundary(Arrays.asList(topLeftCoordinate, topRightCoordinate, bottomLeftCoordinate, bottomRightCoordinate));
    conf.setLevelsSettings(Arrays.asList(plotPointsConfig, samplePointsConfig));
    SamplingPointDataGenerator generator = new SamplingPointDataGenerator(coordinateOperations, survey, null, conf);
    List<SamplingDesignItem> items = generator.generate();
    // printLatLonPoints(items);
    assertTrue(items.size() <= numPlots + numPlots * samplesPerPlot);
    List<SamplingDesignItem> plotItems = getSamplingItemsInLevel(items, 1);
    assertTrue(plotItems.size() <= numPlots);
    for (SamplingDesignItem plotItem : plotItems) {
        assertPointInSquare(plotItem, topLeftCoordinate, bottomRightCoordinate);
    }
}
Also used : SamplingPointGenerationSettings(org.openforis.collect.metamodel.samplingdesign.SamplingPointGenerationSettings) Coordinate(org.openforis.idm.model.Coordinate) SamplingPointDataGenerator(org.openforis.collect.io.metadata.samplingpointdata.SamplingPointDataGenerator) CollectSurvey(org.openforis.collect.model.CollectSurvey) SamplingPointLevelGenerationSettings(org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) Test(org.junit.Test)

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