Search in sources :

Example 16 with BoundContainer

use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.

the class PbfReader method run.

@Override
public void run() {
    StreamSplitter streamSplitter = null;
    ExecutorService executorService;
    if (workers > 0) {
        executorService = Executors.newFixedThreadPool(workers);
    } else {
        executorService = MoreExecutors.newDirectExecutorService();
    }
    try {
        InputStream inputStream = supplier.get();
        // Create a stream splitter to break the PBF stream into blobs.
        streamSplitter = new StreamSplitter(new DataInputStream(inputStream));
        // Obtain the header block.
        Osmformat.HeaderBlock header = new HeaderSeeker().apply(streamSplitter);
        // Get the pipeline metadata (e.g. do ways include location information) from header.
        Map<String, Object> metadata = new HeaderMetadataReader().apply(header);
        sink.initialize(metadata);
        // Get Bound information from the header.
        BoundContainer bound = new HeaderBoundReader().apply(header);
        sink.process(bound);
        // Process all blobs of data in the stream using threads from the
        // executor service. We allow the decoder to issue an extra blob
        // than there are workers to ensure there is another blob
        // immediately ready for processing when a worker thread completes.
        // The main thread is responsible for splitting blobs from the
        // request stream, and sending decoded entities to the sink.
        PbfDecoder pbfDecoder = new PbfDecoder(streamSplitter, executorService, workers + 1, sink);
        pbfDecoder.run();
        sink.complete();
    } finally {
        sink.close();
        executorService.shutdownNow();
        if (streamSplitter != null) {
            streamSplitter.close();
        }
    }
}
Also used : HeaderBoundReader(org.openstreetmap.osmosis.pbf2.v0_6.impl.HeaderBoundReader) HeaderMetadataReader(org.openstreetmap.osmosis.pbf2.v0_6.impl.HeaderMetadataReader) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DataInputStream(java.io.DataInputStream) Osmformat(crosby.binary.Osmformat) HeaderSeeker(org.openstreetmap.osmosis.pbf2.v0_6.impl.HeaderSeeker) BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) PbfDecoder(org.openstreetmap.osmosis.pbf2.v0_6.impl.PbfDecoder) ExecutorService(java.util.concurrent.ExecutorService) StreamSplitter(org.openstreetmap.osmosis.pbf2.v0_6.impl.StreamSplitter)

Example 17 with BoundContainer

use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.

the class HeaderBoundReader method apply.

@Override
public BoundContainer apply(Osmformat.HeaderBlock header) {
    Bound bound;
    if (header.hasBbox()) {
        Osmformat.HeaderBBox bbox = header.getBbox();
        bound = new Bound(bbox.getRight() * COORDINATE_SCALING_FACTOR, bbox.getLeft() * COORDINATE_SCALING_FACTOR, bbox.getTop() * COORDINATE_SCALING_FACTOR, bbox.getBottom() * COORDINATE_SCALING_FACTOR, header.getSource());
    } else {
        bound = new Bound(header.getSource());
    }
    return new BoundContainer(bound);
}
Also used : BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) Osmformat(crosby.binary.Osmformat)

Example 18 with BoundContainer

use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.

the class BoundSetterTest method removeExistingBoundTest.

/**
 * Tests the bound removal.
 */
@Test
public void removeExistingBoundTest() {
    SinkEntityInspector inspector = new SinkEntityInspector();
    BoundSetter setter = new BoundSetter(null);
    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();
    EntityContainer ec = inspector.getProcessedEntities().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 19 with BoundContainer

use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.

the class ApidbReader 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 = new EntitySnapshotReader(entityDao.getHistory(), snapshotInstant)) {
            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) EntitySnapshotReader(org.openstreetmap.osmosis.apidb.v0_6.impl.EntitySnapshotReader) SchemaVersionValidator(org.openstreetmap.osmosis.apidb.v0_6.impl.SchemaVersionValidator)

Example 20 with BoundContainer

use of org.openstreetmap.osmosis.core.container.v0_6.BoundContainer in project osmosis by openstreetmap.

the class BoundingBoxFilter method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(BoundContainer boundContainer) {
    Bound newBound;
    /*
		 * The order of calling intersect is important because the first non-empty origin string
		 * will be used for the resulting Bound, and we want the origin string from the pipeline
		 * Bound to be used.
		 */
    newBound = boundContainer.getEntity().intersect(bound);
    // intersect will return null if there is no overlapping area
    if (newBound != null) {
        // Send on a bound element clipped to the area
        super.process(new BoundContainer(newBound));
    }
}
Also used : BoundContainer(org.openstreetmap.osmosis.core.container.v0_6.BoundContainer) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound)

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