heroku / heroku-geo-buildpack

Classic buildpack that installs the Geo/GIS libraries GDAL, GEOS and PROJ.
38 stars 28 forks source link

gdal_merge.py support? #47

Closed cody-elhard closed 6 months ago

cody-elhard commented 1 year ago

Is there any workarounds to get gdal_merge.py to work or do we need to manually install gdal with python support?

From the docs. gdal_merge.py is a Python script, and will only work if GDAL was built with Python support.

https://gdal.org/programs/gdal_merge.html

edmorley commented 1 year ago

Hi!

This buildpack is maintained on a best effort basis only. It's not used at all within Heroku, so we generally don't really understand much about how GDAL works.

I presume from your wording that something isn't working (it's implied but not explicitly stated; including an error message in cases like this is helpful)?

If there is a configure option or similar that needs to be adding to the GDAL builds, then I'd accept a PR: https://github.com/heroku/heroku-geo-buildpack/blob/79e30b559963daa796fe8f6ca0c82457e0677851/builds/gdal/gdal.sh#L16

cody-elhard commented 1 year ago

I will need to investigate this a bit.

There is a subset of gdal utilities that are built with Python. https://gdal.org/user/gdal_python_utilities.html I believe Python is part of the base Heroku stack.

In our instance I get

$ python --version
Python 3.10.12
cody-elhard commented 1 year ago

@edmorley thanks for the timely response.

So looking at the flags for configure it appears we can pass a --with-python flag.

It appears python is included on every stack meaning this should pass?

We don't have access to AWS_ACCESS_KEY_ID so we can't test this ourselves.

➜  gdal-3.5.0 ./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

...

Optional Packages:
  ...
  --with-python=ARG   Enable python bindings (ARG=yes, no, or path to python binary)
edmorley commented 1 year ago

Ah so it seems that the GDAL project now has Debian packages available: https://gdal.org/download.html#debian

It may be possible to use those via https://github.com/heroku/heroku-buildpack-apt rather than needing this buildpack. Longer term that seems a more sustainable option than us trying to keep this buildpack going.

edmorley commented 6 months ago

So I looked into this as part of #53.

Enabling the Python bindings during the build of the GDAL library for this buildpack wouldn't be ideal, since:

However, I found that the GDAL Python package from PyPI already includes gdal_merge.py, so this feature was actually already supported by using that package.

ie:

  1. Add this buildpack and the Python buildpack to your app
  2. Add GDAL to requirements.txt so the Python buildpack installs the GDAL Python package too
  3. Use via the command gdal_merge.py (the GDAL package configures it as a console script during package installation)

eg:

$ heroku run bash
Running bash on ⬢ emorley-geo-test... up, run.1550 (Basic)
~ $ cat requirements.txt | tail -n1
GDAL
~ $ gdal_merge.py --help
Usage: gdal_merge.py [--help] [--help-general]
                     [-o <out_filename>] [-of <out_format>] [-co <NAME>=<VALUE>]...
                     [-ps <pixelsize_x> <pixelsize_y>] [-tap] [-separate] [-q] [-v] [-pct]
                     [-ul_lr <ulx> <uly> <lrx> <lry>] [-init "<value>[ <value>]..."]
                     [-n <nodata_value>] [-a_nodata <output_nodata_value>]
                     [-ot <datatype>] [-createonly] <input_file> [<input_file>]...
                     [--help-general]