Geospatial Data Abstraction Library

GDAL INTRODUCTION

GDAL is a translator library for raster and vector geospatial data formats that is released under an X/MIT style Open Source license by the Open Source Geospatial Foundation. This library is very important when we are working with rasters and vectors. It supports 155 raster and 95 vector formats. This library is available in C++, C#, Python, Java and Ruby for Linux, Mac and Windows platform. For more information you can refer to GDALWiki.

DOWNLOAD & SETUP

You can download the executable GDAL packages (stable releases) from GISinternals. Choose compiler (Microsoft Visual C) & architecture (32bit or 64bit) depending upon your PC and download the compiled binaries zip file (not the Compiled libraries and headers).

Or in short download the compiled binaries of GDAL from the below links

Now Follow the below mentioned Setup procedure:

  1. Extract the zip file and save in some drive preferably C drive.
  2. Now create/append the following data in your PC Environmental Variables (Computer --> Properties -->Advance System Settings -->Environment variables):

    CREATE/APPENDVARIABLEVALUEREQUIREMENT
    CREATEGDAL_DATAC:\gdal\bin\gdal-dataMANDATORY
    CREATEGDAL_DRIVER_PATHC:\gdal\bin\gdal\pluginsMANDATORY
    APPENDPATHC:\gdal\binMANDATORY
    APPENDPATHC:\gdal\bin\gdal\appsOPTIONAL

  3. The last append option is required if you want to use the gdal tools from any location in your PC.

Every raster file is associated with georeferencing information which is used by GIS applications. This georeferencing information may be in the form of PAM (Persistent Auxiliary metadata) .aux.xml sidecar file, INTERNAL, TABFILE (.tab) or WORLDFILE. By default GDAL uses one of these forms in the priority order as mentioned above. This priority order can be changed (for GDAL v2.2+) with the GDAL_GEOREF_SOURCES configuration option (or GEOREF_SOURCES open option) whose value is a comma-separated list of the following keywords : PAM,INTERNAL,TABFILE,WORLDFILE,NONE. First mentioned sources are the most priority over the next ones. A non mentioned source will be ignored.

For example set Environmental variable GDAL_GEOREF_SOURCES and value as WORLDFILE,PAM,INTERNAL,TABFILE,NONE for giving first priority to Worldfile.

Now you test the GDAL tools. Open Command prompt in your PC and type gdalinfo --formats. This command will list out the type of raster formats it supports. Alternatively ogrinfo --formats will display vector formats.

If before showing the raster/vector formats, the command prompt window shows some error with .dll file like ogr_OCI.dll or/and gdal_GEOR.dll then you can delete these files from C:\gdal\bin\gdal\plugins folder.

Now you have setup GDAL in your PC and ready to go. Below we will see some important gdal tools which can help us in dealing with rasters and vectors.

Raster formats supported by GDAL

  • BAG (ro): Bathymetry Attributed Grid
  • ECW (rov): ERDAS Compressed Wavelets (SDK 5.0)
  • JP2ECW (rov): ERDAS JPEG2000 (SDK 5.0)
  • FITS (rw+): Flexible Image Transport System
  • GeoRaster (rw+s): Oracle Spatial GeoRaster
  • GMT (rw): GMT NetCDF Grid Format
  • HDF4 (ros): Hierarchical Data Format Release 4
  • HDF4Image (rw+): HDF4 Dataset
  • HDF5 (ros): Hierarchical Data Format Release 5
  • HDF5Image (ro): HDF5 Dataset
  • MrSID (rov): Multi-resolution Seamless Image Database (MrSID)
  • netCDF (rw+s): Network Common Data Format
  • VRT (rw+v): Virtual Raster
  • GTiff (rw+vs): GeoTIFF
  • NITF (rw+vs): National Imagery Transmission Format
  • RPFTOC (rovs): Raster Product Format TOC format
  • ECRGTOC (rovs): ECRG TOC format
  • HFA (rw+v): Erdas Imagine Images (.img)
  • SAR_CEOS (rov): CEOS SAR Image
  • CEOS (rov): CEOS Image
  • JAXAPALSAR (rov): JAXA PALSAR Product Reader (Level 1.1/1.5)
  • GFF (rov): Ground-based SAR Applications Testbed File Format (.gff)
  • ELAS (rw+v): ELAS
  • AIG (rov): Arc/Info Binary Grid
  • AAIGrid (rwv): Arc/Info ASCII Grid
  • GRASSASCIIGrid (rov): GRASS 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 (rov): Japanese DEM (.mem)
  • GIF (rwv): Graphics Interchange Format (.gif)
  • BIGGIF (rov): Graphics Interchange Format (.gif)
  • ESAT (rov): 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 (ros): 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 (rw+v): USGS Astrogeology ISIS cube (Version 2)
  • PDS (rov): NASA Planetary Data System
  • TIL (rov): EarthWatch .TIL
  • ERS (rw+v): ERMapper .ers Labelled
  • JP2OpenJPEG (rwv): JPEG-2000 driver based on OpenJPEG library
  • L1B (rovs): NOAA Polar Orbiter Level 1b Data Set
  • FIT (rwv): FIT Image
  • GRIB (rov): GRIdded Binary (.grb)
  • RMF (rw+v): Raster Matrix Format
  • WCS (rovs): OGC Web Coverage Service
  • WMS (rwvs): OGC Web Map Service
  • MSGN (ro): EUMETSAT Archive native (.nat)
  • RST (rw+v): Idrisi Raster A.1
  • INGR (rw+v): Intergraph Raster
  • GSAG (rwv): Golden Software ASCII Grid (.grd)
  • GSBG (rw+v): Golden Software Binary Grid (.grd)
  • GS7BG (rw+v): Golden Software 7 Binary Grid (.grd)
  • COSAR (ro): COSAR Annotated Binary Matrix (TerraSAR-X)
  • TSX (rov): TerraSAR-X Product
  • COASP (ro): DRDC COASP SAR Processor Raster
  • R (rwv): R Object Data Store
  • MAP (rov): OziExplorer .MAP
  • PNM (rw+v): Portable Pixmap Format (netpbm)
  • DOQ1 (rov): USGS DOQ (Old Style)
  • DOQ2 (rov): USGS DOQ (New Style)
  • ENVI (rw+v): ENVI .hdr Labelled
  • EHdr (rw+v): ESRI .hdr Labelled
  • GenBin (rov): 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 (rov): GSC Geogrid
  • FAST (rov): EOSAT FAST Format
  • BT (rw+v): VTP .bt (Binary Terrain) 1.3 Format
  • LAN (rw+v): Erdas .LAN/.GIS
  • CPG (ro): Convair PolGASP
  • IDA (rw+): Image Data and Analysis
  • NDF (rov): NLAPS Data Format
  • EIR (rov): Erdas Imagine Raw
  • DIPEx (rov): DIPEx
  • LCP (rwv): FARSITE v.4 Landscape File (.lcp)
  • GTX (rw+v): NOAA Vertical Datum .GTX
  • LOSLAS (rov): NADCON .los/.las Datum Grid Shift
  • NTv2 (rw+vs): NTv2 Datum Grid Shift
  • CTable2 (rw+v): CTable2 Datum Grid Shift
  • ACE2 (rov): ACE2
  • SNODAS (rov): Snow Data Assimilation System
  • KRO (rw+v): KOLOR Raw
  • ARG (rwv): Azavea Raster Grid format
  • RIK (ro): Swedish Grid RIK (.rik)
  • USGSDEM (rwv): USGS Optional ASCII DEM (and CDED)
  • GXF (ro): GeoSoft Grid Exchange Format
  • HTTP (ro): HTTP Fetching Wrapper
  • NWT_GRD (rov): Northwood Numeric Grid Format .grd/.tab
  • NWT_GRC (rov): Northwood Classified Grid Format .grc/.tab
  • ADRG (rw+vs): ARC Digitized Raster Graphics
  • SRP (rovs): Standard Raster Product (ASRP/USRP)
  • BLX (rw): Magellan topo (.blx)
  • Rasterlite (rws): Rasterlite
  • PostGISRaster (rws): 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
  • PDF (rwvs): Geospatial PDF
  • OZI (rov): OziExplorer Image File
  • CTG (rov): USGS LULC Composite Theme Grid
  • E00GRID (rov): Arc/Info Export E00 GRID
  • ZMap (rwv): ZMap Plus Grid
  • NGSGEOID (rov): NOAA NGS Geoid Height Grids
  • MBTiles (rov): MBTiles
  • IRIS (rov): IRIS data (.PPI, .CAPPi etc)

Vector formats supported by GDAL

  • -> "OCI" (read/write)
  • -> "ESRI Shapefile" (read/write)
  • -> "MapInfo File" (read/write)
  • -> "UK .NTF" (readonly)
  • -> "SDTS" (readonly)
  • -> "TIGER" (read/write)
  • -> "S57" (read/write)
  • -> "DGN" (read/write)
  • -> "VRT" (readonly)
  • -> "REC" (readonly)
  • -> "Memory" (read/write)
  • -> "BNA" (read/write)
  • -> "CSV" (read/write)
  • -> "NAS" (readonly)
  • -> "GML" (read/write)
  • -> "GPX" (read/write)
  • -> "LIBKML" (read/write)
  • -> "KML" (read/write)
  • -> "GeoJSON" (read/write)
  • -> "Interlis 1" (read/write)
  • -> "Interlis 2" (read/write)
  • -> "GMT" (read/write)
  • -> "GPKG" (read/write)
  • -> "SQLite" (read/write)
  • -> "ODBC" (read/write)
  • -> "WAsP" (read/write)
  • -> "PGeo" (readonly)
  • -> "MSSQLSpatial" (read/write)
  • -> "PostgreSQL" (read/write)
  • -> "MySQL" (read/write)
  • -> "PCIDSK" (read/write)
  • -> "OpenFileGDB" (readonly)
  • -> "XPlane" (readonly)
  • -> "AVCBin" (readonly)
  • -> "AVCE00" (readonly)
  • -> "DXF" (read/write)
  • -> "Geoconcept" (read/write)
  • -> "GeoRSS" (read/write)
  • -> "GPSTrackMaker" (read/write)
  • -> "VFK" (readonly)
  • -> "PGDump" (read/write)
  • -> "OSM" (readonly)
  • -> "GPSBabel" (read/write)
  • -> "SUA" (readonly)
  • -> "OpenAir" (readonly)
  • -> "PDS" (readonly)
  • -> "WFS" (readonly)
  • -> "HTF" (readonly)
  • -> "AeronavFAA" (readonly)
  • -> "Geomedia" (readonly)
  • -> "EDIGEO" (readonly)
  • -> "GFT" (read/write)
  • -> "GME" (read/write)
  • -> "SVG" (readonly)
  • -> "CouchDB" (read/write)
  • -> "Idrisi" (readonly)
  • -> "ARCGEN" (readonly)
  • -> "SEGUKOOA" (readonly)
  • -> "SEGY" (readonly)
  • -> "ODS" (read/write)
  • -> "XLSX" (read/write)
  • -> "ElasticSearch" (read/write)
  • -> "PDF" (read/write)
  • -> "Walk" (readonly)
  • -> "CartoDB" (readonly)
  • -> "SXF" (readonly)

GDAL TOOLS

The are many GDAL tools you will find in C:\gdal\bin\gdal\apps folder. Some of which are explained below.

  • gdalinfo: Dispalys geospatial information of raster data.
  • gdallocationinfo: It returns the pixel value at provided position of the raster file.
  • gdalbuildvrt: It builds a virtual raster file (xml file) for one or many raster data.
  • gdal_translate: It converts raster data from one format to another.
  • gdaladdo: It creates raster data overview/pyramid layers internally or externally.
  • gdalwarp: It converts the raster data in desired coordinate system.
  • gdalsrsinfo: It gives the coordinate system information of the raster data.
  • gdaltindex: It creates a tile index shape file of raster data.
  • ogr2ogr: It converts one vector format to other.
  • ogrtindex: It creates a tile index shape file of vector data.
  • ogrinfo: Displays geometry information of vector data.

1. gdalinfo : Suppose you have got a raster file in your system say D:\raster\bluemarbel.tif and you want to read the geospatial information in its header file, then run the following command in the command prompt of your PC and press enter.

gdalinfo D:\raster\bluemarbel.tif

You will see the following information. This information is stored in raster data header and GDAL helps us to display it in human readable format. Look the displayed information carefully.

Driver: GTiff/GeoTIFF
Files: D:\raster\bluemarbel.tif
Size is 21600, 21600
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (-180.000000000000000,90.000000000000000)
Pixel Size = (0.002083333333333,-0.002083333333333)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (-180.0000000,  90.0000000) (180d 0' 0.00"W, 90d 0' 0.00"N)
Lower Left  (-180.0000000,  45.0000000) (180d 0' 0.00"W, 45d 0' 0.00"N)
Upper Right (-135.0000000,  90.0000000) (135d 0' 0.00"W, 90d 0' 0.00"N)
Lower Right (-135.0000000,  45.0000000) (135d 0' 0.00"W, 45d 0' 0.00"N)
Center      (-157.5000000,  67.5000000) (157d30' 0.00"W, 67d30' 0.00"N)
Band 1 Block=512x512 Type=Byte, ColorInterp=Red
  Overviews: 10800x10800, 5400x5400, 2700x2700, 1350x1350, 675x675, 338x338, 169x169, 85x85, 43x43
Band 2 Block=512x512 Type=Byte, ColorInterp=Green
  Overviews: 10800x10800, 5400x5400, 2700x2700, 1350x1350, 675x675, 338x338, 169x169, 85x85, 43x43
Band 3 Block=512x512 Type=Byte, ColorInterp=Blue
  Overviews: 10800x10800, 5400x5400, 2700x2700, 1350x1350, 675x675, 338x338, 169x169, 85x85, 43x43

Driver: GDAL has got various drivers for reading the header information of various raster formats. For this raster (tif format) it used GTiff/GeoTIFF driver.

Files: It displays the files GDAL operated to extract the geospatial information. If there were external pyramid layers (bluemarbel.aux) along with this raster file, it would have displayed it also.

Size: It represents the width and height of the raster data in terms of pixels. This raster file has 21600 pixels along its width and 21600 pixels along its height.

Coordinate system: The Coordinate system of the raster data is represented in WKT (Well-Known Text) format.In this format the datum is mentioned as WGS 84 and projection as EPSG:4326 which is equivalent to WGS84 in LatLong projection. You can even see the radius of earth value (6378137), flattening value (298.257223563) and unit (degree). Refer for more information on various EPSG (European Petroleum Survey Group) projections.

Origin: Origin represents the Coordinate of the centre of the Upper-left pixel of the raster data.

Pixel Size: This represents how much units (degrees in this case) each pixel covers. In case the projection system were in UTM, then pixel size would have been represented in meters.

Corner Coordinates: This information is displayed in five parts as Upper Left, Lower Left, Upper Right, Lower Right and Center. You can observe that each cordinates have been written twice. First one is in the projection system which the data has and the next in Degree Minute Second.

Bands & Overviews: Band will display different band information like block size (512 pixel x 512 pixel), datatype (Byte i.e 8bit) and color of the band like red, blue, green or gray. Overview displays the number of pyramid layers (internal or external) the raster data has. In this case it has got 9 pyramid layers.

2. gdallocationinfo: This utility provide a mechanism to query information about a pixel given it's location in one of a variety of coordinate systems. This utility is very usefulwhen we want to find out the height of a perticular location in terms of coordinates. You can Download all DEM files of you area of interest.

For example if you have a dem file at location D:\GDem\ASTGTM2_N27E086_dem.tif and you want to find the height at latitude 27.45 & longitude 86.29, run the following command in commad prompt

gdallocationinfo -geoloc -valonly D:\GDem\ASTGTM2_N27E086_dem.tif 86.29 27.45

The output will be 1765.

This perticular DEM will give you height value only in the latitude range 27-28 and longitude range 86-87. What if you have downloaded all the DEM files and you want to query a single file instead of different DEM file for every different location? You need a mosaic of all DEM. But this will result in a very BIGTIFF data. For such problems, GDAL has provided a tool called gdalbuildvrt which is explained below.

3. gdalbuildvrt: This utility builds a virtual raster data in vrt (xml) format which has the reference of one or more raster files. Suppose you want to create a single vrt file Gdem.vrt for all DEM files downloaded, you can run the following command

gdalbuildvrt D:/GDem/GDem.vrt D:/GDEMv2/TIF/*.tif

Now you can run the gdallocationinfo command on a single raster file called GDem.vrt for all coordinates.

If you want to create a vrt file raster data having different coordinate systems, then add -a_srs EPSG:4326 after gdalbuildvrt above.

4. gdal_translate: This utility is used to convert one raster data to another format in compressed (optional) way. We will not be using this command but you can convert a raster format (8bit) to JPG format with 25% compression in EPSG:4326 coordinate system as follows

gdal_translate -a_srs EPSG:4326 -outsize 25% 25% -of JPEG D:/Raster/A.tif D:/Raster/A.jpg

5. gdaladdo: This tool will be used to create the overview (pyramid) layers of raster files so as to enable it render fast when opened in geospatial viewer or through WMS (Web Map Service). You can create pyramid layers internally or externally. But remember that if internal pyramid layers are created, they cannot be cleanly removed and will not allow further pyramids to be created externally. Hence go for external pyramid creation preferably in .aux format. For example the following command creates external pyramid layers in .aux format in 6 layers (2 4 8 16 32 64).

gdaladdo -r NEAREST --config USE_RRD YES D:/Raster/A.tif 2 4 8 16 32 64

If the given raster data was of 21600x21600 size then the pyramid layers will have 10800x10800, 5400x5400, 2700x2700, 1350x1350, 675x675, 338x338.

6. gdalwarp: This creates a new raster data with new coordinate system. We will not be using this tool. If you want to create a raster data in EPSG:4326 coordinate system irrespective of its original coordinate system, then run the following command

gdalwarp -t_srs EPSG:4326 D:/Raster/A.tif D:/Raster/A_reproj4326.tif

7. gdalsrsinfo: This tool displays the Spatial Reference System (SRS) of the raster in WKT (Well Known Text) format and PROJ.4 format.

For example

gdalsrsinfo D:\Raster\A.tif

The following will be the output for this raster data:

PROJ.4 : '+proj=longlat +datum=WGS84 +no_defs '

OGC WKT :
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
	

8. gdaltindex: GDALtindex is used to create a tile index shape file having the location details of all the raster files along with the boundary geometry. This utility is very useful when rendering a large number of raster data through WMS server like MS4W (Map Server 4 Windows).

For example you want to display all Landsat satellite data on a web page through WMS service, then use the tile index shape file instead of using the raster files directly. Create a tile index shape file (rastertindex.shp) using the following command

gdaltindex D:/Raster/rastertindex.shp D:/Raster/*.tif

If you have a collection of raster files in a folder but all have different Coordinate system, then you can save the coordinate system in tile index shape file as a column in EPSG format which is very useful when rendering raster through WMS service. Do it suing the following command

gdaltindex -t_srs EPSG:4326 -src_srs_name epsg_no D:/Raster/rastertindex.shp D:/Raster/*.tif

where -t_srs is the image boundary calculated in EPSG:4326 and epsg_no is the column of tile index shape file which saves the coordinate system of each raster data in epsg format.

9. ogr2ogr: This is an important tool which is used to convert vector data from one format to another.

For example, if we want to create KML file new vector.kml from shape.shp shapefile we can run the following command

ogr2ogr -f "KML" D:\vector\newvector.kml D:\vector\shape.shp

We can also create shapefile from geospatial database table having geometry column. Suppose we have got a table oStable in Oracle spatial, then we can create shapefile from this table as follows

ogr2ogr -f "Shapefile" D:\vector\newvector.shp OCI:dbusername/dbpassword@orcl -sql "Select * from OStable"

where dbusername is the database username, dbpassword is database password and orcl is the SID. You can even run a conditional query in -sql option and save the result in shapefile.

Sometimes it is required to merge two or more shapefiles into one, this can be accomplished with ogr2ogr tool using the following command for each shapefile to be merged.

ogr2ogr -f "ESRI Shapefile" D:\Merged.shp -update -append C:\FirstSHP.shp

ogr2ogr -f "ESRI Shapefile" D:\Merged.shp -update -append C:\SecondSHP.shp

This will mearge FirstSHP.shp and SecondSHP.shp shapefiles into Merged.shp.

10. ogrtindex: This has got the similar function as gdaltindex provided it takes vector files only.

11. ogrinfo: It displays the geometry information of a vector file. To see the geometry infomation like its coordinate system, contents and geometry details run the following command

ogrinfo -al D:\vector\newvector.kml

For this query find the output yourself. You can even run the conditional query to filter the content of a vector file.

QUICK LINKS
Coordinates

Earth Shape

Ellipsoid & Geoid

Datum

Projection

UTM

Rasters

Vectors
GDAL

GDAL Setup

GDAL Rasters

GDAL Vectors

GDAL Tools
WMS

MS4W

Spatial DB

Oracle Spatial

SDO_GEOMETRY

Geo-Crawler
Web Clients

Openlayers

OL3

Closest Distance Map

Openlayers v2.x

ThreeJS

Terrain Viewer

Bluemarble (250m tiff)

JS Tools

Geographiclib

JS2Shapefile

CSV2Shape


GeoSpatialEarth.in Copyright © All rights reserved.