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);
}
}
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;
}
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();
}
}
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());
}
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"));
}
Aggregations