semiautomaticgit / SemiAutomaticClassificationPlugin

https://fromgistors.blogspot.com/p/semi-automatic-classification-plugin.html
Other
137 stars 50 forks source link

Wrong path to GDAL binaries on MacPorts/OSX #6

Closed aaschwanden closed 7 years ago

aaschwanden commented 8 years ago

Hi,

I'm using QGIS 2.16.1 installed on my Mac OSX 10.11.6 with MacPorts.

For some reason, SCP picks up the wrong path to GDAL:

2016-08-19 13.11.47.117901 SemiAutomaticClassificationPlugin.core.utils-GDALCopyRaster 2900 GDAL error:: /bin/sh: /Library/Frameworks/GDAL.framework/Versions/2.1/Programs/gdal_translate: No such file or directory I don't know how SCP looks for GDAL, since

$ which gdal_translate
/opt/local/bin/gdal_translate

points to the correct path to GDAL. So the question is: How can I convince SIP that my GDAL installation is in /opt/local, not in /Library/Frameworks? I will try to brute-force remove /Library/Frameworks/GDAL.framework (as I don't recall where this is coming from, I'm sure I don't need it), but this is a somewhat inelegant solution. Note that /Library/Frameworks/GDAL.framework/Versions/2.1/Programs/ is not in my search path:

$ echo $PATH
/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Users/andy/Library/Python/2.7/bin:/Users/andy/local/bin:/Users/andy/petsc/macosx/bin/:/Users/andy/pism/bin:/Users/andy/pism/util:/Users/andy/pism/test:/Users/andy/base/ice/util:/usr/texbin/:/Users/andy/bin:/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/lib/postgresql93/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Library/TeX/texbin

Andy

semiautomaticgit commented 8 years ago

Hi Andy,

you can change the line https://github.com/semiautomaticgit/SemiAutomaticClassificationPlugin/blob/master/core/utils.py#L650

Are gdalwarp and gdalbuildvrt in the same directory?

Luca

aaschwanden commented 8 years ago

Thanks Luca, I'll give it a try.

aaschwanden commented 8 years ago

Alright, hard coding the path works.

Maybe a more elegant way could be (inspired by https://gist.github.com/techtonik/4368898):


import os
import sys

def find_executable(executable, path=None):
    """Find if 'executable' can be run. Looks for it in 'path'
    (string that lists directories separated by 'os.pathsep';
    defaults to os.environ['PATH']). Checks for all executable
    extensions. Returns full path or None if no command is found.
    """
    if path is None:
        path = os.environ['PATH']
    paths = path.split(os.pathsep)
    extlist = ['']
    if os.name == 'os2':
        (base, ext) = os.path.splitext(executable)
        # executable files on OS/2 can have an arbitrary extension, but
        # .exe is automatically appended if no dot is present in the name
        if not ext:
            executable = executable + ".exe"
    elif sys.platform == 'win32':
        pathext = os.environ['PATHEXT'].lower().split(os.pathsep)
        (base, ext) = os.path.splitext(executable)
        if ext.lower() not in pathext:
            extlist = pathext
    for ext in extlist:
        execname = executable + ext
        if os.path.isfile(execname):
            return execname
        else:
            for p in paths:
                f = os.path.join(p, execname)
                if os.path.isfile(f):
                    return f
    else:
return None

fg.gdalPath = os.path.split(find_executable('gdal_translate'))[0]

Works for me with my OSX / MacPorts and with the latest Ubuntu, but I don't have access to a Windows machine.

A.

semiautomaticgit commented 8 years ago

Thank you very much. Actually I think that in your case if you set cfg.gdalPath = "" it should work. Could you please test this?

aaschwanden commented 8 years ago

Luca,

yes this works for me.

Now the pansharpening appears to work despite an error after the conversion process:

Traceback (most recent call last): File "/Users/andy/.qgis2/python/plugins/raster_transparency/rastertransparency.py", line 150, in layerChanged maxValue = int(stat.maximumValue) OverflowError: cannot convert float infinity to integer

that appears when SCP tries to load the layers back into QGIS. Some of the bands have NaN as min/max values, could that be the culprit? I've checked with my Ubuntu QGIS and the exactly same Landsat scene. Some bands also have NaN min/max values, but I don't get an error from SCP.

Anyway, now I can explore the plugin, which looks amazing.

Andy

On Thu, Aug 25, 2016 at 12:42 PM, Luca Congedo notifications@github.com wrote:

Thank you very much. Actually I think that in your case if you set cfg.gdalPath = "" it should work. Could you please test this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/semiautomaticgit/SemiAutomaticClassificationPlugin/issues/6#issuecomment-242532994, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHXenOWcqYLP1hABp_qPCXo-p7ZcYHYks5qjf4ogaJpZM4JsW5y .

semiautomaticgit commented 8 years ago

Thank you Andy. I am going to fix the path issue in the next version of SCP.

Yes, that error is caused by the plugin raster_transparency when the band contains Nan values usually for NoData.

Best regards, Luca