Tips on GeoPandas
According to the documentation in GeoPandas, the following codes could read a local GeoJSON file and import to a PostGIS DB:
import geopandas
from sqlalchemy import create_engine
path_to_data = "./my_file.geojson"
gdf = geopandas.read_file(path_to_data)
db_connection_url = "postgres://user:pwd@localhost:5432/db";
engine = create_engine(db_connection_url)
gdf.to_postgis("my_file_table", con=engine)
I found the following tips:
- "postgres://" has to be changed to "postgresql://".
- Package "psycopg2" is required together with "sqlalchemy" (Details could be found in DBAPI support section in PostgreSQL documentation)
- Package "GeoAlchemy2" is required together with "sqlalchemy"
Enjoy!
Comments
Post a Comment