Search in sources :

Example 1 with SamplingPointLevelGenerationSettings

use of org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings 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)

Example 2 with SamplingPointLevelGenerationSettings

use of org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings 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 3 with SamplingPointLevelGenerationSettings

use of org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings 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 4 with SamplingPointLevelGenerationSettings

use of org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings in project collect by openforis.

the class SamplingPointDataGenerator method generateLocations.

private List<Coordinate> generateLocations(Coordinate latLonCenter, int levelIdx) {
    SamplingPointLevelGenerationSettings pointsConfiguration = configuration.getLevelsSettings().get(levelIdx);
    Coordinate webMercatorAoiCenter = reprojectFromLatLonToWebMercator(latLonCenter);
    switch(pointsConfiguration.getShape()) {
        case CIRCLE:
            double areaWidth = calculateAoiWidth(levelIdx);
            return generateLocationsInCircle(webMercatorAoiCenter, areaWidth / 2, pointsConfiguration);
        case SQUARE:
            SamplingPointLevelGenerationSettings nextLevelPointsConfiguration = levelIdx == configuration.getLevelsSettings().size() - 1 ? null : configuration.getLevelsSettings().get(levelIdx + 1);
            Double pointWidth = nextLevelPointsConfiguration == null ? DEFAULT_POINT_SIZE : nextLevelPointsConfiguration.getPointWidth();
            List<Coordinate> boundary = levelIdx == 0 ? configuration.getAoiBoundary() : generateSquareBoundary(latLonCenter, pointWidth);
            return generateLocationsInSquare(webMercatorAoiCenter, boundary, pointsConfiguration);
        default:
            throw new IllegalArgumentException("Shape type not supported: " + pointsConfiguration.getShape());
    }
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) SamplingPointLevelGenerationSettings(org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings)

Aggregations

SamplingPointLevelGenerationSettings (org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings)4 Coordinate (org.openforis.idm.model.Coordinate)4 Test (org.junit.Test)2 SamplingPointDataGenerator (org.openforis.collect.io.metadata.samplingpointdata.SamplingPointDataGenerator)2 SamplingPointGenerationSettings (org.openforis.collect.metamodel.samplingdesign.SamplingPointGenerationSettings)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)2 Predicate (org.apache.commons.collections.Predicate)1