I am importing a osm.pbf file into my java application using Osmosis like this:
data class MapObject (
val lat: Double,
val lon: Double,
val id: Long
)
class OsmReader : Sink {
val data = mutableListOf<MapObject>()
override fun close() {}
override fun complete() {}
override fun initialize(metaData: MutableMap<String, Any>?) {}
override fun process(entityContainer: EntityContainer?) {
if (entityContainer is NodeContainer) {
val node = entityContainer.entity
data.add( MapObject(node.latitude, node.longitude, node.id) )
}
}
}
fun readOSM(pathToPBF: String) {
val inputStream = FileInputStream(pathToPBF)
// read from osm pbf file:
val custom = OsmReader()
val reader = OsmosisReader(inputStream)
reader.setSink(custom)
// initial parsing of the .pbf file:
reader.run()
println("Break")
}
I would like to only read the nodes in a given bounding box. Then using Osmosis from the command line you can use --bounding-box, but how would you do the same thing in code?
Currently I intersect each node with the bounding box using the JTS, however that is rather slow.