Search in sources :

Example 6 with SamplingDesignItem

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

the class SamplingPointDataGeneratorTest method randomSamplingPointsGenerationTest.

@Test
public void randomSamplingPointsGenerationTest() {
    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();
    List<SamplingDesignItem> plotItems = getSamplingItemsInLevel(items, 1);
    List<SamplingDesignItem> samplingPointItems = getSamplingItemsInLevel(items, 2);
    assertEquals(plotItems.size() * samplesPerPlot, samplingPointItems.size());
    for (final SamplingDesignItem samplingPointItem : samplingPointItems) {
        SamplingDesignItem plotItem = (SamplingDesignItem) CollectionUtils.find(items, new Predicate() {

            public boolean evaluate(Object object) {
                return Arrays.asList(samplingPointItem.getLevelCode(1)).equals(((SamplingDesignItem) object).getLevelCodes());
            }
        });
        assertNotNull(plotItem);
        assertPointInCircle(samplingPointItem, new Coordinate(plotItem.getX(), plotItem.getY(), LAT_LON_SRS_ID), plotWidth / 2);
    }
}
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) Predicate(org.apache.commons.collections.Predicate) Test(org.junit.Test)

Example 7 with SamplingDesignItem

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

the class SamplingPointDataGeneratorTest method printLatLonPoints.

@SuppressWarnings("unused")
private void printLatLonPoints(List<SamplingDesignItem> items) {
    StringBuilder sb = new StringBuilder();
    for (SamplingDesignItem item : items) {
        // if (item.getLevel() == 1) {
        sb.append(item.getY());
        sb.append(',');
        sb.append(item.getX());
        sb.append('\n');
    // }
    }
    System.out.println(sb.toString());
}
Also used : SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 8 with SamplingDesignItem

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

the class SamplingDesignImportProcessIntegrationTest method testImport.

@Test
public void testImport() throws Exception {
    SamplingDesignImportProcess process = importCSVFile(VALID_TEST_CSV);
    SamplingDesignImportStatus status = process.getStatus();
    assertTrue(status.isComplete());
    assertTrue(status.getSkippedRows().isEmpty());
    assertEquals(27, status.getProcessed());
    SamplingDesignSummaries samplingDesignSummaries = samplingDesignManager.loadBySurvey(survey.getId(), 0, 30);
    assertNotNull(samplingDesignSummaries);
    assertEquals(26, samplingDesignSummaries.getTotalCount());
    List<SamplingDesignItem> items = samplingDesignSummaries.getRecords();
    assertNotNull(findItem(items, -10000d, 100000d, "1_01", "1"));
    assertNotNull(findItem(items, 200000d, -2000000d, "1_02", "1"));
    assertNotNull(findItem(items, 806090d, 9320050d, "10_114", "7"));
    assertNotNull(findItem(items, 805680d, 9305020d, "10_117", "6"));
}
Also used : SamplingDesignImportProcess(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportProcess) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) SamplingDesignImportStatus(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 9 with SamplingDesignItem

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

the class SurveyManagerIntegrationTest method duplicateSurveySamplingDesignForEditTest.

@Test
public void duplicateSurveySamplingDesignForEditTest() {
    insertTestSamplingDesign();
    CollectSurvey surveyWork = surveyManager.createTemporarySurveyFromPublished(survey.getUri(), adminUser);
    SamplingDesignSummaries summaries = samplingDesignManager.loadBySurvey(surveyWork.getId());
    List<SamplingDesignItem> records = summaries.getRecords();
    assertEquals(3, records.size());
    {
        SamplingDesignItem item = records.get(0);
        assertEquals(Arrays.asList("7_81"), item.getLevelCodes());
        assertEquals("EPSG:21035", item.getSrsId());
        assertEquals(Double.valueOf(792200d), item.getX());
        assertEquals(Double.valueOf(9484420d), item.getY());
    }
    {
        SamplingDesignItem item = records.get(1);
        assertEquals(Arrays.asList("7_81", "2"), item.getLevelCodes());
        assertEquals("EPSG:21035", item.getSrsId());
        assertEquals(Double.valueOf(792200d), item.getX());
        assertEquals(Double.valueOf(9484420d), item.getY());
    }
    {
        SamplingDesignItem item = records.get(2);
        assertEquals(Arrays.asList("7_81", "3"), item.getLevelCodes());
        assertEquals("EPSG:21035", item.getSrsId());
        assertEquals(Double.valueOf(792200d), item.getX());
        assertEquals(Double.valueOf(9484670d), item.getY());
    }
}
Also used : SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) CollectSurvey(org.openforis.collect.model.CollectSurvey) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 10 with SamplingDesignItem

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

the class SamplingPointDataGenerator method generateItems.

private List<SamplingDesignItem> generateItems(int levelIdx, List<String> previousLevelKeys, Coordinate latLonAoiCenter) {
    if (samplingPointsByLevel != null && samplingPointsByLevel.size() > levelIdx && CollectionUtils.isNotEmpty(samplingPointsByLevel.get(levelIdx))) {
        List<SamplingDesignItem> items = new ArrayList<SamplingDesignItem>();
        List<SamplingDesignItem> itemsInLevel = samplingPointsByLevel.get(levelIdx);
        items.addAll(itemsInLevel);
        for (SamplingDesignItem item : itemsInLevel) {
            item.setSurveyId(survey.getId());
            if (levelIdx < configuration.getLevelsSettings().size() - 1) {
                List<String> itemKeys = item.getLevelCodes();
                items.addAll(generateItems(levelIdx + 1, itemKeys, item.getCoordinate()));
            }
        }
        return items;
    } else {
        List<SamplingDesignItem> items = new ArrayList<SamplingDesignItem>();
        List<Coordinate> locations = generateLocations(latLonAoiCenter, levelIdx);
        for (int locationIdx = 0; locationIdx < locations.size(); locationIdx++) {
            Coordinate webMercatorCenter = locations.get(locationIdx);
            Coordinate latLonCenter = reprojectFromWebMercatorToLatLon(webMercatorCenter);
            SamplingDesignItem item = new SamplingDesignItem();
            item.setSrsId(LAT_LON_SRS_ID);
            item.setSurveyId(survey.getId());
            List<String> itemKeys = new ArrayList<String>(previousLevelKeys);
            itemKeys.add(String.valueOf(locationIdx + 1));
            item.setLevelCodes(itemKeys);
            item.setX(latLonCenter.getX());
            item.setY(latLonCenter.getY());
            items.add(item);
            if (levelIdx < configuration.getLevelsSettings().size() - 1) {
                items.addAll(generateItems(levelIdx + 1, itemKeys, latLonCenter));
            }
        }
        return items;
    }
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) ArrayList(java.util.ArrayList) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

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