[GIS] How to import shp2pgsql on mac

postgisshapefile

I am using EnterpriseDB to run Postgis.

when I run "shp2pgsql" on got an error message.

~ macbook$ shp2pgsql
-bash: shp2pgsql: command not found
~ macbook$ which shp2pgsql

I read that I should find it in this directory, but It seems that I am missing that file.

~ macbook$ ls /Library/PostgreSQL/9.3/bin/

clusterdb       pg_controldata      pgbench
createdb        pg_ctl          pgsql2shp
createlang      pg_dump         pltcl_delmod
createuser      pg_dumpall      pltcl_listmod
dropdb          pg_isready      pltcl_loadmod
droplang        pg_receivexlog      postgres
dropuser        pg_resetxlog        postmaster
ecpg            pg_restore      psql
initdb          pg_standby      raster2pgsql
oid2name        pg_test_fsync       reindexdb
pg_archivecleanup   pg_test_timing      shp2pgsql
pg_basebackup       pg_upgrade      vacuumdb
pg_config       pg_xlogdump     vacuumlo

when I run this comma
/Library/PostgreSQL/9.3/bin/shp2pgsql.sh Outlines.shp city | psql -d City

It says:
-bash: psql: command not found
-bash: shp2pgsql.sh: command not found

How can I run this command ?
should I go for shp2pgsql-gui loader ?

Best Answer

I haven't used the EnterpriseDB installer before, so I'm not sure if it installs shp2pgsql by default.

You can confirm whether or not you do have shp2pgsql installed, however, by performing the following commands:

# Update your search database
$ sudo /usr/libexec/locate.updatedb
# Execute search for shp2pgsql
$ locate shp2pgsql

The output of this command for me is as follows:

Matthews-MacBook-Pro-2:scripts matt$ locate shp2pgsql
/usr/local/Cellar/postgis/2.1.1/bin/shp2pgsql
/usr/local/Cellar/postgis/2.1.1/share/man/man1/shp2pgsql.1
/usr/local/bin/shp2pgsql
/usr/local/share/man/man1/shp2pgsql.1

Looking more specifically at /usr/local/bin/shp2pgsql on my system, we can see that it's symbolically linked to /usr/local/Cellar/postgis/2.1.1/bin/shp2pgsql

Matthews-MacBook-Pro-2:scripts matt$ ls -lath /usr/local/bin/shp2pgsql
lrwxr-xr-x  1 matt  admin    37B Dec  7 20:31 /usr/local/bin/shp2pgsql -> ../Cellar/postgis/2.1.1/bin/shp2pgsql

So, if the output of the locate command on your Mac shows that shp2pgsql has been installed, but is not in your /usr/local/bin directory, you might be able to get away with creating the symlink in /usr/local/bin, pointing it to the actual file path to shp2pgsql.

See this link on creating symlinks: http://justinwalker.me/2012/02/better-than-an-alias-create-a-symbolic-link-in-mac-os-x/