OpenStreetMap to GeoPackage Converter
Import OpenStreetMap spatial layers into structured databases.
This guide demonstrates how to extract OpenStreetMap records and organize them into SQL tables within a portable GeoPackage database. Organise points, polylines, and polygons into indexable database tables dynamically.
Indirect Mapping Execution Required
Because database connection attributes or local attributes parsing is required, direct web streams are disabled. Use the GDAL CLI script below for precise terminal conversions.
Specification Rules
- Build offline mapping databases for desktop GIS applications
- Organize complex road network layers into clean relational databases
- Maintain historical regional map snapshots on isolated devices
- OpenStreetMap raw files store topological structures, not simple spatial tables
- Large scale extractions are subject to local storage constraints
- Requires mapping configurations to structure key-value tags into database columns
GDAL Direct Equivalent Terminal Command
When to use this conversion
Use when you need offline access to a region's OSM data inside a desktop GIS or a mobile field app. GeoPackage is the right target because it carries multiple layers (roads, buildings, POIs) in a single file with spatial indexes.
Technical Details
GeoPackage is typically 1.5–3× the size of the source PBF. PBF is highly compressed; GeoPackage adds geometry blob overhead and indexes but is still much smaller than equivalent GeoJSON.
Common Errors & Fixes
- Database bloats to many gigabytes: full-country extracts include every tag on every feature. Fix: minimise osmconf.ini to only the keys you need.
- No spatial index created: missing CREATE SPATIAL INDEX in the ogr2ogr options. Fix: add -lco SPATIAL_INDEX=YES (default in modern GDAL).
- Relations not assembled: complex multipolygons fall through as raw lines. Fix: ensure complete-ways input and check the multipolygons layer.
- CRS unexpected: a downstream tool wants Web Mercator for tile generation. Fix: reproject to EPSG:3857 after import using ogr2ogr.
Alternative Tools
- osm2pgsql for the canonical OSM-to-PostGIS pipeline (then export GeoPackage via ogr2ogr)
- imposm3 for tag-aware OSM imports with custom mapping rules
- QGIS QuickOSM plugin for small-area extracts directly into project layers
- Maperitive or Geofabrik's GeoPackage extracts (when available)
Frequently Asked Questions
How are OSM tag pairs organized into database columns?
The GDAL extraction driver references settings in the 'osmconf.ini' file, mapping defined keys to direct columns while grouping unlisted tags into a single HSTORE database field.
Can I perform immediate spatial queries on the output?
Yes, GeoPackage natively utilizes SQLite, allowing you to run SQL statements with spatial search indexes.
How do I extract only building footprints?
Run a targeted SQL query selecting only features with active 'building' attributes.