Building GDAL on Linux

From Wildsong
Revision as of 21:53, 23 October 2013 by Brian Wilson (talk | contribs)
Jump to navigationJump to search

See also my newer PostGIS page. I have GDAL build instructions there, too.

These are notes on how I have built GDAL to run on Linux systems. I do this to get the newest versions, and to add support for ESRI and MrSID files. If you don't need these things, by all means use packages. (apt-get or yum) This is extra pain that you don't need.

Oh; if you don't know what GDAL is, look at the Wikipedia entry.

Build prerequisites

sudo apt-get install subversion git
sudo apt-get install swig python-dev
sudo apt-get install cmake-qt-gui make bison flex gcc g++ libtool
sudo apt-get install lib1g-dev libcurl4-openssl-dev liblcms2-dev liblcms2-utils
sudo apt-get install libpng12-dev libtiff4-dev
sudo apt-get install libspatialite-dev

You might also need, depending on how you install PostGIS

sudo apt-get install libpq-dev

OGDI support for VMAP

http://www.gdal.org/ogr/drv_ogdi.html

sudo apt-get install ogdi-bin libogdi3.2-dev

JPEG2000

Options for JPEG2000 support include

  • LizardTech MrSID SDK (--with-jp2mrsid) (costs money to use encoder)
  • Jasper (--with-jasper)
  • Kakadu (commercial license "if you have to ask...") http://www.kakadusoftware.com/
  • OpenJPEG (--with-openjpeg)

Which is best?? Choose one

OpenJPEG

sudo apt-get install libopenjpeg-dev openjpeg-tools

Jasper

You want the Jasper from the remotesensing site, not the official one. It has support for something called GeoJP2

ftp://ftp.remotesensing.org/pub/gdal/

Building gdal on my 64-bit Debian system required this

cd jasper src dir
export CFLAGS="-fPIC -m64"
./configure
make; sudo make install
unset CFLAGS
sudo ldconfig

Non-free support

ESRI file geodatabases

NOTE 1: You won't be able to access FGDBs created before ArcGIS 10.0
NOTE 2: To get ESRI FGDB support requires gdal 1.9.0 or better

I want to be able to script loading data from file geodatabases into postgis, as described in the GDAL page. Refer to the GDAL FGDB driver page

Agree to their terms and then download the file gdb API from the ESRI site.

Here you will find build instructions.

I put the lib*so files in /usr/local/lib

cd FileGDB_API
export LD_LIBRARY_PATH=`pwd`/lib
cd samples
make
sudo cp ../lib/* /usr/local/lib
sudo ldconfig

Lizardtech MrSID raster files

Go to the Lizardtech developer site, sign up, and download the DSDK. Unpack it in a convenient place then tell gdal configure where to find it. You don't need to install anything unless you want to use their utilities.

2013-Aug-21 GDAL build

I generally build GDAL from sources so that I can add the non-standard parts such as MRSID support. (Regarding Geospatial PDF, see http://www.gdal.org/frmt_pdf.html -- there are links to further documentation and sample GeoPDF's at the bottom of this page.)

Supporting actors

Poppler is for PDF support, see also PoDoFo

# UBUNTU -- First install required prerequisite packages
sudo apt-get install libproj-dev libpoppler-dev
# DEBIAN -- I am running "lenny" with backports to get this
sudo apt-get -t lenny-backports install proj libpoppler3 libpoppler-dev

MrSID

I manually copied the libraries into /usr/local/lib and the binaries into /usr/local/bin -- Maybe I could have done the install using a script but I was too lazy to dig through their SDK to figure out how.

GEOS

wget http://download.osgeo.org/geos/geos-3.4.1.tar.bz2
tar xjf geos*bz2
cd geos*
./configure --enable-python
make -j 10
sudo make install
cd ..

I had some trouble because the GDAL build kept seeing the MrSID tools -- the commercial ones, not the SDK. MrSID uses GEOS, too, but an outdated version. Make sure your environment is not set to expose the old library to the whole system.

Spatialite

sudo apt-get install libsqlite3-dev
wget http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.1.1.tar.gz
tar xzvf libspatialite*gz
cd libspatialite-4.1.1
./configure --enable-freexl=no
make -j 10
sudo make install

Building GDAL (finally!)

cd ~/src/GIS/
svn checkout https://svn.osgeo.org/gdal/trunk/gdal gdal
cd gdal

or

cd ~/src/GIS/gdal
svn update

On my desktop on good days at home I use this, it has ESRI and MrSID installed.

./configure --with-python --with-poppler=yes \
--with-geos --with-geotiff --with-jpeg --with-png --with-expat --with-libkml --with-xerces-c \
--with-mrsid=$HOME/src/GIS/MrSID/Raster_DSDK \
--with-fgdb=$HOME/src/GIS/FileGDB_API \
--with-openjpeg --with-geos --with-pg \
--with-curl \
--with-spatialite
make -j 10
sudo make install

On bad days 03-04-13 it won't build right now so I cut a bunch of unneeded stuff out and finally got it to build with this. I don't know exactly why it won't build with all the formats above but I don't really care enough to investigate because what I am doing is trying to get to the point where I can build QGIS from source. I know ogdi and openjpeg were causing problems for me. I had to set to "no" to stop them from being included. Leaving it off the list was not enough.'

./configure --with-python --with-poppler=no \
--with-geos --with-geotiff --with-jpeg --with-png \
--with-mrsid=$HOME/src/GIS/MrSID/Raster_DSDK --with-fgdb=$HOME/src/GIS/FileGDB_API \
--with-openjpeg=no --with-pg --with-ogdi=no --with-curl

OR on my public server I use this

./configure --with-python --with-poppler=yes \
--with-openjpeg --with-geos \
--with-ogdi

OR At AGI I used this

./configure --with-python --with-poppler --with-pg --with-curl --with-openjpeg \
 --with-geos --with-geotiff --with-jpeg --with-png --with-expat --with-libkml --with-xerces-c \
 --with-mrsid=$HOME/src/GIS/MrSID/Raster_DSDK \
 --with-java=/opt/oracle/jdk1.7.0_09 --with-fgdb=$HOME/src/GIS/FileGDB_API \
 --with-mdb

Followed by

make -j 10
sudo make install

Does it work?

% gdalinfo 1501ANC4815_geo.pdf 
Driver: PDF/Geospatial PDF
Files: 1501ANC4815_geo.pdf
Size is 4470, 3375
Coordinate System is:
PROJCS["UTM Zone 48, Northern Hemisphere",
   GEOGCS["Indian 1960",
       DATUM["Indian_1960",
           SPHEROID["Everest 1830 (1937 Adjustment)",6377276.345,300.8017,
               AUTHORITY["EPSG","7015"]],
           TOWGS84[198,881,317,0,0,0,0],
           AUTHORITY["EPSG","6131"]],
       PRIMEM["Greenwich",0,
           AUTHORITY["EPSG","8901"]],
       UNIT["degree",0.0174532925199433,
           AUTHORITY["EPSG","9122"]],
       AUTHORITY["EPSG","4131"]],
   PROJECTION["Transverse_Mercator"],
   PARAMETER["latitude_of_origin",0],
   PARAMETER["central_meridian",105],
   PARAMETER["scale_factor",0.9996],
   PARAMETER["false_easting",500000],
   PARAMETER["false_northing",0],
   UNIT["Meter",1]]
GeoTransform =
 429999.053008, 42.34642896, 0.04051872
 999725.914982, 0.04124303999999999, -42.332688
Metadata:
 NEATLINE=POLYGON ((445035.80158801417565 999277.556482305750251,444993.235997625160962 991902.349403560161591,444864.738057852664497 884201.712978136376478,452159.580137342331 884208.817744017927907,585964.54743435990531 884289.527591207530349,614300.221590773784555 884383.269830735283904,614190.235319046885706 999293.477391553344205,605175.140901734353974 999218.552309990860522,553978.789515793323517 999300.979716640315019,505958.457250406034291 999353.427943945163861,451172.635888226970565 999382.750743734533899,445035.722449889173731 999360.237513555795886,445035.80158801417565 999277.556482305750251,445035.80158801417565  999277.556482305750251,445035.80158801417565 999277.556482305750251))
Corner Coordinates:
Upper Left  (  429999.053,  999725.915) (104d21'46.72"E,  9d 2'39.27"N)
Lower Left  (  430135.804,  856853.093) (104d21'58.76"E,  7d45' 6.78"N)
Upper Right (  619287.590,  999910.271) (106d 5' 7.80"E,  9d 2'41.48"N)
Lower Right (  619424.341,  857037.449) (106d 4'59.36"E,  7d45' 9.52"N)
Center      (  524711.697,  928381.682) (105d13'28.20"E,  8d23'57.68"N)
Band 1 Block=4470x1 Type=Byte, ColorInterp=Red
Band 2 Block=4470x1 Type=Byte, ColorInterp=Green
Band 3 Block=4470x1 Type=Byte, ColorInterp=Blue
JOY! It works!

To see if it built all required formats, for real, you can check:

% gdalinfo --formats
Supported Formats:
 VRT (rw+v): Virtual Raster
 GTiff (rw+v): GeoTIFF
 NITF (rw+v): National Imagery Transmission Format
 RPFTOC (rov): Raster Product Format TOC format
 HFA (rw+v): Erdas Imagine Images (.img)
 SAR_CEOS (rov): CEOS SAR Image
 CEOS (rov): CEOS Image
 JAXAPALSAR (ro): JAXA PALSAR Product Reader (Level 1.1/1.5)
 GFF (rov): Ground-based SAR Applications Testbed File Format (.gff)
 ELAS (rw+): ELAS
 AIG (rov): Arc/Info Binary Grid
 AAIGrid (rwv): Arc/Info ASCII Grid
 SDTS (rov): SDTS Raster
 DTED (rwv): DTED Elevation Raster
 PNG (rwv): Portable Network Graphics
 JPEG (rwv): JPEG JFIF
 MEM (rw+): In Memory Raster
 JDEM (ro): Japanese DEM (.mem)
 GIF (rwv): Graphics Interchange Format (.gif)
 BIGGIF (rov): Graphics Interchange Format (.gif)
 ESAT (ro): Envisat Image Format
 BSB (rov): Maptech BSB Nautical Charts
 XPM (rwv): X11 PixMap Format
 BMP (rw+v): MS Windows Device Independent Bitmap
 DIMAP (rov): SPOT DIMAP
 AirSAR (ro): AirSAR Polarimetric Image
 RS2 (ro): RadarSat 2 XML Product
 PCIDSK (rw+v): PCIDSK Database File
 PCRaster (rw): PCRaster Raster File
 ILWIS (rw+v): ILWIS Raster Map
 SGI (rw+): SGI Image File Format 1.0
 SRTMHGT (rwv): SRTMHGT File Format
 Leveller (rw+): Leveller heightfield
 Terragen (rw+): Terragen heightfield
 ISIS3 (rov): USGS Astrogeology ISIS cube (Version 3)
 ISIS2 (rov): USGS Astrogeology ISIS cube (Version 2)
 PDS (rov): NASA Planetary Data System
 TIL (ro): EarthWatch .TIL
 ERS (rw+): ERMapper .ers Labelled
 JPEG2000 (rwv): JPEG-2000 part 1 (ISO/IEC 15444-1)
 L1B (ro): NOAA Polar Orbiter Level 1b Data Set
 FIT (rwv): FIT Image
 GRIB (rov): GRIdded Binary (.grb)
 MrSID (ro): Multi-resolution Seamless Image Database (MrSID)
 JP2MrSID (ro): MrSID JPEG2000
 RMF (rw+): Raster Matrix Format
 WCS (ro): OGC Web Coverage Service
 WMS (ro): OGC Web Map Service
 MSGN (ro): EUMETSAT Archive native (.nat)
 RST (rw+): Idrisi Raster A.1
 INGR (rw+v): Intergraph Raster
 GSAG (rw): Golden Software ASCII Grid (.grd)
 GSBG (rw+): Golden Software Binary Grid (.grd)
 GS7BG (ro): Golden Software 7 Binary Grid (.grd)
 COSAR (ro): COSAR Annotated Binary Matrix (TerraSAR-X)
 TSX (ro): TerraSAR-X Product
 COASP (ro): DRDC COASP SAR Processor Raster
 R (rwv): R Object Data Store
 PNM (rw+): Portable Pixmap Format (netpbm)
 DOQ1 (ro): USGS DOQ (Old Style)
 DOQ2 (ro): USGS DOQ (New Style)
 ENVI (rw+v): ENVI .hdr Labelled
 EHdr (rw+v): ESRI .hdr Labelled
 GenBin (ro): Generic Binary (.hdr Labelled)
 PAux (rw+): PCI .aux Labelled
 MFF (rw+): Vexcel MFF Raster
 MFF2 (rw+): Vexcel MFF2 (HKV) Raster
 FujiBAS (ro): Fuji BAS Scanner Image
 GSC (ro): GSC Geogrid
 FAST (ro): EOSAT FAST Format
 BT (rw+): VTP .bt (Binary Terrain) 1.3 Format
 LAN (rov): Erdas .LAN/.GIS
 CPG (ro): Convair PolGASP
 IDA (rw+): Image Data and Analysis
 NDF (ro): NLAPS Data Format
 EIR (rov): Erdas Imagine Raw
 DIPEx (ro): DIPEx
 LCP (rov): FARSITE v.4 Landscape File (.lcp)
 GTX (rw+v): NOAA Vertical Datum .GTX
 LOSLAS (rov): NADCON .los/.las Datum Grid Shift
 NTv2 (rw+v): NTv2 Datum Grid Shift
 RIK (ro): Swedish Grid RIK (.rik)
 USGSDEM (rw): USGS Optional ASCII DEM (and CDED)
 GXF (ro): GeoSoft Grid Exchange Format
 HTTP (ro): HTTP Fetching Wrapper
 NWT_GRD (ro): Northwood Numeric Grid Format .grd/.tab
 NWT_GRC (ro): Northwood Classified Grid Format .grc/.tab
 ADRG (rw+v): ARC Digitized Raster Graphics
 SRP (rov): Standard Raster Product (ASRP/USRP)
 BLX (rw): Magellan topo (.blx)
 Rasterlite (rw): Rasterlite
 PostGISRaster (ro): PostGIS Raster driver
 SAGA (rw+v): SAGA GIS Binary Grid (.sdat)
 KMLSUPEROVERLAY (rwv): Kml Super Overlay
 XYZ (rwv): ASCII Gridded XYZ
 HF2 (rwv): HF2/HFZ heightfield raster
 OZI (rov): OZI

...all the right stuff!

Now back to Mapping Vietnam

01-Dec-2010

Building gdal 1.7.3 so I can have gdal python bindings, so I can reclassify a raster. In another window, I am running a very simple ESRI Spatial Analyst reclassification, but it's taking so long that I can probably build gdal and write a python script to do the same thing before the ESRI tool completes.

(I assume the ESRI tool crashed but as usual, I have no way of knowing.)

I had to add C++ to my system. Compiling.

Oh -- gdal built successfully. Installing it. Done. Updated system path.

Trying to build Python bindings now, what a pain! In the meantime, I clicked "cancel" button, perhaps in a few hours I will know if ArcMap crashed or not. (See comment above about failure of cancel button to cancel...)