I am trying to get raster to shape form in R using John Baumgartner's code. This function needs gdal_polygonize.py from gdal package. I installed gdal package using: (I am using MacOS Sierra Version 10.12.6)

brew install gdal --HEAD 

When I check for the version. It seems I have installed GDAL:

gdalinfo --version
GDAL 2.3.0dev, released 2017/99/99

Now when I try to run the gdal_polygoniseR function. It gives error. It needs gdal_polygonize.py file. I am stuck at this point:

> system.time(p <- gdal_polygonizeR(r1))
Error in gdal_polygonizeR(r1) : 
Can't find gdal_polygonize.py on your system.

I wanted to check if it exists or not and if it does then its path:

> Sys.which("gdal_polygonize.py")

I saw that there is one additional step after installing GDAL:

echo 'export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH' >> ~/.bash_profile
source ~/.bash_profile

I am able to run this line but does not help as the framework folder does not have gdal folder. When I check for this I do not see "GDAL.framework" in my "Library/Frameworks/..".

If I am able to locate the ".py" file. I will be able to run the function.

1 Answer 1


You have a problem with the unix paths in Mac OS X (see GDAL: Building On Mac)

1) The GDAL pre-compiled binaries of Kyng Chaos use the Framework way (installed in /Library/Frameworks/GDAL.framework).


 $ /Library/Frameworks/GDAL.framework/Versions/2.2/unix/bin/gdal-config --libs
-L/Library/Frameworks/GDAL.framework/Versions/1.11/unix/lib -lgdal
 $ /Library/Frameworks/GDAL.framework/Versions/2.2/unix/bin/gdal-config --cflags

2) The Homebrew way installs all in /usr/local/Cellar/ with symbolic links in /usr/local/bin/


$ gdal-config --libs
-L/usr/local/Cellar/gdal2/2.2/lib -lgdal
$ gdal-config --cflags

So, if you have installed only the Homebrew version, it is normal that

I do not see "GDAL.framework" in my "Library/Frameworks/..".

And there's no need to add /Library/Frameworks/GDAL.framework/Programs to your PATH

3) Now to find the gdal_polygonize.py file, simply use in the terminal

locate gdal_polygonize.py
  • This is helpful. Though locate command does not work for Mac OS. mdfind gdal_polygonize.py did the job for me. The function gives me another error from osgeo import gdal ModuleNotFoundError: No module named 'osgeo' Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open data source. I hope to find some solution for this as well.
    – vikram
    Commented Jun 3, 2018 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.