use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.
the class BoundingBoxFilterTest method testProcessBoundContainer2.
/**
* Test the non-passing of a Bound which does not intersect the filter area.
*/
@Test
public final void testProcessBoundContainer2() {
simpleAreaFilter.process(new BoundContainer(nonIntersectingBound));
simpleAreaFilter.complete();
assertNull(entityInspector.getLastEntityContainer());
}
use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.
the class EntityMerger method run.
/**
* {@inheritDoc}
*/
public void run() {
try {
EntityContainerComparator comparator;
EntityContainer entityContainer0 = null;
EntityContainer entityContainer1 = null;
// Create a comparator for comparing two entities by type and identifier.
comparator = new EntityContainerComparator(new EntityByTypeThenIdComparator());
// We can't get meaningful data from the initialize data on the
// input streams, so pass empty meta data to the sink and discard
// the input meta data.
postbox0.outputInitialize();
postbox1.outputInitialize();
sink.initialize(Collections.<String, Object>emptyMap());
// BEGIN bound special handling
// If there is a bound, it's going to be the first object
// in a properly sorted stream
entityContainer0 = nextOrNull(postbox0);
entityContainer1 = nextOrNull(postbox1);
// on both streams - no data implies no bound
if (entityContainer0 != null && entityContainer1 != null) {
Bound bound0 = null;
Bound bound1 = null;
// If there are any bounds upstream, eat them up
if (entityContainer0.getEntity().getType() == EntityType.Bound) {
bound0 = (Bound) entityContainer0.getEntity();
entityContainer0 = nextOrNull(postbox0);
}
if (entityContainer1.getEntity().getType() == EntityType.Bound) {
bound1 = (Bound) entityContainer1.getEntity();
entityContainer1 = nextOrNull(postbox1);
}
// to be smaller than the actual data, which is bad)
if (bound0 != null && bound1 != null) {
sink.process(new BoundContainer(bound0.union(bound1)));
} else if ((bound0 != null && bound1 == null) || (bound0 == null && bound1 != null)) {
handleBoundRemoved(bound0 == null);
}
}
// We continue in the comparison loop while both sources still have data.
while ((entityContainer0 != null || postbox0.hasNext()) && (entityContainer1 != null || postbox1.hasNext())) {
long comparisonResult;
// Get the next input data where required.
if (entityContainer0 == null) {
entityContainer0 = postbox0.getNext();
}
if (entityContainer1 == null) {
entityContainer1 = postbox1.getNext();
}
// Compare the two entities.
comparisonResult = comparator.compare(entityContainer0, entityContainer1);
if (comparisonResult < 0) {
// Entity 0 doesn't exist on the other source and can be
// sent straight through.
sink.process(entityContainer0);
entityContainer0 = null;
} else if (comparisonResult > 0) {
// Entity 1 doesn't exist on the other source and can be
// sent straight through.
sink.process(entityContainer1);
entityContainer1 = null;
} else {
// The entity exists on both sources so we must resolve the conflict.
if (conflictResolutionMethod.equals(ConflictResolutionMethod.Timestamp)) {
int timestampComparisonResult;
timestampComparisonResult = entityContainer0.getEntity().getTimestamp().compareTo(entityContainer1.getEntity().getTimestamp());
if (timestampComparisonResult < 0) {
sink.process(entityContainer1);
} else if (timestampComparisonResult > 0) {
sink.process(entityContainer0);
} else {
// If both have identical timestamps, use the second source.
sink.process(entityContainer1);
}
} else if (conflictResolutionMethod.equals(ConflictResolutionMethod.LatestSource)) {
sink.process(entityContainer1);
} else if (conflictResolutionMethod.equals(ConflictResolutionMethod.Version)) {
int version0 = entityContainer0.getEntity().getVersion();
int version1 = entityContainer1.getEntity().getVersion();
if (version0 < version1) {
sink.process(entityContainer1);
} else if (version0 > version1) {
sink.process(entityContainer0);
} else {
// If both have identical versions, use the second source.
sink.process(entityContainer1);
}
} else {
throw new OsmosisRuntimeException("Conflict resolution method " + conflictResolutionMethod + " is not recognized.");
}
entityContainer0 = null;
entityContainer1 = null;
}
}
// Any remaining entities on either source can be sent straight through.
while (entityContainer0 != null || postbox0.hasNext()) {
if (entityContainer0 == null) {
entityContainer0 = postbox0.getNext();
}
sink.process(entityContainer0);
entityContainer0 = null;
}
while (entityContainer1 != null || postbox1.hasNext()) {
if (entityContainer1 == null) {
entityContainer1 = postbox1.getNext();
}
sink.process(entityContainer1);
entityContainer1 = null;
}
sink.complete();
postbox0.outputComplete();
postbox1.outputComplete();
} finally {
sink.close();
postbox0.outputRelease();
postbox1.outputRelease();
}
}
use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.
the class ApidbCurrentReader method runImpl.
/**
* Runs the task implementation. This is called by the run method within a transaction.
*
* @param dbCtx
* Used to access the database.
*/
protected void runImpl(DatabaseContext2 dbCtx) {
try {
AllEntityDao entityDao;
sink.initialize(Collections.<String, Object>emptyMap());
new SchemaVersionValidator(loginCredentials, preferences).validateVersion(ApidbVersionConstants.SCHEMA_MIGRATIONS);
entityDao = new AllEntityDao(dbCtx.getJdbcTemplate());
sink.process(new BoundContainer(new Bound("Osmosis " + OsmosisConstants.VERSION)));
try (ReleasableIterator<EntityContainer> reader = entityDao.getCurrent()) {
while (reader.hasNext()) {
sink.process(reader.next());
}
}
sink.complete();
} finally {
sink.close();
}
}
use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.
the class PostgreSqlDatasetContext method iterate.
/**
* {@inheritDoc}
*/
@Override
public ReleasableIterator<EntityContainer> iterate() {
List<Bound> bounds;
List<ReleasableIterator<EntityContainer>> sources;
if (!initialized) {
initialize();
}
// Build the bounds list.
bounds = new ArrayList<Bound>();
bounds.add(new Bound("Osmosis " + OsmosisConstants.VERSION));
sources = new ArrayList<ReleasableIterator<EntityContainer>>();
sources.add(new UpcastIterator<EntityContainer, BoundContainer>(new BoundContainerIterator(new ReleasableAdaptorForIterator<Bound>(bounds.iterator()))));
sources.add(new UpcastIterator<EntityContainer, NodeContainer>(new NodeContainerIterator(nodeDao.iterate())));
sources.add(new UpcastIterator<EntityContainer, WayContainer>(new WayContainerIterator(wayDao.iterate())));
sources.add(new UpcastIterator<EntityContainer, RelationContainer>(new RelationContainerIterator(relationDao.iterate())));
return new MultipleSourceIterator<EntityContainer>(sources);
}
use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.
the class OsmosisBinaryParser method parse.
@Override
public void parse(Osmformat.HeaderBlock block) {
for (String s : block.getRequiredFeaturesList()) {
if (s.equals("OsmSchema-V0.6")) {
// We can parse this.
continue;
}
if (s.equals("DenseNodes")) {
// We can parse this.
continue;
}
throw new OsmosisRuntimeException("File requires unknown feature: " + s);
}
if (block.hasBbox()) {
String source = OsmosisConstants.VERSION;
if (block.hasSource()) {
source = block.getSource();
}
double multiplier = .000000001;
double rightf = block.getBbox().getRight() * multiplier;
double leftf = block.getBbox().getLeft() * multiplier;
double topf = block.getBbox().getTop() * multiplier;
double bottomf = block.getBbox().getBottom() * multiplier;
Bound bounds = new Bound(rightf, leftf, topf, bottomf, source);
sink.process(new BoundContainer(bounds));
}
}
Aggregations