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);
}
}
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());
}
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"));
}
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());
}
}
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;
}
}
Aggregations