I use python and GeoPandas to preprocess data in a GeoDataFrame. Now I want to import these data into PostGIS. I know that I could do it with python directly but this is too slow. My application needs to be as fast as possible.
Therefore I want to make use of https://osm2pgsql.org/ because is is written in C and is supposed to be very fast.
Problem
osm2pgsql only supports XML, PBF or O5M format. How can I export the GeoDataFrame to pbf (preferred)? I could also export it as GeoJson, but then I need to convert GeoJson to PBF, but how? I also had a look at osmium https://osmcode.org/osmium-tool/ but I think only pbf -> geojson is possible.
Best Answer
To improve your load time into PostgreSQL database do an export of your geodataframe to csv, then import resulting file to the database using COPY command and psycopg that performs better than directly using to_sql or to_postgis over dataframe, as: