0

I installed Homebrew and used it to install GDAL from within Ubuntu. After the installation finished, I'm still running into the following error: "'ogr2ogr/ogrinfo/gdalinfo' is not recognized as an internal or external command, operable program, or batch file" anytime I try using ogr2ogr, gdalinfo --version, or ogrinfo --help in command prompt. If I run those in Ubuntu, the error message reads "command not found."

Does this mean the installation did not work correctly? Would you advise to try reinstalling GDAL?

(The end goal is to use ogr2ogr to import a shapefile into postgres, eventually running ogr2ogr -f "PostgreSQL" PG:"host=myhost user=myloginname dbname=mydbname password=mypassword" mytabfile.tab as advised by the documentation.)

Jim Jones
  • 18,404
  • 3
  • 35
  • 44
amb
  • 27
  • 6

1 Answers1

0

If you're simply trying to import shapefiles into PostgreSQL, you might wanna take a look at shp2pgsql. It's quite simple - if you have the luxury of choosing the import tool :)

Data sample: TM_WORLD_BORDERS_SIMPL-0.3.zip

After unpacking your zip file just execute the following line in your console:

$ shp2pgsql -I -s 4326 TM_WORLD_BORDERS_SIMPL-0.3.shp table_world | psql -d mydb

Things to take into account:

  • table_world is the name of the target table
  • psql -d mydb takes into account that your current operating system user has an account in the database, that no password is required, that the database is installed at localhost and that it listens at the the standard port 5432. Check the psql documentation to build your own connection command, e.g. psql -U myuser -h 192.168.1.42 -p 5434 -d mydb to login with the user myuser in the database mydb in the remote PostgreSQL at 192.168.1.42 that listens at the port 5434. In case your PostgreSQL isn't configured to accept connections, check this answer.
  • 4326 is the identifier for WGS84, which is the spatial reference system of this shapefile - and the most often used worldwide.

.. and your data is ready to be played with, e.g. import into QGIS:

enter image description here

Further reading: psql, shp2pgsql tutorial

Jim Jones
  • 18,404
  • 3
  • 35
  • 44
  • Hi @JimJones, thanks for the response! I tried running what you suggested in Ubuntu, but am getting the error: ```Unable to open TM_WORLD_BORDERS_SIMPL-0.3.shp or TM_WORLD_BORDERS_SIMPL-0.3.SHP. TM_WORLD_BORDERS_SIMPL-0.3.shp: dbf file (.dbf) can not be opened. psql: error: could not connect to server: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?``` The error is occurring both with the data sample provided and the shp file I am trying to import to postgres. – amb Jan 06 '20 at 22:17
  • @amb the error is because you cannot connect to the database via `psql`. Is your database accepting connections? Have you enable access in the `postgresql.conf` and `pg_hba.conf`? – Jim Jones Jan 07 '20 at 07:01