Last active
February 24, 2020 11:42
-
-
Save tastatham/d436aa99b8d98263a3856fca75c69bfd to your computer and use it in GitHub Desktop.
Geopandas to postgis example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load pkgs and data | |
import geopandas as gpd | |
data = gpd.read_file("https://gist.githubusercontent.com/HTenkanen/456ec4611a943955823a65729c9cf2aa/raw/be56f5e1e5c06c33cd51e89f823a7d770d8769b5/ykr_basegrid.geojson") | |
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')) | |
# Subset argentina as single ply | |
argentina = world[world['name'] == 'Argentina' ] | |
# Define engine | |
engine = create_engine("postgresql+psycopg2://[user]:[password]@localhost:5432/[my_db]") | |
# Copy to postgis | |
copy_to_postgis(data, engine, table='my_table1', schema='my_schema', if_exists='replace') | |
# Copy to postgis | |
copy_to_postgis(world, engine, table='my_table2', schema='my_schema', if_exists='replace') | |
# Copy to postgis | |
copy_to_postgis(argentina, engine, table='my_table3', schema='my_schema', if_exists='replace') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment