TransWikia.com

Adding shapefiles to PostGIS database

Geographic Information Systems Asked by Sam007 on July 1, 2021

I was able to create a Postgresql database and then I executed,

createlang plpgsql geospecies
psql -d geospecies -f postgis.sql
psql -d geospecies -f spatial_ref_sys.sql

So now can I directly import the shapefiles? Would this be the right command,

ogr2ogr -f PostgreSQL PG:"host=server_ip user=username dbname=dbname password=password" yourshapefile.shp;

I am not sure how to structure the database, would it not need a table? I will eventually need to add a bunch load of shapefiles and so is there a command to do that?

3 Answers

Try shp2pgsql. The basic syntax is like:

shp2pgsql -s SRID SHAPEFILE.shp SCHEMA.TABLE | psql -h HOST -d DATABASE -U USER

I always find this cheatsheet from http://www.bostongis.com useful. If you scroll down a little, you will find simple examples on how to load data.

Hope it helps.

Correct answer by user8723 on July 1, 2021

Ahh! Can't comment yet!

What Haziq posted would be the correct commandline way to do it Sam.

TABLE is just whatever you want to name it and would be the name to use when calling it from a query, the table will be generated upon import.

If you become lazy like me, I just use the awesome SPIT (Shapefile to PostGIS Import Tool) available as a QGIS plugin to import all my shapefiles now. Assuming you are using QuantumGIS as you said your were using OpenGeo earlier.

Answered by RomaH on July 1, 2021

Anyone doing this in 2021 should be aware of the amazingly convenient QGIS Processing Toolbox tool 'Export to PostgreSQL':

enter image description here

Answered by Encomium on July 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP