I tried converting .osm file to .gpkg file and it works just fine, like this:

$ ogr2ogr output2.gpkg somefile.osm
0...10...20...30...40...50...60...70...80...90...100 - done.

but when I reverse it back it won't work.

$ ogr2ogr output2.osm output2.gpkg
ERROR 1: Cannot guess driver for output2.osm

I also tried

$ogr2ogr -f osm output2.osm output2.gpkg
ERROR 1: osm driver does not support data source creation.

another attempt is using ogr2osm but this also returned an error from python.

$ ogr2osm output2.osm

Traceback (most recent call last):                                                                                        

File "C:\Users\x\anaconda3\lib\runpy.py", line 197, in _run_module_as_main                                       return _run_code(code, main_globals, None,                                                                            

File "C:\Users\x\anaconda3\lib\runpy.py", line 87, in _run_code                                                  exec(code, run_globals)                                                                                               

File "C:\Users\x\anaconda3\Scripts\ogr2osm.exe\__main__.py", line 7, in <module>                               File "C:\Users\x\anaconda3\lib\site-packages\ogr2osm\ogr2osm.py", line 271, in main                              osmdata.process(datasource)                                                                                           

File "C:\Users\x\anaconda3\lib\site-packages\ogr2osm\osm_data.py", line 406, in process                          self.add_feature(ogrfeature, layer_fields, datasource.source_encoding, reproject)                                     

File "C:\Users\x\anaconda3\lib\site-packages\ogr2osm\osm_data.py", line 354, in add_feature                      osmgeometries = self.__parse_geometry(ogrgeometry, feature_tags)                                                      

File "C:\Users\x\anaconda3\lib\site-packages\ogr2osm\osm_data.py", line 329, in __parse_geometry                 osmgeometries.append(self.__parse_collection(ogrgeometry, tags))                                                      

File "C:\Users\x\anaconda3\lib\site-packages\ogr2osm\osm_data.py", line 297, in __parse_collection               if len(members) == 1 and len(members[0].nodes) <= self.max_points_in_way:    

AttributeError: 'tuple' object has no attribute 'nodes'

I'm stuck. How do I convert the .gpkg back to .osm using ogr2ogr?

  • 3
    As ogr2ogr --formats notes, "OSM" (readonly), so ogrtools can't create OSMs, sorry. Commented Jun 17, 2022 at 12:37
  • @barrycarter oh no. do you happen to know any solution beside ogr2ogr? I need my .gpkg in .osm format.
    – sutan
    Commented Jun 17, 2022 at 13:02
  • wiki.openstreetmap.org/wiki/OSM_file_formats may or may not be helpful-- OSM may be a family of formats, not a single format? Commented Jun 19, 2022 at 0:10

2 Answers 2


Try the ogr2osm utility https://github.com/roelderickx/ogr2osm. It should still work even the project is not active at the moment.

Ogr2osm will read any data source that ogr can read and handle reprojection for you. It takes a python file to translate external data source tags into OSM tags, allowing you to use complicated logic. If no translation is specified it will use an identity translation, carrying all tags from the source to the .pbf or .osm output.


Ogr2ogr is not capable of converting to osm, you need to use another tool like for example ogr2osm. It expects at least the input file as parameter, in your case that will be the .gpkg file in stead of the .osm file, e.g. ogr2osm output2.gpkg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.