This way one command is enough but it may not be extremely fast because GDAL must in any case create temporary database structures from the whole .pbf file for resolving nodes-ways-relations.
ogrinfo -dialect sqlite -sql "select ST_Envelope(geometry) from multipolygons where building is not null limit 5" albania-latest.osm.pbf
Had to open data source read-only.
INFO: Open of `albania-latest.osm.pbf'
using driver `OSM' successful.
Layer name: SELECT
Geometry: Unknown (any)
Feature Count: 5
Extent: (19.470962, 40.289919) - (20.153678, 41.329786)
Layer SRS WKT:
GEOGCRS["WGS 84",
...
Data axis to CRS axis mapping: 2,1
Geometry Column = ST_Envelope(geometry)
OGRFeature(SELECT):0
POLYGON ((19.4709618 40.7198672,19.4713055 40.7198672,19.4713055 40.7201239,19.4709618 40.7201239,19.4709618 40.7198672))
OGRFeature(SELECT):1
POLYGON ((20.153198 40.297601,20.153678 40.297601,20.153678 40.2979293,20.153198 40.2979293,20.153198 40.297601))
OGRFeature(SELECT):2
POLYGON ((19.8165231 41.3290525,19.8177414 41.3290525,19.8177414 41.3297856,19.8165231 41.3297856,19.8165231 41.3290525))
OGRFeature(SELECT):3
POLYGON ((19.8073262 41.3292145,19.8078217 41.3292145,19.8078217 41.3296297,19.8073262 41.3296297,19.8073262 41.3292145))
OGRFeature(SELECT):4
POLYGON ((20.0099954 40.2899189,20.0104853 40.2899189,20.0104853 40.2904093,20.0099954 40.2904093,20.0099954 40.2899189))
Edit the SQL if you want to include more attributes and use it with ogr2ogr when you are happy with it.
You did not tell the method that you used for parsing the bounding boxes from GeoPackage, but SQLite dialect and ST_Extent() can be used similarly with GeoPackage data.
osmium_extract
intoosmium_export
with boudary filter and import into PostgreSQL (you can get a GeoJSON, too); I know you explicitly want to use no intermediate storage, but its trivial to go from there. – geozelot Nov 22 '20 at 14:26boundary
filter onosmium_export
will not result in a file that contains bounding boxes of the original polygons… – Dave Nov 22 '20 at 14:33