Search in sources :

Example 1 with GMLFilterGeometry

use of org.geotools.gml.GMLFilterGeometry in project exist by eXist-db.

the class GMLIndexTest method lowLevelSearch.

@Test
public void lowLevelSearch() throws EXistException, SAXException, ParserConfigurationException, SpatialIndexException, IOException {
    GMLHandlerJTS geometryHandler = new GeometryHandler();
    GMLFilterGeometry geometryFilter = new GMLFilterGeometry(geometryHandler);
    GMLFilterDocument handler = new GMLFilterDocument(geometryFilter);
    final BrokerPool pool = server.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        AbstractGMLJDBCIndexWorker indexWorker = (AbstractGMLJDBCIndexWorker) broker.getIndexController().getWorkerByIndexId(AbstractGMLJDBCIndex.ID);
        // Unplugged
        if (indexWorker != null) {
            SAXParserFactory factory = ExistSAXParserFactory.getSAXParserFactory();
            factory.setNamespaceAware(true);
            InputSource src = new InputSource(new StringReader(IN_MEMORY_GML));
            SAXParser parser = factory.newSAXParser();
            XMLReader reader = parser.getXMLReader();
            SAXAdapter adapter = new SAXAdapter();
            reader.setContentHandler(handler);
            reader.setProperty("http://xml.org/sax/properties/lexical-handler", adapter);
            reader.parse(src);
            Geometry EPSG4326_geometry = indexWorker.transformGeometry(currentGeometry, "osgb:BNG", "EPSG:4326");
            assertNotNull(EPSG4326_geometry);
            NodeSet ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.EQUALS);
            assertTrue(ns.getLength() > 0);
            ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.DISJOINT);
            assertTrue(ns.getLength() > 0);
            ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.INTERSECTS);
            assertTrue(ns.getLength() > 0);
            ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.TOUCHES);
            // assertTrue(ns.getLength() > 0);
            ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.CROSSES);
            // assertTrue(ns.getLength() > 0);
            ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.WITHIN);
            assertTrue(ns.getLength() > 0);
            ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.CONTAINS);
            assertTrue(ns.getLength() > 0);
        // ns = ((GMLIndexWorker)index.getWorker()).search(broker, EPSG4326_geometry, SpatialOperator.OVERLAPS);
        // assertTrue(ns.getLength() > 0);
        }
    }
}
Also used : NodeSet(org.exist.dom.persistent.NodeSet) FileInputSource(org.exist.util.FileInputSource) GMLHandlerJTS(org.geotools.gml.GMLHandlerJTS) GMLFilterDocument(org.geotools.gml.GMLFilterDocument) Geometry(com.vividsolutions.jts.geom.Geometry) GMLFilterGeometry(org.geotools.gml.GMLFilterGeometry) DBBroker(org.exist.storage.DBBroker) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) SAXAdapter(org.exist.dom.memtree.SAXAdapter) GMLFilterGeometry(org.geotools.gml.GMLFilterGeometry) BrokerPool(org.exist.storage.BrokerPool) SAXParserFactory(javax.xml.parsers.SAXParserFactory) ExistSAXParserFactory(org.exist.util.ExistSAXParserFactory)

Example 2 with GMLFilterGeometry

use of org.geotools.gml.GMLFilterGeometry in project chordatlas by twak.

the class Footprints method parse.

public static Callback parse(InputSource input) throws IOException, SAXException {
    // parse xml
    XMLReader reader = XMLReaderFactory.createXMLReader();
    Callback callback = new Callback();
    GMLFilterGeometry geometryCallback = new GMLFilterGeometry(callback);
    GMLFilterDocument gmlCallback = new GMLFilterDocument(geometryCallback);
    reader.setContentHandler(gmlCallback);
    ComplexContentHandler ch;
    reader.parse(input);
    return callback;
}
Also used : ComplexContentHandler(org.geotools.xml.handlers.xsi.ComplexContentHandler) GMLFilterDocument(org.geotools.gml.GMLFilterDocument) GMLFilterGeometry(org.geotools.gml.GMLFilterGeometry) XMLReader(org.xml.sax.XMLReader)

Aggregations

GMLFilterDocument (org.geotools.gml.GMLFilterDocument)2 GMLFilterGeometry (org.geotools.gml.GMLFilterGeometry)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 StringReader (java.io.StringReader)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 SAXAdapter (org.exist.dom.memtree.SAXAdapter)1 NodeSet (org.exist.dom.persistent.NodeSet)1 BrokerPool (org.exist.storage.BrokerPool)1 DBBroker (org.exist.storage.DBBroker)1 ExistSAXParserFactory (org.exist.util.ExistSAXParserFactory)1 FileInputSource (org.exist.util.FileInputSource)1 GMLHandlerJTS (org.geotools.gml.GMLHandlerJTS)1 ComplexContentHandler (org.geotools.xml.handlers.xsi.ComplexContentHandler)1 XMLReader (org.xml.sax.XMLReader)1