Search in sources :

Example 1 with SpatialReferenceSystem

use of org.openforis.idm.metamodel.SpatialReferenceSystem in project collect by openforis.

the class CSVDataImportProcess method setSRSIdField.

private void setSRSIdField(Attribute<?, ?> attr, String value, long row, String colName) {
    boolean valid = true;
    if (StringUtils.isNotBlank(value)) {
        // check SRS id validity
        Survey survey = attr.getSurvey();
        SpatialReferenceSystem srs = survey.getSpatialReferenceSystem(value);
        if (srs == null) {
            ParsingError parsingError = new ParsingError(ErrorType.INVALID_VALUE, row, colName, SRS_NOT_FOUND_MESSAGE_KEY);
            parsingError.setMessageArgs(new String[] { value });
            status.addParsingError(parsingError);
            valid = false;
        }
    }
    if (valid) {
        Field<String> field = ((CoordinateAttribute) attr).getSrsIdField();
        NodeChangeSet changes = recordUpdater.updateField(field, value);
        if (nodeChangeBatchProcessor != null) {
            nodeChangeBatchProcessor.add(changes, adminUser.getUsername());
        }
    }
}
Also used : NodeChangeSet(org.openforis.collect.model.NodeChangeSet) CollectSurvey(org.openforis.collect.model.CollectSurvey) Survey(org.openforis.idm.metamodel.Survey) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) SpatialReferenceSystem(org.openforis.idm.metamodel.SpatialReferenceSystem)

Example 2 with SpatialReferenceSystem

use of org.openforis.idm.metamodel.SpatialReferenceSystem in project collect by openforis.

the class CoordinateValidator method evaluate.

@Override
public ValidationResultFlag evaluate(CoordinateAttribute node) {
    Coordinate coordinate = node.getValue();
    CoordinateAttributeDefinition definition = node.getDefinition();
    List<SpatialReferenceSystem> srs = definition.getSurvey().getSpatialReferenceSystems();
    boolean valid = coordinate.getX() != null && coordinate.getY() != null && isSrsIdValid(srs, coordinate.getSrsId());
    if (valid) {
        valid = node.getSurveyContext().getCoordinateOperations().validate(coordinate);
    }
    return ValidationResultFlag.valueOf(valid);
}
Also used : CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) Coordinate(org.openforis.idm.model.Coordinate) SpatialReferenceSystem(org.openforis.idm.metamodel.SpatialReferenceSystem)

Example 3 with SpatialReferenceSystem

use of org.openforis.idm.metamodel.SpatialReferenceSystem in project collect by openforis.

the class CoordinateOperations method convertTo.

private Coordinate convertTo(Coordinate coordinate, SpatialReferenceSystem toSrs) {
    SpatialReferenceSystem fromSrs = toSrs(coordinate);
    if (fromSrs.equals(toSrs)) {
        return coordinate;
    } else {
        double[] uiCoordinate = toUiCoordinate(coordinate);
        double[] transformed = CoordinateUtils.transform(fromSrs, uiCoordinate, toSrs);
        return new Coordinate(transformed[0], transformed[1], toSrs.getId());
    }
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) SpatialReferenceSystem(org.openforis.idm.metamodel.SpatialReferenceSystem)

Example 4 with SpatialReferenceSystem

use of org.openforis.idm.metamodel.SpatialReferenceSystem in project collect by openforis.

the class GeoToolsCoordinateOperations method fetchSRS.

public SpatialReferenceSystem fetchSRS(String code, Set<String> labelLanguages) {
    try {
        CRSAuthorityFactory factory = CRS.getAuthorityFactory(true);
        CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem(code);
        SpatialReferenceSystem result = new SpatialReferenceSystem(code, crs.toWKT());
        String description = getDescription(crs);
        for (String lang : labelLanguages) {
            result.setLabel(lang, code);
            result.setDescription(lang, description);
        }
        return result;
    } catch (Exception e) {
        throw new RuntimeException("Error fetching SRS with code: " + code, e);
    }
}
Also used : SpatialReferenceSystem(org.openforis.idm.metamodel.SpatialReferenceSystem) CRSAuthorityFactory(org.opengis.referencing.crs.CRSAuthorityFactory) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) InternationalString(org.opengis.util.InternationalString) FactoryException(org.opengis.referencing.FactoryException) CoordinateOperationException(org.openforis.idm.geospatial.CoordinateOperationException) TransformException(org.opengis.referencing.operation.TransformException)

Example 5 with SpatialReferenceSystem

use of org.openforis.idm.metamodel.SpatialReferenceSystem in project collect by openforis.

the class SamplingDesignLineValidator method validateSrsId.

protected void validateSrsId(SamplingDesignLine line) {
    String srsId = line.getSrsId();
    SpatialReferenceSystem srs = survey.getSpatialReferenceSystem(srsId);
    if (srs == null) {
        ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, line.getLineNumber(), SamplingDesignFileColumn.SRS_ID.getColumnName(), INVALID_SRS_ID_MESSAGE_KEY);
        error.setMessageArgs(new String[] { srsId });
        errors.add(error);
    }
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) SpatialReferenceSystem(org.openforis.idm.metamodel.SpatialReferenceSystem)

Aggregations

SpatialReferenceSystem (org.openforis.idm.metamodel.SpatialReferenceSystem)9 CollectSurvey (org.openforis.collect.model.CollectSurvey)4 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)2 Coordinate (org.openforis.idm.model.Coordinate)2 ArrayList (java.util.ArrayList)1 GeoToolsCoordinateOperations (org.openforis.collect.geospatial.GeoToolsCoordinateOperations)1 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)1 CoordinateOperationException (org.openforis.idm.geospatial.CoordinateOperationException)1 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)1 Survey (org.openforis.idm.metamodel.Survey)1 CoordinateAttribute (org.openforis.idm.model.CoordinateAttribute)1 FactoryException (org.opengis.referencing.FactoryException)1 CRSAuthorityFactory (org.opengis.referencing.crs.CRSAuthorityFactory)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 TransformException (org.opengis.referencing.operation.TransformException)1 InternationalString (org.opengis.util.InternationalString)1