22

How do I export a vector shapefile to PostGIS database? I am asking what format I have to export it.

Sunil
  • 4,763
  • 7
  • 43
  • 87
Arun
  • 1,462
  • 6
  • 21
  • 37
  • 3
    You could use the shp2pgsql tool, included in postgis. See http://postgis.net/docs/manual-2.1/using_postgis_dbmanagement.html#shp2pgsql_usage – Oyvind Aug 19 '13 at 10:25
  • PostGIS database can import from a shapefile. are you asking how to export from some application in a format other than shapefile? – nmtoken May 11 '18 at 12:13

4 Answers4

24

You can use the DBManager core plugin

enter image description here

Nathan W
  • 34,706
  • 5
  • 97
  • 148
16

As @oyvind suggested, shp2pgsql is the best method for just getting the data into a PostGIS database. OpenGEO has a good startup guide for loading data into PostGIS that should get you up and running if you're having issues. As @nathanw pointed out, DB Manager is a good option for importing a shapefile into a database. Also available is PostGIS Manager, which is a great option if you're working specifically with PostGIS. @underdark has a great blog post about how to use it.

You'll need the database connection information (username, hostname or host address, and database name) as well as the SRID for the shapefile, but that is all covered in the OpenGEO startup guide. Good luck!

DarkCygnus
  • 314
  • 2
  • 16
Richard D
  • 462
  • 2
  • 8
  • 3
    DB Manger supports importing any layer that is open in QGIS not just shapefiles. – Nathan W Aug 20 '13 at 04:34
  • The DB manager link is broken, and the PostGIS Manger link leads to a page that says this is "depracated" in favor of DB Manager (which can handle SpatiaLite and PostGIS). – DarkCygnus May 11 '18 at 00:26
3

To export your vector file, with re-projection option using ogr2ogr, here is the command line:

ogr2ogr -overwrite -progress --config PG_USE_COPY YES -f PostgreSQL PG:"host=Your_host port=your_DB_port(5432) dbname=your_DB_name password=DB_password user=DB_user" dir_to_your_Vector(.shp, .gml, .geojson...) -nlt MULTIPOLYGON -lco SCHEMA=your_DB_schema(public) -lco GEOMETRY_NAME=geom -lco FID=id -nln your_Output_Table_Name -s_srs EPSG:your_Source_EPSG_code -t_srs EPSG:your_Target_EPSG_code

Don't forget to check that you have permissions to connect to the hose where the postgis is and to create the database.

Mounirsky
  • 103
  • 7
1

Not a new answer, just an updated screen shot for Nathan W's excellent one. The DB manager interface is a bit different now (2.18) and the options are now in menus. The SQL window is under Database and the table related ones under table.

screed shot fro QGIS 2.18

Russell Fulton
  • 2,994
  • 3
  • 31
  • 55