Data import and export in a GIS is often a must do operation while working on any data.Understanding databases for data
storage and management is a vital skill in any GIS work.
In this tutorial, we are going to explore three methods for data import into PostGIS namely;
- Using PostGIS shapefile import/export manager
- Using QGIS import to PostGIS tool
- Executing .SQL files (Coded table layout)
All these methods achieve the same functionality
Using PostGIS shapefile import/export manager
In this method, we use this tool that is installed when you install PostGIS on your local system.
This offers a GUI that is easy and straight forward to use.
To use this method,
On Terminal, shp2pgsql-gui to launch the manager
Launch pgAdmin3 and access PostGIS import/export manager or access “C:\Program Files\PostgreSQL\9.3\bin\postgisgui\shp2pgsql-gui.exe”
Once launched, this is the view
Under the view connection details, input the parameter depending on the settings on your system
Click ok to connect to database
Click on add file to add the .shp file of interest
Click on import to import the data into the dumy database
Check the table section in PostgreSQL to ensure the table exists
Using QGIS import to PostGIS tool
This launches this window, input all the parameters and click Run
Executing .SQL files (Coded table layout)
In this section, we will generate a .sql from a .shp file and use this to load data into the PostGIS database.
Use this code in terminal to generate the sql file;
shp2pgsql -s 4210 landuse.shp landuse > landuse.shp
This generates the .sql file like this;
Then, run this command to load the data into the database
sudo su postgres – To connect to PostGIS as user postgres
psql -f landuse.sql dumy – Create landuse table in dumy database
After this section, the table is created in PostGIS and data loaded.
I also recorded a video for this topic.
Enjoy the video!!