Skip to content

Commit

Permalink
Add GeometryAttr parameter to Union
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Jan 17, 2024
1 parent 57ef59e commit fbde3f3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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;
Expand Down Expand Up @@ -29,13 +31,26 @@ public String getQualifiedIliName() {

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

if (argGeometries.isUndefined()) {
if (argObjects.isUndefined()) {
return Value.createSkipEvaluation();
}

Collection<IomObject> surfaces = argGeometries.getComplexObjects();
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);
}

if (surfaces == null) {
return Value.createUndefined();
}
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 @@ -46,11 +46,11 @@ MODEL GeoW_FunctionsExt
!!@ fn.since = "2023-12-21";
FUNCTION IsInside (ReferenceGeometry: MULTIAREA; 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 'Geometries' können nur Geometrien angegeben werden.";
!!@ fn.param = "Geometries: Geometrien, die zusammengefasst werden sollen";
!!@ 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 'GeometryAttr' soll der Pfad zur Flächen-Geometrie in INTERLIS 2 Syntax angegeben werden. Falls 'Objects' bereits die Geometrien enthält, soll für 'GeometryAttr' 'UNDEFINED' übergeben werden.";
!!@ fn.param = "Objects: Objekte, deren Geometrien zusammengefasst werden sollen. GeometryAttr: Pfad zum Geometrieattribut oder UNDEFINED";
!!@ fn.return = "Zusammengefasste Flächen-Geometrie";
!!@ fn.since = "2023-12-13";
FUNCTION Union (Geometries: ANYSTRUCTURE): MULTIAREA;
FUNCTION Union (Objects: ANYSTRUCTURE; GeometryAttr: TEXT): MULTIAREA;

!!@ fn.description = "Prüft, ob sich die Linien-Geometrien überlappen oder eine gemeinsame Teilstrecke vorhanden ist (wenn die Schnittmenge der Innenbereiche einer Linie entspricht). Für 'Objects' können Objekte oder Geometrien angegeben werden. Für 'LineAttr' soll der Pfad zur Linien-Geometrie in INTERLIS 2 Syntax angegeben werden. Falls 'Objects' bereits die Geometrien enthält, soll für 'LineAttr' 'UNDEFINED' übergeben werden.";
!!@ fn.param = "Objects: Ausgangsobjekte oder Geometrien. LineAttr: Pfad zum Geometrieattribut oder UNDEFINED";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MODEL TestSuite

!! Surfaces evaluated as union (inner rings overlap in test data)
MANDATORY CONSTRAINT innerRingsUnion:
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(THIS->surfaceAttribute), UNDEFINED) == 1;
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) > 3;
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(THIS->surfaceAttribute, UNDEFINED), UNDEFINED) > 3;

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

END BaseClass;

Expand Down

0 comments on commit fbde3f3

Please sign in to comment.