Search in sources :

Example 1 with SamplingDesignItem

use of org.openforis.collect.model.SamplingDesignItem in project collect by openforis.

the class SamplingDesignDao method insert.

/**
 * Inserts the items in batch.
 *
 * @param taxa
 */
public void insert(List<SamplingDesignItem> items) {
    if (items != null && !items.isEmpty()) {
        SamplingDesignDSLContext dsl = dsl();
        int id = dsl.nextId(OFC_SAMPLING_DESIGN.ID, OFC_SAMPLING_DESIGN_ID_SEQ);
        int maxId = id;
        Insert<OfcSamplingDesignRecord> query = dsl.createInsertStatement();
        BatchBindStep batch = dsl.batch(query);
        for (SamplingDesignItem item : items) {
            if (item.getId() == null) {
                item.setId(id++);
            }
            Object[] values = dsl.extractValues(item);
            batch.bind(values);
            maxId = Math.max(maxId, item.getId());
        }
        batch.execute();
        dsl.restartSequence(OFC_SAMPLING_DESIGN_ID_SEQ, maxId + 1);
    }
}
Also used : BatchBindStep(org.jooq.BatchBindStep) OfcSamplingDesignRecord(org.openforis.collect.persistence.jooq.tables.records.OfcSamplingDesignRecord) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 2 with SamplingDesignItem

use of org.openforis.collect.model.SamplingDesignItem 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 3 with SamplingDesignItem

use of org.openforis.collect.model.SamplingDesignItem in project collect by openforis.

the class SamplingPointsController method loadSamplingDesignItems.

private List<SamplingDesignItem> loadSamplingDesignItems(CollectSurvey survey) {
    SamplingDesignSummaries samplingDesignSummaries = samplingDesignManager.loadBySurvey(survey.getId());
    List<SamplingDesignItem> samplingDesignItems = samplingDesignSummaries.getRecords();
    List<SamplingDesignItem> result = new ArrayList<SamplingDesignItem>();
    for (SamplingDesignItem item : samplingDesignItems) {
        result.add(item);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 4 with SamplingDesignItem

use of org.openforis.collect.model.SamplingDesignItem 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 SamplingDesignItem

use of org.openforis.collect.model.SamplingDesignItem 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

SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)26 ArrayList (java.util.ArrayList)9 SamplingDesignSummaries (org.openforis.collect.model.SamplingDesignSummaries)8 Coordinate (org.openforis.idm.model.Coordinate)7 CollectSurvey (org.openforis.collect.model.CollectSurvey)6 Test (org.junit.Test)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 SamplingPointDataGenerator (org.openforis.collect.io.metadata.samplingpointdata.SamplingPointDataGenerator)3 SamplingPointGenerationSettings (org.openforis.collect.metamodel.samplingdesign.SamplingPointGenerationSettings)3 SamplingDesignImportProcess (org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportProcess)2 SamplingDesignImportStatus (org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus)2 SamplingPointLevelGenerationSettings (org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings)2 OfcSamplingDesignRecord (org.openforis.collect.persistence.jooq.tables.records.OfcSamplingDesignRecord)2 CsvWriter (org.openforis.commons.io.csv.CsvWriter)2 CoordinateOperations (org.openforis.idm.geospatial.CoordinateOperations)2 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 ReferenceDataSchema (org.openforis.idm.metamodel.ReferenceDataSchema)2 SamplingPointDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.SamplingPointDefinition)2 Document (de.micromata.opengis.kml.v_2_2_0.Document)1 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)1