GDAL reference: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
Line 67: Line 67:


To reproject data, use [http://gdal.org/gdalwarp.html gdalwarp]
To reproject data, use [http://gdal.org/gdalwarp.html gdalwarp]


I had trouble going from NAD83HARN to NAD27. Using --debug on reveals no datum is defined, even though it is in the SID.
I had trouble going from NAD83HARN to NAD27. Using --debug on reveals no datum is defined, even though it is in the SID.
Line 84: Line 83:
  '''+datum=NAD83'''
  '''+datum=NAD83'''
  +units=m +no_defs
  +units=m +no_defs
Still no go, so I try referring to http://trac.osgeo.org/proj/wiki/FAQ


=== Mosaic ===
=== Mosaic ===

Revision as of 19:58, 13 April 2011

General notes

It can be helpful to run gdalwarp with the commandline option "--debug on" in which case the debug output should include the PROJ.4 rendering of the source and destination coordinate system.

At a very low level you can also define the PROJ_DEBUG environment variable to the value ON and PROJ.4 will report some details on what datum files are opened.


Clip or Extract

Geometric

If you want to clip a rectangle out of a larger raster, for example to remove the collar from a scanned map, you can use gdal_translate but only if the input raster is not in a spherical projection. (For example, if it's in WGS84 (EPSG 4326) this will work.)

If the data is not projected you can use a gdal_translate command with either projwin or srcwin specifying a window on the command line.

If it is projected it will fail.

Using a mask

This tutorial shows how to use a shapefile to clip a raster: http://linfiniti.com/2009/09/clipping-rasters-with-gdal-using-polygons/

I want to use the neatline from a GeoPDF to remove the collar from a USGS scanned map. To do this, I need to make a polygon in a shapefile from the points in the neatline.

Distance

gdal_proximity

Generalization

gdal_sieve

Raster polygons smaller than a provided threshold size (in pixels) and replaces replaces them with the pixel value of the largest neighbour polygon. The result can be written back to the existing raster band, or copied into a new file.

Map algebra

Data conversion

Raster colorspaces conversion

rgb2pct.py

pct2rgb.py

Raster to Raster

Use gdal_translate

Raster to Polygon

gdal_polygonize

Vector to Raster

gdal_rasterize

X,Y Table to Vector File

Data management

Projections

To reproject data, use gdalwarp

I had trouble going from NAD83HARN to NAD27. Using --debug on reveals no datum is defined, even though it is in the SID.

OGRCT: Source: +proj=lcc +lat_1=44.33333333333334
+lat_2=46 +lat_0=43.66666666666666 +lon_0=-120.5
+x_0=2500000 +y_0=0
+ellps=GRS80
+units=m +no_defs

I can override the source SRS on the command line, which gives me same results when I define it as HARN. When I override it and leave out the HARN, it finds the datum correctly. This is a bug.

OGRCT: Source: +proj=lcc +lat_1=44.33333333333334
+lat_2=46 +lat_0=43.66666666666666 +lon_0=-120.5
+x_0=2500000 +y_0=0
+datum=NAD83
+units=m +no_defs

Still no go, so I try referring to http://trac.osgeo.org/proj/wiki/FAQ

Mosaic

The gdal_merge command creates a single raster output from several inputs. It does this the old-fashioned way by copying pixels.

Build raster catalog

(Or, "what is a VRT")

In GDAL world this is called a VRT = Virtual Dataset (which in my mind would abbreviate to "VD" but no one asked me.)

To build one you can use gdalbuildvrt

I think it creates a small file referencing the members of the dataset, which can then be processed by GDAL commands that accept only one input file.

Surfaces

Contour

To build a vector contour layer from an elevation dataset, use gdal_contour

Raster surfaces

To generate raster surfaces from an elevation dataset, use gdaldem

The list of surfaces you can generate includes

  • hillshade
  • color relief
  • shaded relief
  • slope
  • aspect
  • terrain ruggedness index
  • topographic position index
  • roughness