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