Hope this OGR driver for MongoDB be included into gdal main release. You may find the ticket in the gdal.org. The document here is determined to guide you compiling it with GDAL source code, so that you won't have to wait. The whole procedure is conducted in Linux OS.
Download MongoDB GDAL Driver from the MongoGIS github, MongoDB source code, GDAL source code.
- mongodb-gdal-driver-master.zip
- mongodb-src-r2.4.10.zip
- gdal192.zip
Note: after MongoDB version 2.6.0, you could not get CXX driver from its source code. See the cxx-driver in github.
Unzip those zip files, get three folders, mongodb-src-r2.6.3, gdal-1.11.0, mongodb-gdal-driver-master.
unzip *.zip
GDAL Driver will need the include files and lib from MongoDB,so we have to make it ready for use. Go to mongodb-src-r2.6.3 folder, and run, (you have to prepare the SCons to build MongoDB.
scons --prefix=/opt/mongo install
--prefix
is for the installation directory, and --full
enables the “full” installation, directing SCons to install the driver headers and libraries to the prefix directory. more info in github and mongodb.org. After the building is done, you will get three folders in the /opt/mongo
, bin
, include
, and libs
, copy the boost library
under the mongodb source code folder src/third_party/boost
into the include
folder, copy the *.a
files in the build/linux2/normal/third_party/boost/
folder into libs
.
So in the end you got a mongo folder going like this:
bin
include/mongo
include/boost
lib/libboost_filesystem.a
,lib/libboost_program_options.a
,lib/libboost_system.a
,lib/libboost_thread.a
,lib/libmongoclient.a
Move mongodb-gdal-driver-master
into gdal/ogrsf_frmts
folder and rename it as mongo
.
mv mongodb-gdal-driver-master/ gdal-1.11.0/ogr/ogrsf_frmts/mongo
Edit ogr/ogrsf_frmts/genetic/ogrregisterall.cpp
, add the RegisterOGRMONGO()
function defined in the ogrmongodriver.cpp
.
#ifdef MONGO_ENABLED
RegisterOGRMONGO();
#endif
Edit ogr/ogrsf_frmts/ogrsf_frmts.h
, add the RegisterOGRMONGO()
function defined in the ogrmongodriver.cpp
.
void CPL_DLL RegisterOGRMONGO();
Edit ogr/ogrsf_frmts/generic/GNUmakefile
, add the following code:
ifeq ($(HAVE_MONGO),yes)
CXXFLAGS := $(CXXFLAGS) -DMONGO_ENABLED
endif
Which means that if HAVE_MONGO
is defined, MONGO
will be enabled (Define MONGO_ENABLED
).
Edit ogr/ogrsf_frmts/GNUmakefile
, add the following code below the paragraph.
SUBDIRS-$(HAVE_MONGO) += mongo
The foreach sentence after the paragraph will compile each folder contained in the SUBDIRS-yes
.
Edit the configure file, add the following code in,
HAVE_MONGO=yes
MONGO_INC="-I/opt/mongo"
MONGO_LIB="-L/opt/mongo"
run configure script to generate GDALmakefile.opt, and you will find:
HAVE_MONGO = yes
MONGO_LIB = -L/opt/mongo
MONGO_INC = -I/opt/mongo
As we have the MongoDB C++ driver in the mongo folder, let's say put it under /opt
. So we have to make a little change to these settings:
HAVE_MONGO = yes
MONGO_LIB = /opt/mongo/lib
MONGO_INC = -I/opt/mongo/include
GDAL_INCLUDE += $(MONGO_INC)
LIBS += $(MONGO_LIB)/libmongoclient.a \
$(MONGO_LIB)/libboost_thread.a \
$(MONGO_LIB)/libboost_system.a \
$(MONGO_LIB)/libboost_program_options.a \
$(MONGO_LIB)/libboost_filesystem.a
These settings will tell the compiler where to find MongoDB headers and libs, otherwise you will get lots of compiling error.
use make and make install with options to install GDAL. After that find ogr2ogr utility and have a test.
# ./ogr2ogr --formats
Supported Formats:
-> "MongoDB" (read/write)
-> "ESRI Shapefile" (read/write)
-> "MapInfo File" (read/write)
-> "UK .NTF" (readonly)
-> "SDTS" (readonly)
-> "TIGER" (read/write)
-> "S57" (read/write)
-> "DGN" (read/write)
-> ...
So MongoDB OGR Driver is ready for use.