Search in sources :

Example 41 with Bound

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

the class BoundsElementProcessor method begin.

/**
 * {@inheritDoc}
 */
@Override
public void begin(Attributes attributes) {
    double bottom = getRequiredDoubleValue(attributes, XmlConstants.ATTRIBUTE_NAME_MINLAT);
    double left = getRequiredDoubleValue(attributes, XmlConstants.ATTRIBUTE_NAME_MINLON);
    double top = getRequiredDoubleValue(attributes, XmlConstants.ATTRIBUTE_NAME_MAXLAT);
    double right = getRequiredDoubleValue(attributes, XmlConstants.ATTRIBUTE_NAME_MAXLON);
    String origin = attributes.getValue(XmlConstants.ATTRIBUTE_NAME_ORIGIN);
    if (origin == null) {
        origin = defaultOrigin;
    }
    bound = new Bound(right, left, top, bottom, origin);
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound)

Example 42 with Bound

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

the class FastXmlParser method readBound.

private Bound readBound() throws Exception {
    String boxString;
    String origin;
    String[] boundStrings;
    Double right;
    Double left;
    Double top;
    Double bottom;
    boxString = reader.getAttributeValue(null, ATTRIBUTE_NAME_BOX);
    if (boxString == null) {
        throw new OsmosisRuntimeException("Missing required box attribute of bound element");
    }
    boundStrings = boxString.split(",");
    if (boundStrings.length != 4) {
        throw new OsmosisRuntimeException("Badly formed box attribute of bound element");
    }
    try {
        bottom = Double.parseDouble(boundStrings[0]);
        left = Double.parseDouble(boundStrings[1]);
        top = Double.parseDouble(boundStrings[2]);
        right = Double.parseDouble(boundStrings[3]);
    } catch (NumberFormatException e) {
        throw new OsmosisRuntimeException("Can't parse box attribute of bound element", e);
    }
    origin = reader.getAttributeValue(null, ATTRIBUTE_NAME_ORIGIN);
    if (origin == null || origin.equals("")) {
        throw new OsmosisRuntimeException("Origin attribute of bound element is empty or missing.");
    }
    Bound bound = new Bound(right, left, top, bottom, origin);
    reader.nextTag();
    reader.nextTag();
    return bound;
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Example 43 with Bound

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

the class LegacyBoundElementProcessor method begin.

/**
 * {@inheritDoc}
 */
@Override
public void begin(Attributes attributes) {
    String boxString;
    String origin;
    String[] boundStrings;
    Double right;
    Double left;
    Double top;
    Double bottom;
    boxString = attributes.getValue(ATTRIBUTE_NAME_BOX);
    if (boxString == null) {
        throw new OsmosisRuntimeException("Missing required box attribute of bound element");
    }
    boundStrings = boxString.split(",");
    if (boundStrings.length != 4) {
        throw new OsmosisRuntimeException("Badly formed box attribute of bound element");
    }
    try {
        bottom = Double.parseDouble(boundStrings[0]);
        left = Double.parseDouble(boundStrings[1]);
        top = Double.parseDouble(boundStrings[2]);
        right = Double.parseDouble(boundStrings[3]);
    } catch (NumberFormatException e) {
        throw new OsmosisRuntimeException("Can't parse box attribute of bound element", e);
    }
    origin = attributes.getValue(ATTRIBUTE_NAME_ORIGIN);
    if (origin == null || origin.equals("")) {
        throw new OsmosisRuntimeException("Origin attribute of bound element is empty or missing.");
    }
    bound = new Bound(right, left, top, bottom, origin);
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Example 44 with Bound

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

the class MergeBoundTest method testBothHaveBounds.

/**
 * Test the proper computation of the union bound iff both sources
 * have bounds.
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testBothHaveBounds() throws Exception {
    Bound bound0 = new Bound(1, 2, 4, 3, "source1");
    RunnableSource source0 = new BoundSource(bound0, true);
    Bound bound1 = new Bound(5, 6, 8, 7, "source2");
    RunnableSource source1 = new BoundSource(bound1, true);
    EntityMerger merger = new EntityMerger(ConflictResolutionMethod.LatestSource, 1, BoundRemovedAction.Ignore);
    SinkEntityInspector merged = RunTaskUtilities.run(merger, source0, source1);
    List<EntityContainer> mergedList = createList(merged.getProcessedEntities());
    Assert.assertEquals(3, mergedList.size());
    Assert.assertEquals(EntityType.Bound, mergedList.get(0).getEntity().getType());
    // Check the bound
    Bound bound01 = (Bound) mergedList.get(0).getEntity();
    Assert.assertEquals(bound0.union(bound1), bound01);
    for (int i = 1; i < mergedList.size(); i++) {
        Assert.assertEquals(EntityType.Node, mergedList.get(i).getEntity().getType());
    }
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) SinkEntityInspector(org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector) RunnableSource(org.openstreetmap.osmosis.core.task.v0_6.RunnableSource) Test(org.junit.Test)

Example 45 with Bound

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

the class OsmHandlerTest method testBoundsNoOrigin.

/**
 * Test the parsing of a bound element as returned by the OSM API
 * without an origin.
 */
@Test
public void testBoundsNoOrigin() {
    parseString(OSM_PREFIX + "<bounds minlat=\"-1.234\" minlon=\"-1.234\" maxlat=\"1.234\" maxlon=\"1.234\"/>" + OSM_SUFFIX);
    Bound b = (Bound) entityInspector.getLastEntityContainer().getEntity();
    assertEquals(-1.234, b.getLeft(), 1E-6);
    assertEquals(-1.234, b.getBottom(), 1E-6);
    assertEquals(1.234, b.getRight(), 1E-6);
    assertEquals(1.234, b.getTop(), 1E-6);
    assertNull(b.getOrigin());
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) Test(org.junit.Test)

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