[OSM-dev] OSM->PostGIS Python tool?

Sarah Hoffmann lonvia at denofr.de
Fri Dec 21 21:46:13 UTC 2018


Hi,

On Thu, Dec 20, 2018 at 08:54:34PM -0800, Spencer Gardner wrote:
> I'm researching options for a Python-based tool that uses OSM data. From
> what I can gather there's no native Python library for OSM imports to a
> PostGIS database. (Yes, imposm is developed in Python but there's no
> documentation I can find on how to use it as a Python library--it appears
> to be intended as a command line tool). This seems odd to me since there's
> such a large community of OSM users. I feel like I'm missing something. Are
> there other viable Python libraries I'm not aware of? (Viable = large-ish
> user base and history of bugfixing.) Is there documentation for using
> imposm within Python that I've overlooked?
> 
> Bonus points for:
> - Windows compatibility
> - No external (i.e. non-Python) libraries needed

If you are looking for something purely Python, then you can combine
pyosmium for reading OSM data with SQLAlchemy for writing it into
the database. This gives you maximum flexibility for the database
schema.

For an example on how to do it:
https://github.com/waymarkedtrails/osgende/blob/master/tools/osgende-import

This tool only imports the raw OSM data. If you want preprocessed
geometries then you would need to have a look at pyosmiums shapely
example. 

This is quite a bit slower than the Java and C++ importers mentioned in this
thread but that would only be relevant if you do regular full planet
imports.

Regarding Windows compatibility: pyosmium does have a native library part.
We do create pre-compiled versions for installation via pip but only for
a handful of python versions and so far I had neither positive nor negative
feedback if that actually works as intended.

Kind regards

Sarah



More information about the dev mailing list