Search in sources :

Example 21 with SamplingDesignItem

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

the class SamplingDesignExportTask method execute.

@Override
protected void execute() throws Throwable {
    if (getTotalItems() > 0) {
        Integer surveyId = survey.getId();
        CsvWriter writer = new CsvWriter(outputStream, OpenForisIOUtils.UTF_8, ',', '"');
        SamplingDesignSummaries summaries = samplingDesignManager.loadBySurvey(surveyId);
        ArrayList<String> colNames = getHeaders();
        writer.writeHeaders(colNames);
        List<SamplingDesignItem> items = summaries.getRecords();
        for (SamplingDesignItem item : items) {
            writeSummary(writer, item);
            incrementProcessedItems();
        }
        writer.flush();
    }
}
Also used : CsvWriter(org.openforis.commons.io.csv.CsvWriter) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 22 with SamplingDesignItem

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

the class SamplingDesignImportTask method persistSamplingDesign.

protected void persistSamplingDesign() throws SurveyImportException {
    List<String> infoColumnNames = reader.getInfoColumnNames();
    List<ReferenceDataDefinition.Attribute> attributes = ReferenceDataDefinition.Attribute.fromNames(infoColumnNames);
    SamplingPointDefinition samplingPoint;
    if (attributes.isEmpty()) {
        samplingPoint = null;
    } else {
        samplingPoint = new SamplingPointDefinition();
        samplingPoint.setAttributes(attributes);
    }
    ReferenceDataSchema referenceDataSchema = survey.getReferenceDataSchema();
    if (referenceDataSchema == null) {
        referenceDataSchema = new ReferenceDataSchema();
        survey.setReferenceDataSchema(referenceDataSchema);
    }
    referenceDataSchema.setSamplingPointDefinition(samplingPoint);
    List<SamplingDesignItem> items = createItemsFromLines();
    samplingDesignManager.insert(survey, items, overwriteAll);
}
Also used : SamplingPointDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.SamplingPointDefinition) ReferenceDataSchema(org.openforis.idm.metamodel.ReferenceDataSchema) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 23 with SamplingDesignItem

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

the class SamplingDesignLine method toSamplingDesignItem.

public SamplingDesignItem toSamplingDesignItem(CollectSurvey survey, List<String> infoColumnNames) {
    SamplingDesignItem item = new SamplingDesignItem();
    item.setSurveyId(survey.getId());
    item.setX(Double.parseDouble(x));
    item.setY(Double.parseDouble(y));
    item.setSrsId(srsId);
    item.setLevelCodes(getKey().getLevelCodes());
    List<String> infoAttributeNames = new ArrayList<String>();
    for (String colName : infoColumnNames) {
        infoAttributeNames.add(getInfoAttribute(colName));
    }
    item.setInfoAttributes(infoAttributeNames);
    return item;
}
Also used : ArrayList(java.util.ArrayList) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 24 with SamplingDesignItem

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

the class SamplingPointDataKmlGenerator method loadSamplingDesignItems.

private List<SamplingDesignItem> loadSamplingDesignItems() {
    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 25 with SamplingDesignItem

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

the class SurveyCreator method generateSimpleSurvey.

public CollectSurvey generateSimpleSurvey(SimpleSurveyCreationParameters parameters) throws SurveyStoreException, SurveyImportException {
    String projectName = parameters.getProjectName();
    String internalName = ObjectUtils.defaultIfNull(parameters.getName(), SurveyObjects.adjustInternalName(projectName));
    CollectSurvey existingSurvey = surveyManager.get(internalName);
    if (existingSurvey != null) {
        // TODO move it to validator
        throw new IllegalArgumentException(String.format("Survey with name %s already existing", internalName));
    }
    CollectSurvey survey = createTemporarySimpleSurvey(internalName, parameters.getCodeLists());
    survey.setProjectName(survey.getDefaultLanguage(), projectName);
    survey.setDescription(survey.getDefaultLanguage(), parameters.getDescription());
    UserGroup userGroup = userGroupManager.loadById(parameters.getUserGroupId());
    survey.setUserGroup(userGroup);
    CeoApplicationOptions ceoApplicationOptions = new CeoApplicationOptions();
    ceoApplicationOptions.setBaseMapSource(parameters.getCeoSettings().getBaseMapSource());
    ceoApplicationOptions.setImageryYear(parameters.getCeoSettings().getImageryYear());
    ceoApplicationOptions.setStackingProfile(parameters.getCeoSettings().getStackingProfile());
    SamplingPointGenerationSettings samplingPointGenerationSettings = parameters.getSamplingPointGenerationSettings();
    ceoApplicationOptions.setSamplingPointDataConfiguration(samplingPointGenerationSettings);
    survey.addApplicationOptions(ceoApplicationOptions);
    surveyManager.save(survey);
    SamplingPointDataGenerator generator = new SamplingPointDataGenerator(coordinateOperations, survey, parameters.getSamplingPointsByLevel(), samplingPointGenerationSettings);
    List<SamplingDesignItem> items = generator.generate();
    samplingDesignManager.insert(survey, items, true);
    return survey;
}
Also used : SamplingPointGenerationSettings(org.openforis.collect.metamodel.samplingdesign.SamplingPointGenerationSettings) CeoApplicationOptions(org.openforis.collect.persistence.xml.CeoApplicationOptions) SamplingPointDataGenerator(org.openforis.collect.io.metadata.samplingpointdata.SamplingPointDataGenerator) CollectSurvey(org.openforis.collect.model.CollectSurvey) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) UserGroup(org.openforis.collect.model.UserGroup)

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