Skip to content

GDAL Ruby SWIG bindings

Oleksii Leonov edited this page Oct 24, 2017 · 2 revisions

Useful info

Build bindings

wget http://download.osgeo.org/gdal/2.2.2/gdal-2.2.2.tar.gz
tar -zxvf gdal-2.2.2.tar.gz && cd gdal-2.2.2
cd swig/ruby

swig -Wall -I../include -I../include/ruby -I../include/ruby/docs -I../.. -c++ -ruby -autorename -prefix "Gdal::" -o gdal.cpp ../include/gdal.i
swig -Wall -I../include -I../include/ruby -I../include/ruby/docs -I../.. -ruby -autorename -prefix "Gdal::" -o gdalconst.c ../include/gdalconst.i
swig -Wall -I../include -I../include/ruby -I../include/ruby/docs -I../.. -c++ -ruby -autorename -prefix "Gdal::" -o osr.cpp ../include/osr.i
swig -Wall -I../include -I../include/ruby -I../include/ruby/docs -I../.. -c++ -ruby -autorename -prefix "Gdal::" -o ogr.cpp ../include/ogr.i

Renaming GetDriver & GetDriverByName

This actions required only when you need to use gdal and ogr methods in same code.

There is old issue with names when require gdal-ruby/gdal and gdal-ruby/ogr same time: https://github.com/zhm/gdal-ruby/issues/2.

Workaround — rename OGR GetDriverByName and GetDriver (in ogr.i from gdal source gdal/swig/include) to OGR_GetDriverByName and OGR_GetDriver. After that rebuild wrappers with SWIG, and get functions ogr_get_driver_by_name and ogr_get_driver for Ruby.

Now use Gdal::Ogr.ogr_get_driver_by_name instead of Gdal::Ogr.get_driver_by_name in Ruby.

Clone this wiki locally