Postgis (or geojson) to .osm file

I have a big postgres table that I would to to see exported as an .osm file.
So far I have succeeded in exporting a part of this table to geojson (with ogr2ogr) and then converting this file via JOSM to an .osm file (save as). I can export the entire table als geojson but it is way to big for JOSM. So I am looking for a way to export postgis to .osm and possibly via geojson.

The reason for this is because I am trying to create an Osmand map of public Dutch geodata. OsmAndMapCreator accepts .osm files. Any suggestions?

If you are just exporting points and ways you can try GitHub - simonpoole/geojson2osm: Small java tool to convert GeoJSON to OSM data to convert from geojson to OSM. See the caveats, if there is a specific issue I might be motivated enough to fix it if you open an issue :slight_smile:

Thanks. Currently my data has only polygons and multipolygons so I guess that would not work.

I found ogr2osm but since I am on windows this seems a bit too complicated for me. :frowning_face:

You should be able to relatively easily get python3 running on windows. The main issue is that you will need to have a lot of memory if the dataset is large, but that is the same essentially for all current tools.

For ogr2osm you mean? Yes I have python3.9 installed but the things is … I lack knowledge on how to get all these tools running together. To me it seems there are some many things to do before everythings runs properly that I just give up. But maybe I will give it an other try this time.

Recently, I created a tool that convert postgis directly to .osm file. It is simple to use. It is working on Linux Debian, but I’m not sure about others Operating Systems.

So far, it has some limitation as described in the section “To-do”, but I plan to improve the code.

Check it out on GitHub - santamariense/postgis_to_osm: postgis_to_osm converts a PostgreSQL + PostGIS table into an .osm file.

1 Like

Hello @santamariense

I was looking for a way to export in osm format data stored in PostgreSQL and your tool seems to answer my issue :slight_smile:

In my case, I want to merge data that comes from OSM API with data that is stored locally in a PostgreSQL database, and then to export merged data in OSM format to upload it with JOSM.
I’ve written a python script that does the job, but only for nodes and not in proper manner.

If my relation is composed of columns that correspond to correct tag names (including metadata such as osm_id and osm_version), should it work with your tool?

Please make sure that any such uploading/importing of data follows the relevant guidelines: Automated Edits code of conduct - OpenStreetMap Wiki resp. Import/Guidelines - OpenStreetMap Wiki - most importantly, you need to discuss your plans with the community first.

3 Likes

Yes, for sure! Thx for the reminder.

This is something I’ve already done for a particular theme (trees), limited to the administrative area I’m professionally working on. I’ve created a dedicated page on the openstreetmap wiki to describe the process (excuse my french).

Yes, I will

At the moment, this tool formats new data from the database into an OSM file. It does not modify data that already exists in an OSM file or on the OSM server. This is a great functionality that I may develop in the future.

About 6 years ago, I developed another tool (osmcsvappender) that might be useful to you. It makes it possible to join data from a CSV into an OSM file. Since then, I haven’t been actively working on this project. I think it still works, but only under Python 2.7 and linux. It joins data by a field or object ID. The limitation of the current version is memory capacity and file size.