Search in sources :

Example 6 with Bound

use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.

the class OsmHandlerTest method testBoundsOriginInheritance.

/**
 * Test the inheritance of generator to the origin.
 */
@Test
public void testBoundsOriginInheritance() {
    parseString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<osm version=\"0.6\" generator=\"somegenerator\">" + "<bounds minlat=\"-1.234\" minlon=\"-1.234\" maxlat=\"1.234\" maxlon=\"1.234\"/>" + "</osm>");
    Bound b = (Bound) entityInspector.getLastEntityContainer().getEntity();
    assertEquals("somegenerator", b.getOrigin());
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) Test(org.junit.Test)

Example 7 with Bound

use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.

the class OsmHandlerTest method testBoundElement1.

/**
 * Test a normal, well-formed bound element.
 */
@Test
public final void testBoundElement1() {
    parseString(OSM_PREFIX + "<bound box=\"-12.34567,-23.45678,34.56789,45.67891\"" + " origin=\"someorigin\"/>" + OSM_SUFFIX);
    Bound b = (Bound) entityInspector.getLastEntityContainer().getEntity();
    assertTrue(Double.compare(b.getRight(), 45.67891) == 0 && Double.compare(b.getLeft(), -23.45678) == 0 && Double.compare(b.getTop(), 34.56789) == 0 && Double.compare(b.getBottom(), -12.34567) == 0);
    assertTrue(b.getOrigin().equals("someorigin"));
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) Test(org.junit.Test)

Example 8 with Bound

use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.

the class OsmWriterTest method testProcess4.

/**
 * Test processing a Bound after a Node.
 */
@Test(expected = OsmosisRuntimeException.class)
public final void testProcess4() {
    testOsmWriter.process(new NodeContainer(new Node(new CommonEntityData(1234, 0, new Date(), new OsmUser(12, "OsmosisTest"), 0, new ArrayList<Tag>()), 20, 20)));
    testOsmWriter.process(new BoundContainer(new Bound("source")));
    fail("Expected to throw an exception.");
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) OsmUser(org.openstreetmap.osmosis.core.domain.v0_6.OsmUser) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) ArrayList(java.util.ArrayList) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Bound

use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.

the class OsmWriterTest method testProcess9.

/**
 * Test processing a Bound after a Relation.
 */
@Test(expected = OsmosisRuntimeException.class)
public final void testProcess9() {
    Relation testRelation;
    testRelation = new Relation(new CommonEntityData(3456, 0, new Date(), new OsmUser(12, "OsmosisTest"), 0));
    testRelation.getMembers().add(new RelationMember(1234, EntityType.Node, "role1"));
    testRelation.getTags().add(new Tag("test_key1", "test_value1"));
    testOsmWriter.process(new RelationContainer(testRelation));
    testOsmWriter.process(new BoundContainer(new Bound("source")));
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember) OsmUser(org.openstreetmap.osmosis.core.domain.v0_6.OsmUser) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Date(java.util.Date) Test(org.junit.Test)

Example 10 with Bound

use of org.openstreetmap.osmosis.core.domain.v0_6.Bound 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)

Aggregations

Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)46 Test (org.junit.Test)25 BoundContainer (org.openstreetmap.osmosis.core.container.v0_6.BoundContainer)22 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)19 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)14 SinkEntityInspector (org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector)14 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)13 Date (java.util.Date)11 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)11 OsmosisRuntimeException (org.openstreetmap.osmosis.core.OsmosisRuntimeException)7 RelationContainer (org.openstreetmap.osmosis.core.container.v0_6.RelationContainer)6 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)6 WayContainer (org.openstreetmap.osmosis.core.container.v0_6.WayContainer)5 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)5 RunnableSource (org.openstreetmap.osmosis.core.task.v0_6.RunnableSource)5 Osmformat (crosby.binary.Osmformat)4 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