Search in sources :

Example 1 with CoordinateAttribute

use of org.openforis.idm.model.CoordinateAttribute 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 CoordinateAttribute

use of org.openforis.idm.model.CoordinateAttribute in project collect by openforis.

the class DistanceCheckTest method testEvalutateDistanceCheckDestinationPoint.

@Test
public void testEvalutateDistanceCheckDestinationPoint() {
    EntityBuilder.addValue(cluster, "id", new Code("001"));
    Coordinate coord = Coordinate.parseCoordinate("SRID=EPSG:21035;POINT(885750 9333820)");
    CoordinateAttribute vehicleLocation = EntityBuilder.addValue(cluster, "vehicle_location", coord);
    CoordinateAttributeDefinition defn = vehicleLocation.getDefinition();
    DistanceCheck check = (DistanceCheck) defn.getChecks().get(0);
    Coordinate destinationPoint = check.evaluateDestinationPoint(vehicleLocation);
    Assert.assertEquals(TEST_COORDINATE, destinationPoint);
}
Also used : CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) DistanceCheck(org.openforis.idm.metamodel.validation.DistanceCheck) Coordinate(org.openforis.idm.model.Coordinate) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 3 with CoordinateAttribute

use of org.openforis.idm.model.CoordinateAttribute in project collect by openforis.

the class DistanceCheckTest method testEvalutateDistanceCheckMaxDistance.

@Test
public void testEvalutateDistanceCheckMaxDistance() {
    EntityBuilder.addValue(cluster, "id", new Code("001"));
    Coordinate coord = Coordinate.parseCoordinate("SRID=EPSG:21035;POINT(885750 9333820)");
    CoordinateAttribute vehicleLocation = EntityBuilder.addValue(cluster, "vehicle_location", coord);
    CoordinateAttributeDefinition defn = vehicleLocation.getDefinition();
    DistanceCheck check = (DistanceCheck) defn.getChecks().get(0);
    Double maxDistance = check.evaluateMaxDistance(vehicleLocation);
    Assert.assertEquals(Double.valueOf(100000d), maxDistance);
}
Also used : CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) DistanceCheck(org.openforis.idm.metamodel.validation.DistanceCheck) Coordinate(org.openforis.idm.model.Coordinate) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 4 with CoordinateAttribute

use of org.openforis.idm.model.CoordinateAttribute in project collect by openforis.

the class DistanceCheckTest method testWarnMaxDistance.

@Test
public void testWarnMaxDistance() {
    String coordStr = "SRID=EPSG:21035;POINT(885750 9333820)";
    Coordinate coord = Coordinate.parseCoordinate(coordStr);
    EntityBuilder.addValue(cluster, "id", new Code("001"));
    CoordinateAttribute vehicleLocation = EntityBuilder.addValue(cluster, "vehicle_location", coord);
    ValidationResults results = validate(vehicleLocation);
    Assert.assertFalse(containsDistanceCheck(results.getErrors()));
    Assert.assertTrue(containsDistanceCheck(results.getWarnings()));
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Coordinate(org.openforis.idm.model.Coordinate) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 5 with CoordinateAttribute

use of org.openforis.idm.model.CoordinateAttribute in project collect by openforis.

the class DistanceCheckTest method testErrorMaxDistance.

@Test
public void testErrorMaxDistance() {
    String coordStr = "SRID=EPSG:21035;POINT(915750 9333820)";
    Coordinate coord = Coordinate.parseCoordinate(coordStr);
    EntityBuilder.addValue(cluster, "id", new Code("001"));
    CoordinateAttribute vehicleLocation = EntityBuilder.addValue(cluster, "vehicle_location", coord);
    ValidationResults results = validate(vehicleLocation);
    Assert.assertTrue(containsDistanceCheck(results.getErrors()));
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Coordinate(org.openforis.idm.model.Coordinate) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Aggregations

CoordinateAttribute (org.openforis.idm.model.CoordinateAttribute)9 Coordinate (org.openforis.idm.model.Coordinate)7 Test (org.junit.Test)5 Code (org.openforis.idm.model.Code)5 ValidationResults (org.openforis.idm.metamodel.validation.ValidationResults)3 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)2 DistanceCheck (org.openforis.idm.metamodel.validation.DistanceCheck)2 ArrayList (java.util.ArrayList)1 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)1 SpatialReferenceSystem (org.openforis.idm.metamodel.SpatialReferenceSystem)1 Survey (org.openforis.idm.metamodel.Survey)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1