rgeo / rgeo-proj4

Proj4 extension for rgeo.
MIT License
13 stars 14 forks source link

Heroku: `proj_create: Cannot find proj.db` and `proj_create: no database context specified` #17

Closed evdevdev closed 3 years ago

evdevdev commented 3 years ago

I have a rails app that is deployed to heroku. I'm running into the following error when trying to create a projected factory:

> RGeo::Geographic.projected_factory(projection_proj4: "EPSG:4326", projection_srid: 4326)
proj_create: Cannot find proj.db
proj_create: no database context specified
/app/vendor/bundle/ruby/3.0.0/gems/rgeo-2.3.0/lib/rgeo/geographic/interface.rb:410:in `projected_factory': Bad proj4 syntax: "EPSG:4326" (ArgumentError)

Somewhat confusing things, RGeo::CoordSys::Proj4.supported? returns true.

About the setup:

I more-or-less used these instructions. Summarized, I have an Aptfile that has the following content:

libproj-dev
proj-bin
libgeos-dev

I would expect this to satisfy the requirements of the gem? But I wouldn't be surprised if I were missing something obvious. Any guidance on getting this to work would be very much appreciated.

evdevdev commented 3 years ago

On additional piece of information. I attempted to install the system dependences using the the buildpack suggestion here. Interesting, when I install this way, I now get the following:

> RGeo::CoordSys::Proj4.supported?
=> false

Judging from #15 (also my issue... sorry to blow you up) - I suspect this is because the buildpack installs proj.h in an unexpected place? To save you a click, the heroku buildpack source is here.

Is there anything I can do to help further debug this? Any help is very much appreciated.

Update

If I create a one-off dyno on heroku, I can do the following:

~ $ find / -type f -name 'proj.h'
/app/.heroku-geo-buildpack/vendor/include/proj.h

So perhaps that is the issue?

It looks like the compile script for the heroku build pack exports PROJ4_LIBRARY_PATH - perhaps that could be used to wire these up?

keithdoggett commented 3 years ago

I'm not very familiar with Heroku, but yes it looks like it could be due to that installation path. Also, I checked out the compile script and it looks like the default PROJ version is only 5.2, but version 3+ requires 6.2+ so that might be affecting the build as well.

evdevdev commented 3 years ago

Solved!

The way to get rgeo-proj4 is as follows.

  1. Start with these instructions.
  2. Modify your Aptfile to look as follows:
    libproj-dev
    libgeos-dev
    proj-bin
  3. Update your Heroku ENV vars to have PROJ_LIB to have the value /app/.apt/usr/share/proj
  4. Clear heroku cache & redeploy as described in the instructions in step one.

And boom! You've got yourself a working stack.

Please let me know if I can be helpful in better documenting this anywhere. Thanks again for the awesome library.

keithdoggett commented 3 years ago

If you want to make a PR to update that doc with the info you just posted here for v3+ that would be awesome!

evdevdev commented 3 years ago

@keithdoggett Good call - I've just opened that PR. Thanks again for your help!