17

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

closed as unclear what you're asking by neogeomat, aldo_tapia, nmtoken, Vince, whyzar May 11 '18 at 13:05

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    You could use the shp2pgsql tool, included in postgis. See postgis.net/docs/manual-2.1/… – 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
14

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!

  • 3
    DB Manger supports importing any layer that is open in QGIS not just shapefiles. – Nathan W Aug 20 '13 at 4: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 0:26
19

You can use the DBManager core plugin

enter image description here

  • please help me in that Query Builder question .i badly need answer for that only.........? – Arun Aug 19 '13 at 11:01
  • Is this something new? I don't see Import Layer & Export Layer Buttons in DB Manager v 0.1.20 in QGIS 1.8 on Windows Xp. – Devdatta Tengshe Aug 20 '13 at 4:32
  • New in 2.0, well 1.9, until 2.0 is released. – Nathan W Aug 20 '13 at 4:33
2

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.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.