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