Skip to content

Instantly share code, notes, and snippets.

@zhm
Last active February 28, 2022 17:11
Show Gist options
  • Save zhm/2005158 to your computer and use it in GitHub Desktop.
Save zhm/2005158 to your computer and use it in GitHub Desktop.
Building GDAL 1.9 with ESRI FileGDB support on OS X Lion

Building GDAL 1.9.x with ESRI FileGDB support on OS X Lion

  • Download the SDK from ESRI's website http://resources.arcgis.com/content/geodatabases/10.0/file-gdb-api
  • Extract the SDK, and put the contents of the directory in a known location, I used ~/local/filegdb. Here's an example path to one of the files: ~/local/filegdb/lib/libFileGDBAPI.dylib
  • I use ~/local/filegdb so it can stay isolated in it's own place. You can put it anywhere, but the next few steps might be different.
  • Go into the directory containing the FileGDB SDK, e.g. ~/local/filegdb
  • ESRI built these dylib's using @rpath's, so to avoid needing to mess with DYLD_LIBRARY_PATH, I updated the @rpath's using install_name_tool. There might be a more elegant way to handle this. If so, comments are welcome!
  • Here are the commands I used to patch the dylibs, this is not required if you want to use DYLD_LIBRARY_PATH yourself:
    install_name_tool -id "$(pwd)/lib/libFileGDBAPI.dylib" ./lib/libFileGDBAPI.dylib
    install_name_tool -change "@rpath/libfgdbunixrtl.dylib" "$(pwd)/lib/libfgdbunixrtl.dylib" ./lib/libFileGDBAPI.dylib
    install_name_tool -id "$(pwd)/lib/libfgdbunixrtl.dylib" ./lib/libfgdbunixrtl.dylib
  • To verify the paths, use otool -L lib/libFileGDBAPI.dylib and otool -L lib/libfgdbunixrtl.dylib and make sure the paths are correct
  • We need to make some changes to the configure.in script for GDAL now, since the FileGDB config script hasn't yet been updated for the OSX FileGDB SDK
  • In the GDAL source root, edit the configure.in and replace it with:
  • In the GDAL source root, run ./autogen.sh to re-create the configure script
  • Now run the configure script:
    ./configure --with-fgdb="$HOME/local/filegdb"
  • The configure script has many options, here is the configure line I use for my custom build: https://gist.github.com/2005091, if you have other GDAL builds on your machine (e.g. homebrew) that you don't want to interfere with, I recommend at least using --prefix="$HOME/local" or some other place on your machine besides /usr/local (default for homebrew) or /opt/local (default for MacPorts).
  • If it worked properly, you should see in the output of configure indicating yes for FileGDB support
  • Build it:
    `make && make install`
    which ogr2ogr        # make sure it's the correct ogr2ogr first
    ogrinfo --formats    # list out the formats
    ogrinfo ~/Downloads/test_fgdb.gdb
    
    #convert FileGDB directly to PostGIS
    ogr2ogr -f "PostgreSQL" PG:"dbname='somedatabase' host='localhost' port='5432'" ~/Downloads/test_fgdb.gdb

Using this build of GDAL in a KyngChaos build of QGIS

# save your current GDAL so you can put it back if you want
cp /Library/Frameworks/GDAL.framework/Versions/1.8/GDAL /Library/Frameworks/GDAL.framework/Versions/1.8/GDAL_orig

# symlink the custom GDAL build to the place QGIS looks
rm /Library/Frameworks/GDAL.framework/Versions/1.8/GDAL
ln -s ~/local/lib/libgdal.dylib /Library/Frameworks/GDAL.framework/Versions/1.8/GDAL

Note: to select one in QGIS, go to Add Vector Layer -> select the Directory radio button -> Select your .gdb directory

I had some problems opening certain FileGDB's. I believe the API only supports FileGDB's created with ArcGIS 10.0+.

More info: http://trac.osgeo.org/gdal/wiki/FileGDB

@zhm
Copy link
Author

zhm commented Jun 27, 2012

@caseypt sweet! Glad you got it working!

@rburhum
Copy link

rburhum commented Jul 14, 2012

Good stuff

@rburhum
Copy link

rburhum commented Nov 2, 2012

@jctull
Copy link

jctull commented Nov 3, 2012

@rburhum: Your simplified approach does not work for me using the latest gdal formula with homebrew. This would be a nice and simple method, but the filegdb path is not getting picked up for some reason for me. I used the symlink approach, so maybe that is part of the problem. Also, gdal.rb changed in the past day or so to reflect new approaches for writing install formulae. This might also have something to do with it.

In the absence of this simplified approach, I have resorted to using a custom formula that performs the necessary patching. I use this statement for my homebrew install, assuming the custom gdal formula is in /usr/local/Library/Formula. I use the -v switch so I can verify desired file support is in place during the configuration phase of the install:

brew install --enable-unsupported --with-postgres --enable-armadillo --enable-opencl --complete gdal.rb -v --env=std

This is based off of the most current gdal formula as of this writing, https://raw.github.com/mxcl/homebrew/67303dd89396ccecff0915a933b81a224eb00d5a/Library/Formula/gdal.rb:

require 'formula'

def complete?
build.include? "complete"
end

def postgres?
build.include? "with-postgres"
end

def mysql?
build.include? "with-mysql"
end

def no_python?
build.include? "without-python"
end

def which_python
"python" + python -c 'import sys;print(sys.version[:3])'.strip
end

def opencl?
build.include? "enable-opencl"
end

def armadillo?
build.include? "enable-armadillo"
end

class Gdal < Formula
homepage 'http://www.gdal.org/'
url 'http://download.osgeo.org/gdal/gdal-1.9.2.tar.gz'
sha1 '7eda6a4d735b8d6903740e0acdd702b43515e351'

head 'https://svn.osgeo.org/gdal/trunk/gdal'

option 'complete', 'Use additional Homebrew libraries to provide more drivers.'
option 'with-postgres', 'Specify PostgreSQL as a dependency.'
option 'with-mysql', 'Specify MySQL as a dependency.'
option 'without-python', 'Build without Python support (disables a lot of tools).'
option 'enable-opencl', 'Build with OpenCL acceleration.'
option 'enable-armadillo', 'Build with Armadillo accelerated TPS transforms.'
option 'enable-unsupported', "Allow configure to drag in any library it can find. Invoke this at your own risk."

For creating up to date man pages.

depends_on 'doxygen' => :build if build.head?

depends_on :libpng

depends_on 'jpeg'
depends_on 'giflib'
depends_on 'proj'
depends_on 'geos'
depends_on 'libtiff'
depends_on 'libgeotiff'
depends_on 'sqlite' # To ensure compatibility with SpatiaLite.
depends_on 'freexl'
depends_on 'libspatialite'

depends_on "postgresql" if postgres?
depends_on "mysql" if mysql?

Without Numpy, the Python bindings can't deal with raster data.

depends_on 'numpy' => :python unless no_python?

depends_on 'armadillo' if armadillo?

if complete?
# Raster libraries
depends_on "netcdf" # Also brings in HDF5
depends_on "jasper"
depends_on "poppler"
depends_on "webp"
depends_on "cfitsio"
depends_on "epsilon"
depends_on "libdap"
# Fix a bug in LibDAP detection and patch FileGDB support
def patches; DATA; end unless build.head?

# Vector libraries
depends_on "unixodbc" # OS X version is not complete enough
depends_on "xerces-c"

# Other libraries
depends_on "xz" # get liblzma compression algorithm library from XZutils

end

def options
[
['--complete', 'Use additional Homebrew libraries to provide more drivers.'],
['--with-postgres', 'Specify PostgreSQL as a dependency.'],
['--with-mysql', 'Specify MySQL as a dependency.'],
['--without-python', 'Build without Python support (disables a lot of tools).'],
['--enable-opencl', 'Build with OpenCL acceleration.'],
['--enable-armadillo', 'Build with Armadillo accelerated TPS transforms.']
]
end

def get_configure_args
args = [
# Base configuration.
"--prefix=#{prefix}",
"--mandir=#{man}",
"--disable-debug",
"--with-local=#{prefix}",
"--with-threads",
"--with-libtool",

  # GDAL native backends.
  "--with-pcraster=internal",
  "--with-pcidsk=internal",
  "--with-bsb",
  "--with-grib",
  "--with-pam",

  # Backends supported by OS X.
  "--with-libiconv-prefix=/usr",
  "--with-libz=/usr",
  "--with-png=#{(MacOS.version >= :mountain_lion) ? HOMEBREW_PREFIX : MacOS::X11.prefix}",
  "--with-expat=/usr",
  "--with-curl=/usr/bin/curl-config",

  # Default Homebrew backends.
  "--with-jpeg=#{HOMEBREW_PREFIX}",
  "--with-jpeg12",
  "--with-libtiff=#{HOMEBREW_PREFIX}",
  "--with-geotiff=#{HOMEBREW_PREFIX}",
  "--with-gif=#{HOMEBREW_PREFIX}",
  "--with-sqlite3=#{HOMEBREW_PREFIX}",
  "--with-freexl=#{HOMEBREW_PREFIX}",
  "--with-spatialite=#{HOMEBREW_PREFIX}",
  "--with-geos=#{HOMEBREW_PREFIX}/bin/geos-config",

  # GRASS backend explicitly disabled.  Creates a chicken-and-egg problem.
  # Should be installed separately after GRASS installation using the
  # official GDAL GRASS plugin.
  "--without-grass",
  "--without-libgrass"
]

# Optional Homebrew packages supporting additional formats.
supported_backends = %w[
  liblzma
  fgdb
  cfitsio
  hdf5
  netcdf
  jasper
  xerces
  odbc
  dods-root
  epsilon
  webp
  libkml
  poppler
]
if complete?
  supported_backends.delete 'liblzma'
  supported_backends.delete 'fgdb'
  args << '--with-liblzma=yes'
  args << '--with-fgdb=/Users/jctull/sources/FileGDB_API'
  args.concat supported_backends.map {|b| '--with-' + b + '=' + HOMEBREW_PREFIX}
else
  args.concat supported_backends.map {|b| '--without-' + b} unless build.include? 'enable-unsupported'
end

# The following libraries are either proprietary, not available for public
# download or have no stable version in the Homebrew core that is
# compatible with GDAL. Interested users will have to install such software
# manually and most likely have to tweak the install routine.
#
# Podofo is disabled because Poppler provides the same functionality and
# then some.
unsupported_backends = %w[
  gta
  ogdi
  fme
  hdf4
  openjpeg
  ecw
  kakadu
  mrsid
  jp2mrsid
  mrsid_lidar
  msg
  oci
  ingres
  dwgdirect
  idb
  sde
  podofo
  rasdaman
]
args.concat unsupported_backends.map {|b| '--without-' + b} unless build.include? 'enable-unsupported'

# Database support.
args << (postgres? ? "--with-pg=#{HOMEBREW_PREFIX}/bin/pg_config" : '--without-pg')
args << (mysql? ? "--with-mysql=#{HOMEBREW_PREFIX}/bin/mysql_config" : '--without-mysql')

# Python is installed manually to ensure everything is properly sandboxed.
args << '--without-python'

# Scripting APIs that have not been re-worked to respect Homebrew prefixes.
#
# Currently disabled as they install willy-nilly into locations outside of
# the Homebrew prefix.  Enable if you feel like it, but uninstallation may be
# a manual affair.
#
# TODO: Fix installation of script bindings so they install into the
# Homebrew prefix.
args << "--without-perl"
args << "--without-php"
args << "--without-ruby"

args << (opencl? ? '--with-opencl' : '--without-opencl')
args << (armadillo? ? '--with-armadillo=yes' : '--with-armadillo=no')

return args

end

def install
# Linking flags for SQLite are not added at a critical moment when the GDAL
# library is being assembled. This causes the build to fail due to missing
# symbols.
#
# Fortunately, this can be remedied using LDFLAGS.
ENV.append 'LDFLAGS', '-lsqlite3'
# Needed by libdap.
ENV.append 'CPPFLAGS', '-I/usr/include/libxml2' if complete?

# Reset ARCHFLAGS to match how we build.
if MacOS.prefer_64_bit?
  ENV['ARCHFLAGS'] = "-arch x86_64"
else
  ENV['ARCHFLAGS'] = "-arch i386"
end

system "echo 'It is necessary to use --env=std.'" unless build.head?
system "./autogen.sh" unless build.head?
system "./configure", *get_configure_args
system "make"
system "make install"

unless no_python?
  # If setuptools happens to be installed, setup.py will cowardly refuse to
  # install to anywhere that is not on the PYTHONPATH.
  #
  # Really setuptools, we're all consenting adults here...
  python_lib = lib + which_python + 'site-packages'
  ENV.append 'PYTHONPATH', python_lib

  # setuptools is also apparently incapable of making the directory it's
  # self
  python_lib.mkpath

  # `python-config` may try to talk us into building bindings for more
  # architectures than we really should.
  if MacOS.prefer_64_bit?
    ENV.append_to_cflags '-arch x86_64'
  else
    ENV.append_to_cflags '-arch i386'
  end

  cd 'swig/python' do
    system "python", "setup.py", "install_lib", "--install-dir=#{python_lib}"
    bin.install Dir['scripts/*']
  end
end

system 'make', 'man' if build.head?
system 'make', 'install-man'
# Clean up any stray doxygen files.
Dir[bin + '*.dox'].each { |p| rm p }

end

unless no_python?
def caveats
<<-EOS
This version of GDAL was built with Python support. In addition to providing
modules that makes GDAL functions available to Python scripts, the Python
binding provides ~18 additional command line tools.

Unless you are using Homebrew's Python, both the bindings and the
additional tools will be unusable unless the following directory is added to
the PYTHONPATH:

#{HOMEBREW_PREFIX}/lib/#{which_python}/site-packages
  EOS
end

end
end

END
Fix test for LibDAP >= 3.10.

diff --git a/configure b/configure
index 997bbbf..a1928d5 100755
--- a/configure
+++ b/configure
@@ -24197,7 +24197,7 @@ else
rm -f islibdappost310.*
echo '#include "Connect.h"' > islibdappost310.cpp
echo 'int main(int argc, char** argv) { return 0; } ' >> islibdappost310.cpp
-if test -z "${CXX} islibdappost310.cpp -c ${DODS_INC} 2>&1" ; then
+if test -z "${CXX} islibdappost310.cpp -c ${DODS_INC} ${CPPFLAGS} 2>&1" ; then
DODS_INC="$DODS_INC -DLIBDAP_310 -DLIBDAP_39"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: libdap >= 3.10" >&5
$as_echo "libdap >= 3.10" >&6; }

diff --git a/configure.in b/configure.in
index a3ca3a1..6c6205e 100644
--- a/configure.in
+++ b/configure.in
@@ -1649,14 +1649,14 @@ else

HAVE_OPENJPEG=yes
LIBS="-L$with_openjpeg -L$with_openjpeg/lib -lopenjpeg $LIBS"

  • if test -r $with_openjpeg/include/openjpeg-2.0/openjpeg.h ; then
  • EXTRA_INCLUDES="-I$with_openjpeg/include/openjpeg-2.0 $EXTRA_INCLUDES"
  • if test -r $with_openjpeg/include/openjpeg-1.99/openjpeg.h ; then
  • EXTRA_INCLUDES="-I$with_openjpeg/include/openjpeg-1.99 $EXTRA_INCLUDES"
    elif test -r $with_openjpeg/include/openjpeg.h ; then
    EXTRA_INCLUDES="-I$with_openjpeg/include $EXTRA_INCLUDES"
    elif test -r $with_openjpeg/openjpeg.h ; then
    EXTRA_INCLUDES="-I$with_openjpeg $EXTRA_INCLUDES"
    else
  • AC_MSG_ERROR([openjpeg.h not found in $with_openjpeg/include or $with_openjpeg/include/openjpeg-2.0])
  • AC_MSG_ERROR([openjpeg.h not found in $with_openjpeg/include or $with_openjpeg/include/openjpeg-1.99])
    fi

AC_CHECK_LIB(openjpeg,opj_decode_tile_data,HAVE_OPENJPEG=yes,HAVE_OPENJPEG=no,)
@@ -1710,15 +1710,39 @@ elif test "$with_fgdb" = "yes" -o "$with_fgdb" = "" ; then
rm -f testfgdb

else

  • case "${host_os}" in
  • darwin)
  •  AC_MSG_CHECKING([for libFileGDBAPI.dylib in in $with_fgdb/lib]) 
    
  •  FGDB_ENABLED=yes
    
  •  if test -r $with_fgdb/lib/libFileGDBAPI.dylib ; then
    
  •    AC_MSG_RESULT([found.])
    
  • AC_MSG_CHECKING([for libFileGDBAPI.so in in $with_fgdb/lib])
  • FGDB_ENABLED=yes
  • if test -r $with_fgdb/lib/libFileGDBAPI.so ; then
  • AC_MSG_RESULT([found.])
  • FGDB_LIB="-L$with_fgdb/lib -lFileGDBAPI"
  • else
  • AC_MSG_ERROR([not found.])
  • fi
  •    FGDB_LIB="-L$with_fgdb/lib -lFileGDBAPI -lfgdbunixrtl"
    
  •  else
    
  •    AC_MSG_ERROR([not found.])
    
  •  fi
    
  •  ;;
    
  • *)
  •  AC_MSG_CHECKING([for libFileGDBAPI.so in in $with_fgdb/lib]) 
    
  •  FGDB_ENABLED=yes
    
  •  if test -r $with_fgdb/lib/libFileGDBAPI.so ; then
    
  •    AC_MSG_RESULT([found.])
    
  •    FGDB_LIB="-L$with_fgdb/lib -lFileGDBAPI -lfgdblinuxrtl"
    
  •  else
    
  •    AC_MSG_ERROR([not found.])
    
  •  fi
    
  •  ;;
    
  • esac
  • #AC_MSG_CHECKING([for libFileGDBAPI.so in in $with_fgdb/lib])
  • #FGDB_ENABLED=yes
  • #if test -r $with_fgdb/lib/libFileGDBAPI.so ; then
  • #AC_MSG_RESULT([found.])
  • #FGDB_LIB="-L$with_fgdb/lib -lFileGDBAPI"
  • #else
  • #AC_MSG_ERROR([not found.])
  • #fi

AC_MSG_CHECKING([for FileGDBAPI.h in $with_fgdb/include])
if test -r $with_fgdb/include/FileGDBAPI.h ; then
@@ -3415,6 +3453,10 @@ dnl RHEL6
elif test -d /usr/lib/jvm/java-openjdk; then
with_java="/usr/lib/jvm/java-openjdk"

+dnl OS X and possibly others

  • elif test -d /usr/libexec/java_home; then
  •    with_java=`/usr/libexec/java_home`
    
    dnl elif test -d /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers; then
    dnl JAVA_INC="-I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers"

@@ -3447,6 +3489,10 @@ elif test "x$with_java" != "x" -a "x$with_java" != "xno"; then
JAVA_HOME="$with_java"
JAVA_INC="-I$JAVA_HOME/include -I$JAVA_HOME/include/freebsd"
AC_MSG_RESULT([yes])

  •    elif test -d "$with_java/include"; then
    
  •        JAVA_HOME="$with_java"
    
  •        JAVA_INC="-I$JAVA_HOME/include"
    
  •        AC_MSG_RESULT([yes])
     else
         AC_MSG_ERROR("Cannot find $with_java/include/linux or solaris or freebsd directory.")
     fi
    

    @@ -3483,10 +3529,27 @@ if test "$with_mdb" = "yes" ; then

    if test "x$with_jvm_lib" != "x"; then
    if test -d "$with_jvm_lib"; then

  •        saved_LDFLAGS="$LDFLAGS"
    
  •        LDFLAGS="$LDFLAGS -L$with_jvm_lib"
    
  •        AC_CHECK_LIB(jvm,JNI_CreateJavaVM,HAS_LIB_JVM=yes,HAS_LIB_JVM=no,)
    
  •        LDFLAGS="$saved_LDFLAGS"
    
  •      dnl OS X needs a check against the JavaVM.framework
    
  •      if test -d /Library/Java/JavaVirtualMachines; then
    
  •          saved_CFLAGS="$CFLAGS"
    
  •          CFLAGS="$CFLAGS $ABI_FLAGS $JAVA_INC"
    
  •          LIBS="$LIBS -framework JavaVM"
    
  •          AC_CACHE_CHECK([for JNI_CreateJavaVM in JavaVM framework],
    
  •                         [HAS_LIB_JVM],
    
  •                         [AC_TRY_LINK([#include <jni.h>],
    
  •                            [JNI_CreateJavaVM(0, 0, 0);],
    
  •                            HAS_LIB_JVM=yes,
    
  •                            HAS_LIB_JVM=no)])
    
  •          CFLAGS="$saved_CFLAGS"
    
  •       elif test "x$OS_TYPE" = "xUNIX" ; then
    
  •          saved_LDFLAGS="$LDFLAGS"
    
  •          LDFLAGS="$LDFLAGS -L$with_jvm_lib"
    
  •          AC_CHECK_LIB(jvm,JNI_CreateJavaVM,HAS_LIB_JVM=yes,HAS_LIB_JVM=no,)
    
  •          LDFLAGS="$saved_LDFLAGS"
    
  •       fi
    
    •    if test "$HAS_LIB_JVM" = "yes"; then
             JVM_LIB="-L$with_jvm_lib -ljvm"
             if test "x$with_jvm_lib_add_rpath" = "xyes"; then
      

    @@ -3718,4 +3781,3 @@ LOC_MSG([ enable pthread support: ${PTHREAD_ENABLED}])
    LOC_MSG([ enable POSIX iconv support:${am_cv_func_iconv}])
    LOC_MSG([ hide internal symbols: ${HAVE_HIDE_INTERNAL_SYMBOLS}])
    LOC_MSG()

    diff --git a/frmts/dods/dodsdataset2.cpp b/frmts/dods/dodsdataset2.cpp
    index 0efa1bb..6f63874 100644
    --- a/frmts/dods/dodsdataset2.cpp
    +++ b/frmts/dods/dodsdataset2.cpp
    @@ -50,13 +50,9 @@
    #include <Sequence.h>
    #include <Grid.h>

-#ifdef LIBDAP_310
/* AISConnect.h/AISConnect class was renamed to Connect.h/Connect in libdap 3.10 */
#include <Connect.h>
#define AISConnect Connect
-#else
-#include <AISConnect.h>
-#endif

#include <DDS.h>
#include <DAS.h>
diff --git a/ogr/ogrsf_frmts/dods/ogr_dods.h b/ogr/ogrsf_frmts/dods/ogr_dods.h
index 99f269e..ba114a0 100644
--- a/ogr/ogrsf_frmts/dods/ogr_dods.h
+++ b/ogr/ogrsf_frmts/dods/ogr_dods.h
@@ -61,13 +61,9 @@
#include <Sequence.h>
#include <Grid.h>

-#ifdef LIBDAP_310
/* AISConnect.h/AISConnect class was renamed to Connect.h/Connect in libdap 3.10 */
#include <Connect.h>
#define AISConnect Connect
-#else
-#include <AISConnect.h>
-#endif

#include <DDS.h>
#include <DAS.h>

@jctull
Copy link

jctull commented Nov 3, 2012

The formula was mangled from unexpected markdown. Here it is:
http://pastebin.com/uK6LQpUH

@sc0ttdav3y
Copy link

I found a world of pain getting FileGDB to work using ESRI drivers, but the good news is that as of GDAL 1.11 an open driver has been included. So now you can use homebrew to install it.

It currently requires a bit of tweaking, but here's my instructions - takes 5 mins.
http://scottdavey.net/article/Installing-GDAL-1.11-on-OSX-using-Homebrew-227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment