Search in sources :

Example 91 with Instance

use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.

the class LinearRingHandlerTest method testLinearRingGml32_Grid.

/**
 * Test linear ring geometries read from a GML 3.2 file
 *
 * @throws Exception if an error occurs
 */
@Test
public void testLinearRingGml32_Grid() throws Exception {
    InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/linearring/sample-linearring-gml32.xml").toURI(), gridConfig);
    // five instances expected
    ResourceIterator<Instance> it = instances.iterator();
    try {
        // 1. LinearRingProperty with LinearRing defined through coordinates
        assertTrue("First sample feature missing", it.hasNext());
        Instance instance = it.next();
        checkSingleGeometry(instance, gridChecker);
        // 2. LinearRingProperty with LinearRing defined through pos
        assertTrue("Second sample feature missing", it.hasNext());
        instance = it.next();
        checkSingleGeometry(instance, gridChecker);
        // 3. LinearRingProperty with LinearRing defined through pointRep
        assertTrue("Third sample feature missing", it.hasNext());
        instance = it.next();
        checkSingleGeometry(instance, gridChecker);
        // 4. LinearRingProperty with LinearRing defined through
        // pointProperty
        assertTrue("Fourth sample feature missing", it.hasNext());
        instance = it.next();
        checkSingleGeometry(instance, gridChecker);
        // 5. LinearRingProperty with LinearRing defined through posList
        assertTrue("Fifth sample feature missing", it.hasNext());
        instance = it.next();
        checkSingleGeometry(instance, gridChecker);
    } finally {
        it.close();
    }
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) Test(org.junit.Test) AbstractHandlerTest(eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)

Example 92 with Instance

use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.

the class PointHandlerTest method testPointGml2_Grid.

/**
 * Test point geometries read from a GML 2 file.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testPointGml2_Grid() throws Exception {
    InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml2.xsd").toURI(), getClass().getResource("/data/point/sample-point-gml2.xml").toURI(), gridConfig);
    // three instances expected
    ResourceIterator<Instance> it = instances.iterator();
    try {
        // 1. PointProperty with Point defined through coordinates
        assertTrue("First sample feature missing", it.hasNext());
        Instance instance = it.next();
        checkSingleGeometry(instance, gridChecker);
        // 2. PointProperty with Point defined through coord
        assertTrue("Second sample feature missing", it.hasNext());
        instance = it.next();
        checkSingleGeometry(instance, gridChecker);
        // 3. GeometryProperty with Point defined through coordinates
        assertTrue("Third sample feature missing", it.hasNext());
        instance = it.next();
        checkSingleGeometry(instance, gridChecker);
    } finally {
        it.close();
    }
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) Test(org.junit.Test) AbstractHandlerTest(eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)

Example 93 with Instance

use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.

the class FilterTest method testLoadShiporderCQL.

/**
 * Test loading a simple XML file with one instance
 *
 * @throws Exception if an error occurs
 */
@Ignore
// element)
@Test
public void testLoadShiporderCQL() throws Exception {
    InstanceCollection instances = loadXMLInstances(getClass().getResource("/testdata/shiporder/shiporder.xsd").toURI(), getClass().getResource("/testdata/shiporder/shiporder.xml").toURI());
    ResourceIterator<Instance> it = instances.iterator();
    try {
        assertTrue(it.hasNext());
        boolean foundIt = false;
        boolean stayFalse = false;
        boolean stayFalseToo = false;
        boolean foundIt2 = false;
        Filter cqlfilter = new FilterGeoCqlImpl("shipto.city = '4000 Stavanger'");
        Filter foulfilter = new FilterGeoCqlImpl("HERP = 'DERP'");
        Filter foulfilter1 = new FilterGeoCqlImpl("shipto.city = 'HURR'");
        Filter cqlfilter2 = new FilterGeoCqlImpl("\"{http://www.example.com}shipto.{http://www.example.com}city\" = '4000 Stavanger'");
        while (it.hasNext()) {
            Instance instance = it.next();
            assertNotNull(instance);
            if (cqlfilter.match(instance)) {
                foundIt = true;
            }
            if (foulfilter.match(instance)) {
                stayFalse = true;
            }
            if (foulfilter1.match(instance)) {
                stayFalseToo = true;
            }
            if (cqlfilter2.match(instance)) {
                foundIt2 = true;
            }
        }
        assertTrue(foundIt);
        assertTrue(foundIt2);
        assertFalse(stayFalse);
        assertFalse(stayFalseToo);
    } finally {
        it.close();
    }
}
Also used : MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 94 with Instance

use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.

the class FilterTest method simpleSchemaTestCQL.

@Test
public void simpleSchemaTestCQL() throws Exception {
    ShapeSchemaReader schemaReader = new ShapeSchemaReader();
    schemaReader.setSource(new DefaultInputSupplier(getClass().getResource("/testdata/GN_Point/GN_Point.shp").toURI()));
    schemaReader.validate();
    IOReport report = schemaReader.execute(null);
    assertTrue(report.isSuccess());
    Schema schema = schemaReader.getSchema();
    ShapeInstanceReader instanceReader = new ShapeInstanceReader();
    instanceReader.setSource(new DefaultInputSupplier(getClass().getResource("/testdata/GN_Point/GN_Point.shp").toURI()));
    instanceReader.setSourceSchema(schema);
    instanceReader.validate();
    report = instanceReader.execute(null);
    assertTrue(report.isSuccess());
    InstanceCollection instances = instanceReader.getInstances();
    assertFalse(instances.isEmpty());
    ResourceIterator<Instance> ri = instances.iterator();
    try {
        boolean foundIt = false;
        boolean stayFalse = false;
        boolean stayFalseToo = false;
        Filter cqlfilter = new FilterGeoCqlImpl("NEV = 'Piritulus'");
        Filter foulfilter = new FilterGeoCqlImpl("HERP = 'DERP'");
        Filter foulfilter1 = new FilterGeoCqlImpl("NEV = 'HURR'");
        while (ri.hasNext()) {
            Instance inst = ri.next();
            assertNotNull(inst);
            if (cqlfilter.match(inst)) {
                foundIt = true;
            }
            if (foulfilter.match(inst)) {
                stayFalse = true;
            }
            if (foulfilter1.match(inst)) {
                stayFalseToo = true;
            }
        }
        assertTrue(foundIt);
        assertFalse(stayFalse);
        assertFalse(stayFalseToo);
    } finally {
        ri.close();
    }
}
Also used : ShapeInstanceReader(eu.esdihumboldt.hale.io.shp.reader.internal.ShapeInstanceReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) ShapeSchemaReader(eu.esdihumboldt.hale.io.shp.reader.internal.ShapeSchemaReader) Test(org.junit.Test)

Example 95 with Instance

use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.

the class InstanceBuilderReader method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Run instance builder", ProgressIndicator.UNKNOWN);
    try {
        CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
        compilerConfiguration.setScriptBaseClass(DelegatingScript.class.getName());
        // Configure the GroovyShell and pass the compiler configuration.
        GroovyShell shell = new GroovyShell(getClass().getClassLoader(), new Binding(), compilerConfiguration);
        DelegatingScript script;
        try (InputStream in = getSource().getInput();
            InputStreamReader reader = new InputStreamReader(in, getCharset())) {
            script = (DelegatingScript) shell.parse(reader);
        }
        InstanceBuilder builder = new InstanceBuilder();
        // apply schema
        builder.setTypes(getSourceSchema());
        script.setDelegate(builder);
        Object res = script.run();
        if (res == null) {
            throw new IllegalStateException("Null returned by script");
        } else if (res instanceof InstanceCollection) {
            instances = (InstanceCollection) res;
        } else if (res instanceof Instance) {
            instances = new DefaultInstanceCollection(Collections.singleton((Instance) res));
        } else {
            throw new IllegalStateException("Unrecognised return type: " + res.getClass().getName());
        }
        reporter.setSuccess(true);
    } catch (Exception e) {
        reporter.setSuccess(false);
        reporter.error("Error running instance builder", e);
    } finally {
        progress.end();
    }
    return reporter;
}
Also used : Binding(groovy.lang.Binding) InputStreamReader(java.io.InputStreamReader) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InputStream(java.io.InputStream) DefaultInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) DefaultInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection) GroovyShell(groovy.lang.GroovyShell) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) DelegatingScript(groovy.util.DelegatingScript) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) InstanceBuilder(eu.esdihumboldt.hale.common.instance.groovy.InstanceBuilder)

Aggregations

Instance (eu.esdihumboldt.hale.common.instance.model.Instance)203 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)131 Test (org.junit.Test)122 AbstractHandlerTest (eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)97 QName (javax.xml.namespace.QName)29 ArrayList (java.util.ArrayList)26 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)25 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)23 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)22 Group (eu.esdihumboldt.hale.common.instance.model.Group)15 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)12 Geometry (com.vividsolutions.jts.geom.Geometry)12 FamilyInstance (eu.esdihumboldt.hale.common.instance.model.FamilyInstance)10 Polygon (com.vividsolutions.jts.geom.Polygon)9 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)8 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)8 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)8 HashSet (java.util.HashSet)8 Point (com.vividsolutions.jts.geom.Point)7