Skip to content

Instantly share code, notes, and snippets.

@peterwake
Last active March 22, 2021 08:34
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save peterwake/b0fff0c5c018c655c6d5a4aee86aa8ef to your computer and use it in GitHub Desktop.
Save peterwake/b0fff0c5c018c655c6d5a4aee86aa8ef to your computer and use it in GitHub Desktop.
Installation of RGeo with Proj support (also called Proj4)

Installation of RGeo with Proj support (also called Proj4)

This is a real pain as of writing (18 Oct 2019). I can't promise it'll work either :)

Reference

Let's start from the beginning...

If you've been hacking around already you should do:

gem uninstall rgeo-proj4
gem uninstall rgeo
brew uninstall proj
brew uninstall geos

Now, let's try this...

Install GEOS

Using Homebrew:

brew install geos

Check it's installed with:

geos-config --version

(Should say: 3.8.0)

Install Proj

Proj 6.2.0 doesn't work with RGeo without hacking it.

So...

brew edit proj

(Should say: Editing /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/proj.rb)

In (say) Atom, edit the file that pops up and add the following (after START OF NEW CODE):

  head do
    url "https://github.com/OSGeo/proj.4.git"
    depends_on "autoconf" => :build
    depends_on "automake" => :build
    depends_on "libtool" => :build
  end
  #### START OF NEW CODE
  patch <<~EOS
    diff -ruN proj-6.1.0/src/proj_api.h proj-6.1.0-new/src/proj_api.h
    --- proj-6.1.0/src/proj_api.h       2019-05-06 02:11:08.000000000 -0300
    +++ proj-6.1.0-new/src/proj_api.h   2019-05-18 21:03:25.000000000 -0300
    @@ -34,7 +34,8 @@
       */

     #ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
    -#error 'To use the proj_api.h you must define the macro ACCEPT_USE_OF_DEPRECATED_PROJ_API_H'
    +#warning 'Defining ACCEPT_USE_OF_DEPRECATED_PROJ_API_H to allow use of deprecated API. This API won't be available in PROJ 7.0.0 and onwards'
    +#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
     #endif

     #ifndef PJ_VERSION
  EOS
  #### END OF NEW CODE

(Source for this geniousness: rgeo/rgeo-proj4#4 (comment))

Save that file!

Now, execute

brew install proj -s

Don't forget the '-s'! This will take a while (about 3 minutes)

Install the gems

(Go to your project directory first)

geos-config --prefix

Should say /usr/local/Cellar/geos/3.8.0

gem install rgeo -- --with-geos-dir=/usr/local/Cellar/geos/3.8.0
gem install rgeo-proj4

Test it's up and running

Run the ruby console with irb

irb(main):002:0> require 'rgeo'
=> true
irb(main):003:0> require 'rgeo/proj4'
=> true
irb(main):004:0> RGeo::CoordSys::Proj4.supported?
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment