-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 Add IsInside function
- Loading branch information
Showing
8 changed files
with
251 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideIoxPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ch.geowerkstatt.ilivalidator.extensions.functions; | ||
|
||
import ch.ehi.basics.types.OutParam; | ||
import ch.interlis.iom.IomObject; | ||
import ch.interlis.iox.IoxException; | ||
import ch.interlis.iox_j.jts.Iox2jtsext; | ||
import ch.interlis.iox_j.validator.Value; | ||
import com.vividsolutions.jts.geom.Geometry; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public final class IsInsideIoxPlugin extends BaseIsInsideFunction { | ||
private static final Map<IomObject, Geometry> VALID_AREA_CACHE = new HashMap<>(); | ||
private static final String QUALIFIED_ILI_NAME = "GeoW_FunctionsExt.IsInside"; | ||
|
||
@Override | ||
public String getQualifiedIliName() { | ||
return QUALIFIED_ILI_NAME; | ||
} | ||
|
||
@Override | ||
protected Value evaluateInternal(String validationKind, String usageScope, IomObject mainObj, Value[] arguments) { | ||
Value argReferenceGeometry = arguments[0]; // MULTIAREA | ||
Value argTestObject = arguments[1]; // OBJECT OF ANYCLASS | ||
Value argTestObjectgeometry = arguments[2]; // TEXT | ||
|
||
if (argTestObject.isUndefined() || argTestObjectgeometry.isUndefined()) { | ||
return Value.createSkipEvaluation(); | ||
} | ||
if (argReferenceGeometry.isUndefined()) { | ||
writeLogErrorMessage(usageScope, "Missing reference geometry."); | ||
return Value.createUndefined(); | ||
} | ||
|
||
Collection<IomObject> referenceGeometryObjects = argReferenceGeometry.getComplexObjects(); | ||
if (referenceGeometryObjects.size() != 1) { | ||
writeLogErrorMessage(usageScope, "Expected exactly one reference geometry."); | ||
return Value.createUndefined(); | ||
} | ||
|
||
IomObject referenceGeometry = referenceGeometryObjects.iterator().next(); | ||
String testObjectGeometryAttribute = argTestObjectgeometry.getValue(); | ||
|
||
return isInsideValidArea(usageScope, argTestObject.getComplexObjects(), testObjectGeometryAttribute, () -> VALID_AREA_CACHE.computeIfAbsent(referenceGeometry, this::getValidArea)); | ||
} | ||
|
||
private Geometry getValidArea(IomObject referenceGeometry) { | ||
try { | ||
return Iox2jtsext.multisurface2JTS(referenceGeometry, 0.0, new OutParam<>(), logger, 0.0, "warning"); | ||
} catch (IoxException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
INTERLIS 2.4; | ||
|
||
MODEL TestSuite | ||
AT "mailto:[email protected]" VERSION "2023-12-21" = | ||
IMPORTS GeoW_FunctionsExt; | ||
|
||
DOMAIN | ||
!!@CRS=EPSG:2056 | ||
CHKoord = COORD 2460000.000 .. 2870000.000 [INTERLIS.m], | ||
1045000.000 .. 1310000.000 [INTERLIS.m], | ||
ROTATION 2 -> 1; | ||
CHMultiArea = MULTIAREA WITH (STRAIGHTS) VERTEX CHKoord WITHOUT OVERLAPS > 0.001; | ||
|
||
TOPIC FunctionTestTopic = | ||
CLASS ConstraintTestClass (ABSTRACT) = | ||
expected : MANDATORY BOOLEAN; | ||
END ConstraintTestClass; | ||
|
||
CLASS IsInsideKantonsgrenze EXTENDS ConstraintTestClass = | ||
testAttributeIsInsideKantonsgrenze : CHKoord; | ||
testAttributeKantonsgrenze : CHMultiArea; | ||
MANDATORY CONSTRAINT IsInsideKantonsgrenze: GeoW_FunctionsExt.IsInside(THIS->testAttributeKantonsgrenze, THIS, "testAttributeIsInsideKantonsgrenze") == expected; | ||
END IsInsideKantonsgrenze; | ||
|
||
CLASS InvalidConstraints = | ||
geometryAttribute : CHKoord; | ||
area : CHMultiArea; | ||
MANDATORY CONSTRAINT IsInsideMissingArea: GeoW_FunctionsExt.IsInside(THIS->area, THIS, "geometryAttribute"); | ||
END InvalidConstraints; | ||
|
||
END FunctionTestTopic; | ||
|
||
END TestSuite. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ili:transfer xmlns:ili="http://www.interlis.ch/xtf/2.4/INTERLIS" xmlns:geom="http://www.interlis.ch/geometry/1.0" | ||
xmlns:TestSuite="http://www.interlis.ch/xtf/2.4/TestSuite"> | ||
<ili:headersection> | ||
<ili:models> | ||
<ili:model>GeoW_FunctionsExt</ili:model> | ||
<ili:model>TestSuite</ili:model> | ||
</ili:models> | ||
<ili:sender>ili2gpkg-4.6.1-63db90def1260a503f0f2d4cb846686cd4851184</ili:sender> | ||
</ili:headersection> | ||
<ili:datasection> | ||
<TestSuite:FunctionTestTopic ili:bid="TestSuite.FunctionTestTopic"> | ||
<TestSuite:InvalidConstraints ili:tid="1"> | ||
<TestSuite:geometryAttribute> | ||
<geom:coord> | ||
<geom:c1>2533306.953</geom:c1> | ||
<geom:c2>1184710.792</geom:c2> | ||
</geom:coord> | ||
</TestSuite:geometryAttribute> | ||
<!-- Kein area-Attribut, um fehlende Fläche zu testen --> | ||
</TestSuite:InvalidConstraints> | ||
<TestSuite:IsInsideKantonsgrenze ili:tid="2"> <!-- Erwartet: 2D-Punkt: liegt im Kt. SO --> | ||
<TestSuite:expected>true</TestSuite:expected> | ||
<TestSuite:testAttributeIsInsideKantonsgrenze> | ||
<geom:coord> | ||
<geom:c1>2620570.500</geom:c1> | ||
<geom:c2>1237151.400</geom:c2> | ||
</geom:coord> | ||
</TestSuite:testAttributeIsInsideKantonsgrenze> | ||
<TestSuite:testAttributeKantonsgrenze> | ||
<geom:multisurface> | ||
<geom:surface> | ||
<geom:exterior> | ||
<geom:polyline> | ||
<geom:coord> | ||
<geom:c1>2591994.000</geom:c1> | ||
<geom:c2>1262353.000</geom:c2> | ||
</geom:coord> | ||
<geom:coord> | ||
<geom:c1>2645900.000</geom:c1> | ||
<geom:c2>1262353.000</geom:c2> | ||
</geom:coord> | ||
<geom:coord> | ||
<geom:c1>2645900.000</geom:c1> | ||
<geom:c2>1211927.000</geom:c2> | ||
</geom:coord> | ||
<geom:coord> | ||
<geom:c1>2591994.000</geom:c1> | ||
<geom:c2>1211927.000</geom:c2> | ||
</geom:coord> | ||
<geom:coord> | ||
<geom:c1>2591994.000</geom:c1> | ||
<geom:c2>1262353.000</geom:c2> | ||
</geom:coord> | ||
</geom:polyline> | ||
</geom:exterior> | ||
</geom:surface> | ||
</geom:multisurface> | ||
</TestSuite:testAttributeKantonsgrenze> | ||
</TestSuite:IsInsideKantonsgrenze> | ||
<TestSuite:IsInsideKantonsgrenze ili:tid="3"> <!-- Erwartet: 2D-Punkt: liegt ausserhalb, c1 der Fläche verschoben --> | ||
<TestSuite:expected>false</TestSuite:expected> | ||
<TestSuite:testAttributeIsInsideKantonsgrenze> | ||
<geom:coord> | ||
<geom:c1>2620570.500</geom:c1> | ||
<geom:c2>1237151.400</geom:c2> | ||
</geom:coord> | ||
</TestSuite:testAttributeIsInsideKantonsgrenze> | ||
<TestSuite:testAttributeKantonsgrenze> | ||
<geom:multisurface> | ||
<geom:surface> | ||
<geom:exterior> | ||
<geom:polyline> | ||
<geom:coord> | ||
<geom:c1>2691994.000</geom:c1> | ||
<geom:c2>1262353.000</geom:c2> | ||
</geom:coord> | ||
<geom:coord> | ||
<geom:c1>2745900.000</geom:c1> | ||
<geom:c2>1262353.000</geom:c2> | ||
</geom:coord> | ||
<geom:coord> | ||
<geom:c1>2745900.000</geom:c1> | ||
<geom:c2>1211927.000</geom:c2> | ||
</geom:coord> | ||
<geom:coord> | ||
<geom:c1>2691994.000</geom:c1> | ||
<geom:c2>1211927.000</geom:c2> | ||
</geom:coord> | ||
<geom:coord> | ||
<geom:c1>2691994.000</geom:c1> | ||
<geom:c2>1262353.000</geom:c2> | ||
</geom:coord> | ||
</geom:polyline> | ||
</geom:exterior> | ||
</geom:surface> | ||
</geom:multisurface> | ||
</TestSuite:testAttributeKantonsgrenze> | ||
</TestSuite:IsInsideKantonsgrenze> | ||
</TestSuite:FunctionTestTopic> | ||
</ili:datasection> | ||
</ili:transfer> |
27 changes: 27 additions & 0 deletions
27
src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideIoxPluginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ch.geowerkstatt.ilivalidator.extensions.functions; | ||
|
||
import ch.interlis.ili2c.Ili2cFailure; | ||
import ch.interlis.iox.IoxException; | ||
import com.vividsolutions.jts.util.Assert; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public final class IsInsideIoxPluginTest { | ||
private static final String TEST_DATA = "IsInside/TestData.xtf"; | ||
private ValidationTestHelper vh; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
vh = new ValidationTestHelper(); | ||
vh.addFunction(new IsInsideIoxPlugin()); | ||
} | ||
|
||
@Test | ||
void isInside() throws Ili2cFailure, IoxException { | ||
vh.runValidation(new String[]{TEST_DATA}, new String[]{"IsInside/MandatoryConstraintThis.ili"}); | ||
|
||
Assert.equals(2, vh.getErrs().size()); | ||
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.IsInsideMissingArea: Unable to evaluate GeoW_FunctionsExt.IsInside. Missing reference geometry."); | ||
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "Mandatory Constraint TestSuite.FunctionTestTopic.InvalidConstraints.IsInsideMissingArea is not true."); | ||
} | ||
} |