Skip to content

Commit

Permalink
Remove AreaAttr from Union function and return MULTIAREA
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Dec 18, 2023
1 parent 1851035 commit 120d06f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package ch.geowerkstatt.ilivalidator.extensions.functions;

import ch.ehi.basics.types.OutParam;
import ch.interlis.ili2c.metamodel.PathEl;
import ch.interlis.ili2c.metamodel.Viewable;
import ch.interlis.iom.IomObject;
import ch.interlis.iox.IoxException;
import ch.interlis.iox_j.jts.Iox2jtsException;
import ch.interlis.iox_j.jts.Iox2jtsext;
import ch.interlis.iox_j.jts.Jts2iox;
import ch.interlis.iox_j.jts.Jtsext2iox;
import ch.interlis.iox_j.validator.Value;
import com.vividsolutions.jts.geom.Geometry;
Expand All @@ -30,28 +29,15 @@ public String getQualifiedIliName() {

@Override
protected Value evaluateInternal(String validationKind, String usageScope, IomObject contextObject, Value[] actualArguments) {
Value argObjects = actualArguments[0]; // OBJECTS OF ANYCLASS
Value argPath = actualArguments[1]; // TEXT
Value argGeometries = actualArguments[0];

if (argObjects.isUndefined()) {
if (argGeometries.isUndefined()) {
return Value.createSkipEvaluation();
}
if (argObjects.getComplexObjects() == null) {
return Value.createUndefined();
}

Collection<IomObject> surfaces;

if (argPath.isUndefined()) {
surfaces = argObjects.getComplexObjects();
} else {
Viewable contextClass = EvaluationHelper.getContextClass(td, contextObject, argObjects);
if (contextClass == null) {
throw new IllegalStateException("unknown class in " + usageScope);
}

PathEl[] attributePath = EvaluationHelper.getAttributePathEl(validator, contextClass, argPath);
surfaces = EvaluationHelper.evaluateAttributes(validator, argObjects, attributePath);
Collection<IomObject> surfaces = argGeometries.getComplexObjects();
if (surfaces == null) {
return Value.createUndefined();
}

UnionSurfaceKey key = new UnionSurfaceKey(surfaces);
Expand Down
6 changes: 3 additions & 3 deletions src/model/GeoW_FunctionsExt.ili
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ MODEL GeoW_FunctionsExt
!!@ fn.since = "2022-12-05";
FUNCTION IsInsideExternalDataset (DatasetName: TEXT; Objects: TEXT; TestObject: OBJECT OF ANYCLASS; TestObjectgeometry: TEXT): BOOLEAN;

!!@ fn.description = "Fasst die Flächen-Geometrien aus der Eingabemenge zu einer Flächen-Geometrie zusammen. Für 'Objects' können Objekte oder Geometrien angegeben werden. Für 'AreaAttr' soll der Pfad zur Flächen-Geometrie in INTERLIS 2 Syntax angegeben werden. Falls 'Objects' bereits die Geometrien enthält, soll für 'AreaAttr' 'UNDEFINED' übergeben werden.";
!!@ fn.param = "Objects: Ausgangsobjekte oder Geometrien. AreaAttr: Pfad zum Geometrieattribut oder UNDEFINED";
!!@ fn.description = "Fasst die Flächen-Geometrien aus der Eingabemenge zu einer Flächen-Geometrie zusammen. Für 'Geometries' können nur Geometrien angegeben werden.";
!!@ fn.param = "Geometries: Geometrien, die zusammengefasst werden sollen";
!!@ fn.return = "Zusammengefasste Flächen-Geometrie";
!!@ fn.since = "2023-12-13";
FUNCTION Union (Objects: OBJECTS OF ANYCLASS; AreaAttr: TEXT): OBJECT OF ANYCLASS;
FUNCTION Union (Geometries: ANYSTRUCTURE): MULTIAREA;
END GeoW_FunctionsExt.
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ MODEL TestSuite
0 .. 10 [INTERLIS.m],
ROTATION 2 -> 1;

Surface = SURFACE WITH (STRAIGHTS) VERTEX Coord WITHOUT OVERLAPS > 0.1;

TOPIC FunctionTestTopic =

CLASS BaseClass =
surfaceAttribute : SURFACE WITH (STRAIGHTS) VERTEX Coord WITHOUT OVERLAPS > 0.1;
surfaceAttribute : BAG OF Surface;

!! Surfaces evaluated separately
SET CONSTRAINT innerRings:
GeoW_FunctionsExt.GetInnerRingsCount(ALL, "surfaceAttribute") == 2;
MANDATORY CONSTRAINT innerRings:
GeoW_FunctionsExt.GetInnerRingsCount(THIS, "surfaceAttribute") == 2;

!! Surfaces evaluated as union (inner rings overlap in test data)
SET CONSTRAINT innerRingsUnion:
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(ALL, "surfaceAttribute"), UNDEFINED) == 1;
MANDATORY CONSTRAINT innerRingsUnion:
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(THIS->surfaceAttribute), UNDEFINED) == 1;

END BaseClass;

Expand Down
4 changes: 2 additions & 2 deletions src/test/data/Union/MandatoryConstraintThis.ili
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ MODEL TestSuite
surfaceAttribute : BAG OF Surface;

MANDATORY CONSTRAINT falseConstraint:
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(THIS->surfaceAttribute, UNDEFINED), UNDEFINED) > 3;
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(THIS->surfaceAttribute), UNDEFINED) > 3;

MANDATORY CONSTRAINT oneInnerRingConstraint:
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(THIS->surfaceAttribute, UNDEFINED), UNDEFINED) == 1;
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(THIS->surfaceAttribute), UNDEFINED) == 1;

END BaseClass;

Expand Down
31 changes: 0 additions & 31 deletions src/test/data/Union/SetConstraintAll.ili

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/data/Union/TestDataMergedInnerRings.xtf
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@
</geom:interior>
</geom:surface>
</TestSuite:surfaceAttribute>
</TestSuite:BaseClass>
<TestSuite:BaseClass ili:tid="1">
<TestSuite:surfaceAttribute> <!-- Surface with one inner square from (1,1) to (4,4) -->
<geom:surface>
<geom:exterior>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,8 @@ void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException {
}

@Test
void setConstraintAll() throws Ili2cFailure, IoxException {
vh.runValidation(new String[]{TEST_DATA}, new String[]{"Union/SetConstraintAll.ili"});
Assert.equals(2, vh.getErrs().size());
AssertionHelper.assertConstraintErrors(vh, 1, "falseConstraint");
AssertionHelper.assertConstraintErrors(vh, 1, "falseConstraintUnion");
AssertionHelper.assertNoConstraintError(vh, "trueConstraint");
AssertionHelper.assertNoConstraintError(vh, "trueConstraintUnion");
}

@Test
void setConstraintMergedInnerRings() throws Ili2cFailure, IoxException {
vh.runValidation(new String[]{TEST_DATA_MERGED_INNER_RINGS}, new String[]{"Union/SetConstraintMergedInnerRings.ili"});
void mandatoryConstraintMergedInnerRings() throws Ili2cFailure, IoxException {
vh.runValidation(new String[]{TEST_DATA_MERGED_INNER_RINGS}, new String[]{"Union/MandatoryConstraintMergedInnerRings.ili"});
Assert.equals(0, vh.getErrs().size());
AssertionHelper.assertNoConstraintError(vh, "innerRings");
AssertionHelper.assertNoConstraintError(vh, "innerRingsUnion");
Expand Down

0 comments on commit 120d06f

Please sign in to comment.