Search in sources :

Example 11 with BoundContainer

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());
}
Also used : BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) Test(org.junit.Test)

Example 12 with BoundContainer

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();
    }
}
Also used : EntityByTypeThenIdComparator(org.openstreetmap.osmosis.core.sort.v0_6.EntityByTypeThenIdComparator) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainerComparator(org.openstreetmap.osmosis.core.sort.v0_6.EntityContainerComparator) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Example 13 with BoundContainer

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();
    }
}
Also used : AllEntityDao(org.openstreetmap.osmosis.apidb.v0_6.impl.AllEntityDao) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) SchemaVersionValidator(org.openstreetmap.osmosis.apidb.v0_6.impl.SchemaVersionValidator)

Example 14 with BoundContainer

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);
}
Also used : NodeContainerIterator(org.openstreetmap.osmosis.core.container.v0_6.NodeContainerIterator) WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) MultipleSourceIterator(org.openstreetmap.osmosis.core.store.MultipleSourceIterator) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) RelationContainerIterator(org.openstreetmap.osmosis.core.container.v0_6.RelationContainerIterator) ReleasableIterator(org.openstreetmap.osmosis.core.lifecycle.ReleasableIterator) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) WayContainerIterator(org.openstreetmap.osmosis.core.container.v0_6.WayContainerIterator) BoundContainerIterator(org.openstreetmap.osmosis.core.container.v0_6.BoundContainerIterator) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer)

Example 15 with BoundContainer

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));
    }
}
Also used : BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Aggregations

BoundContainer (org.openstreetmap.osmosis.core.container.v0_6.BoundContainer)29 Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)22 Test (org.junit.Test)12 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)10 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)9 RelationContainer (org.openstreetmap.osmosis.core.container.v0_6.RelationContainer)7 WayContainer (org.openstreetmap.osmosis.core.container.v0_6.WayContainer)7 Date (java.util.Date)5 OsmosisRuntimeException (org.openstreetmap.osmosis.core.OsmosisRuntimeException)5 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)5 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 ReleasableIterator (org.openstreetmap.osmosis.core.lifecycle.ReleasableIterator)4 MultipleSourceIterator (org.openstreetmap.osmosis.core.store.MultipleSourceIterator)4 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)3 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)3 SinkEntityInspector (org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector)3 Osmformat (crosby.binary.Osmformat)2