3

I'm new to GIS related things and I'm setting up a Postgre/Postgis database for geospatial queries. I'd like to import various shapefiles into the database and I found that Pgadmin3 has a shapefile importer. How do I install the shapefile import plugin for pgadmin3 (I'm on Mountain Lion 10.8)?

Right now, the plugin menu is empty, and I have the very latest of Postgres and Postgis. See my comment below about what I've seen elsewhere on this topic.

Glen Selle
  • 245
  • 1
  • 3
  • 11
  • which Mac OS are you on? – Mapperz May 23 '13 at 23:43
  • see Mike Toews Answer http://gis.stackexchange.com/questions/7803/bulk-load-multiple-shapefiles-into-postgis – Mapperz May 23 '13 at 23:49
  • I'm on Mountain Lion (10.8) and the questions you posted is for Windows 7. That's just my problem. All of the documentation I've seen has been on Windows and most of what I've read says pgadmin3 comes with it by default--but I don't have it, for some reason :( – Glen Selle May 24 '13 at 01:20
  • 1
    think the only way to load shapefiles is via shp2pgsql http://gis.stackexchange.com/questions/41799/adding-shapefiles-to-postgis-database – Mapperz May 24 '13 at 01:44
  • QGIS (mac version) will load shapefiles to postgis databases using the SPIT tool http://hub.qgis.org/projects/quantum-gis/wiki/Download#4-MacOS-X – Mapperz May 24 '13 at 01:47
  • @Mapperz There is a GUI. It can be a pain to enable though.

    http://gis.stackexchange.com/questions/16181/how-can-i-enable-shapefile-gui-loader-in-pgadmin3

    Easiest way to have it would be to just install the OpenGeo Suite as it has it by default.

    – R.K. May 24 '13 at 01:56
  • @Mapperz I might just stick with shp2pgsql if I can't get R.K.'s solution to work. Thank you both for your help – Glen Selle May 24 '13 at 03:25
  • I wrote this blog post to suit Ubuntu - http://www.staygeo.com/2013/05/enabling-postgis-shapefile-and-dbf.html. I believe the instructions would be similar for Mac. I had to set PGBINDIR environment variable, create symbolic link etc. – Chethan S. May 24 '13 at 03:59
  • @Chethan S. Ok, I'll take a look! – Glen Selle May 24 '13 at 10:57

3 Answers3

8

I decided to go ahead and use the command line utility (shp2pgsql) to import my .shp file. Since I was able to get it working without too much trouble and a little Googling around I wanted to share this possible solution for anyone else who just wants to import a .shp file into Postgres and didn't want to deal with the hassle of trying to get pgadmin's GUI geospatial data importer. To import a shapefile here is the command (of course you need both Postgres and Postgis installed, first):

shp2pgsql -I -s <SRID> <PATH/TO/SHAPEFILE> <SCHEMA>.<DBTABLE> | psql -d <DATABASE>

And here's the OpenGeo docs explaining each of the above parameters:

The command parameters are:
<SRID>Spatial reference identifier
<PATH/TO/SHAPEFILE>Full path to the shapefile (such as C:\MyData\roads\roads.shp)
<SCHEMA>Target schema where the new table will be created
<DBTABLE>New database table to be created (usually the same name as the source shapefile)
<DATABASE>Target database where the table will be created

So just as an example, here was my command:

shp2pgsql -I -s 3857 ~/Downloads/MoGeospatialData/MO_2012_Senate_Districts.shp public.geospatial-data | psql -p 5432 -d vetting-geospatial

If you're not sure where to get the SRID just go here and upload your .prj file and use the topmost match it generates: http://prj2epsg.org/search

And for a comprehensive explanation of this CLI and importing data in general, just check out this great documentation from OpenGeo: http://suite.opengeo.org/docs/dataadmin/pgGettingStarted/shp2pgsql.html

I hope this helps someone!

Glen Selle
  • 245
  • 1
  • 3
  • 11
  • I had an instance running on macosx docker using boot2docker. I just added the -h 192.168.59.103 -p ???? -U docker args to the psql and it worked fined as well. – Emile Sep 08 '14 at 15:54
1

R.K.'s answer is heading in the right direction. Unfortunately, the pgShapeLoader.app file is needed (within /Applications/OpenGeo/), otherwise the script with plugins.ini will now execute properly (it has no file to reference). I'm not sure the file is available anywhere other than OpenGeoSuite. Ironically, if you download the OpenGeoSuite and install postGIS from it, the phShapeLoader should already be installed and ready to go.

1

You might have to add the following to your plugins.ini file:

;
; pgShapeLoader (OSX):
;
Title=PostGIS Shapefile and DBF loader
Command=/usr/bin/open /Applications/OpenGeo/pgShapeLoader.app --args '-U $$USERNAME -d $$DATABASE -p $$PORT -h $$HOSTNAME'
Description=Open a PostGIS ESRI Shapefile or Plain dbf loader console to the current database.
KeyFile=/Applications/OpenGeo/pgShapeLoader.app/Contents/Info.plist
Platform=osx
ServerType=postgresql
Database=Yes
SetPassword=No

You'll most probably have to tweak the paths a little to fit your configuration. I got this file from the OpenGeo Suite install. Hopefully this should be enough to point you in the right direction. Good luck!

R.K.
  • 17,405
  • 3
  • 59
  • 110