Search in sources :

Example 16 with Bound

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

the class BoundSetterTest method removeNoBoundTest.

/**
 * Tests the bound removal when there is no bound upstream.
 */
@Test
public void removeNoBoundTest() {
    SinkEntityInspector inspector = new SinkEntityInspector();
    BoundSetter setter = new BoundSetter(null);
    setter.setSink(inspector);
    setter.process(new NodeContainer(new Node(new CommonEntityData(1, 1, new Date(), OsmUser.NONE, 1), 1, 1)));
    setter.complete();
    setter.close();
    EntityContainer ec = inspector.getProcessedEntities().iterator().next();
    Assert.assertEquals(EntityType.Node, ec.getEntity().getType());
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) 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 17 with Bound

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

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

the class BoundingBoxFilter method isNodeWithinArea.

/**
 * {@inheritDoc}
 */
@Override
protected boolean isNodeWithinArea(Node node) {
    double latitude;
    double longitude;
    latitude = node.getLatitude();
    longitude = node.getLongitude();
    /*
		 * Check the node coordinates against the bounding box by comparing them to each "simple"
		 * bound.
		 */
    for (Bound b : bound.toSimpleBound()) {
        if (b.getTop() >= latitude && b.getBottom() <= latitude && b.getLeft() <= longitude && b.getRight() >= longitude) {
            return true;
        }
    }
    return false;
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound)

Example 19 with Bound

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

the class PolygonFilter method simpleBoundIntersect.

/**
 * Get the simple intersection of this polygon with the passed Bound.
 *
 * @param bound
 *            Bound with which to intersect. Must be "simple" (not cross antimeridian).
 * @return Bound resulting rectangular area after intersection
 */
private Bound simpleBoundIntersect(Bound bound) {
    Rectangle2D r;
    double width, height;
    Bound newBound = null;
    // make a copy so we don't disturb the original
    Area a2 = (Area) area.clone();
    if (bound.getLeft() > bound.getRight()) {
        return null;
    }
    width = bound.getRight() - bound.getLeft();
    height = bound.getTop() - bound.getBottom();
    /*
		 * Perform the intersect against the Area itself instead of its bounding box for maximum
		 * precision.
		 */
    a2.intersect(new Area(new Rectangle2D.Double(bound.getLeft(), bound.getBottom(), width, height)));
    if (!a2.isEmpty()) {
        r = a2.getBounds2D();
        newBound = new Bound(r.getMaxX(), r.getMinX(), r.getMaxY(), r.getMinY(), bound.getOrigin());
    }
    return newBound;
}
Also used : Area(java.awt.geom.Area) Rectangle2D(java.awt.geom.Rectangle2D) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound)

Example 20 with Bound

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

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