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