Search in sources :

Example 1 with ShapeSchemaReader

use of eu.esdihumboldt.hale.io.shp.reader.internal.ShapeSchemaReader 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 2 with ShapeSchemaReader

use of eu.esdihumboldt.hale.io.shp.reader.internal.ShapeSchemaReader in project hale by halestudio.

the class FilterTest method simpleSchemaTestECQL.

@Test
public void simpleSchemaTestECQL() 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 FilterGeoECqlImpl("NEV = 'Piritulus'");
        Filter foulfilter = new FilterGeoECqlImpl("HERP = 'DERP'");
        Filter foulfilter1 = new FilterGeoECqlImpl("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)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)2 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)2 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)2 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)2 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)2 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)2 ShapeInstanceReader (eu.esdihumboldt.hale.io.shp.reader.internal.ShapeInstanceReader)2 ShapeSchemaReader (eu.esdihumboldt.hale.io.shp.reader.internal.ShapeSchemaReader)2 Test (org.junit.Test)2