Search in sources :

Example 6 with BoundContainer

use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.

the class FastXmlParser method readOsm.

/**
 * Parses the xml and sends all data to the sink.
 */
public void readOsm() {
    try {
        String generator = null;
        if (reader.nextTag() == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals("osm")) {
            String fileVersion;
            fileVersion = reader.getAttributeValue(null, ATTRIBUTE_NAME_VERSION);
            if (!XmlConstants.OSM_VERSION.equals(fileVersion)) {
                LOG.warning("Expected version " + XmlConstants.OSM_VERSION + " but received " + fileVersion + ".");
            }
            generator = reader.getAttributeValue(null, ATTRIBUTE_NAME_GENERATOR);
            reader.nextTag();
            if (reader.getEventType() == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals(ELEMENT_NAME_BOUND)) {
                LOG.fine("Legacy <bound> element encountered.");
                sink.process(new BoundContainer(readBound()));
            }
            if (reader.getEventType() == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals(ELEMENT_NAME_BOUNDS)) {
                sink.process(new BoundContainer(readBounds(generator)));
            }
            while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
                // Node, way, relation
                if (reader.getLocalName().equals(ELEMENT_NAME_NODE)) {
                    sink.process(new NodeContainer(readNode()));
                } else if (reader.getLocalName().equals(ELEMENT_NAME_WAY)) {
                    sink.process(new WayContainer(readWay()));
                } else if (reader.getLocalName().equals(ELEMENT_NAME_RELATION)) {
                    sink.process(new RelationContainer(readRelation()));
                } else {
                    readUnknownElement();
                }
            }
        } else {
            throw new XMLStreamException();
        }
    } catch (Exception e) {
        throw new OsmosisRuntimeException(e);
    }
}
Also used : WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) XMLStreamException(javax.xml.stream.XMLStreamException) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException) XMLStreamException(javax.xml.stream.XMLStreamException) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Example 7 with BoundContainer

use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.

the class LegacyBoundElementProcessor method end.

/**
 * {@inheritDoc}
 */
@Override
public void end() {
    getSink().process(new BoundContainer(bound));
    bound = null;
}
Also used : BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer)

Example 8 with BoundContainer

use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.

the class XmlDownloader method run.

/**
 * Reads all data from the server and send it to the {@link Sink}.
 */
public void run() {
    try {
        mySink.initialize(Collections.<String, Object>emptyMap());
        SAXParser parser = createParser();
        InputStream inputStream = getInputStream(myBaseUrl + "/map?bbox=" + myLeft + "," + myBottom + "," + myRight + "," + myTop);
        // First send the Bound down the pipeline
        mySink.process(new BoundContainer(new Bound(myRight, myLeft, myTop, myBottom, myBaseUrl)));
        try {
            parser.parse(inputStream, new OsmHandler(mySink, true));
        } finally {
            inputStream.close();
            inputStream = null;
        }
        mySink.complete();
    } catch (SAXParseException e) {
        throw new OsmosisRuntimeException("Unable to parse xml" + ".  publicId=(" + e.getPublicId() + "), systemId=(" + e.getSystemId() + "), lineNumber=" + e.getLineNumber() + ", columnNumber=" + e.getColumnNumber() + ".", e);
    } catch (SAXException e) {
        throw new OsmosisRuntimeException("Unable to parse XML.", e);
    } catch (IOException e) {
        throw new OsmosisRuntimeException("Unable to read XML.", e);
    } finally {
        mySink.close();
        cleanup();
    }
}
Also used : BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) GZIPInputStream(java.util.zip.GZIPInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) SAXParser(javax.xml.parsers.SAXParser) OsmHandler(org.openstreetmap.osmosis.xml.v0_6.impl.OsmHandler) IOException(java.io.IOException) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException) SAXException(org.xml.sax.SAXException)

Example 9 with BoundContainer

use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.

the class BoundSetterTest method overwriteBoundTest.

/**
 * Tests the bound setting.
 */
@Test
public void overwriteBoundTest() {
    SinkEntityInspector inspector = new SinkEntityInspector();
    Bound newBound = new Bound(2, 1, 4, 3, "NewBound");
    BoundSetter setter = new BoundSetter(newBound);
    setter.setSink(inspector);
    setter.process(new BoundContainer(new Bound("Test")));
    setter.process(new NodeContainer(new Node(new CommonEntityData(1, 1, new Date(), OsmUser.NONE, 1), 1, 1)));
    setter.complete();
    setter.close();
    Iterator<EntityContainer> iterator = inspector.getProcessedEntities().iterator();
    EntityContainer ec = iterator.next();
    Assert.assertEquals(EntityType.Bound, ec.getEntity().getType());
    Bound bound = (Bound) ec.getEntity();
    Assert.assertEquals(bound, newBound);
    // Ensure there is no second bound
    ec = iterator.next();
    Assert.assertEquals(EntityType.Node, ec.getEntity().getType());
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) SinkEntityInspector(org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector) Date(java.util.Date) Test(org.junit.Test)

Example 10 with BoundContainer

use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.

the class BoundingBoxFilterTest method testProcessBoundContainer1.

/**
 * Test passing a Bound which intersects the filter area.
 */
@Test
public final void testProcessBoundContainer1() {
    Bound compareBound;
    simpleAreaFilter.process(new BoundContainer(intersectingBound));
    simpleAreaFilter.complete();
    compareBound = (Bound) entityInspector.getLastEntityContainer().getEntity();
    assertTrue(Double.compare(compareBound.getRight(), 20) == 0);
    assertTrue(Double.compare(compareBound.getLeft(), 10) == 0);
    assertTrue(Double.compare(compareBound.getTop(), 20) == 0);
    assertTrue(Double.compare(compareBound.getBottom(), 10) == 0);
    assertTrue(compareBound.getOrigin().equals("intersecting"));
}
Also used : BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) Test(org.junit.Test)

Aggregations

BoundContainer (org.openstreetmap.osmosis.core.container.v0_6.BoundContainer)29 Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)22 Test (org.junit.Test)12 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)10 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)9 RelationContainer (org.openstreetmap.osmosis.core.container.v0_6.RelationContainer)7 WayContainer (org.openstreetmap.osmosis.core.container.v0_6.WayContainer)7 Date (java.util.Date)5 OsmosisRuntimeException (org.openstreetmap.osmosis.core.OsmosisRuntimeException)5 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)5 BoundContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.BoundContainerIterator)4 NodeContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.NodeContainerIterator)4 RelationContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.RelationContainerIterator)4 WayContainerIterator (org.openstreetmap.osmosis.core.container.v0_6.WayContainerIterator)4 ReleasableIterator (org.openstreetmap.osmosis.core.lifecycle.ReleasableIterator)4 MultipleSourceIterator (org.openstreetmap.osmosis.core.store.MultipleSourceIterator)4 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)3 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)3 SinkEntityInspector (org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector)3 Osmformat (crosby.binary.Osmformat)2