Introduction to some Gdal tool functions

Source: Internet
Author: User

Main transfer from Http://blog.csdn.net/liminlu0314?viewmode=contents

Introduction to some Gdal tool functions

Gdalinfo.exe displays information about the various raster files supported by Gdal.

The gdal_translate.exe is converted between different formats. At the same time, there are potential tasks for cutting, resampling, and changing pixel proportions.

Gdalwarp.exe projection transformations and projection bindings. Image mosaics can also be performed. This program can re-project the supported projections, and if the image ("raw" with) control information can also store GCPS and images together

Gdaltindex.exe A shp file that creates a raster index. It can create a record for each raster: a property that contains the name of the raster, and a polygon composed of the outer bounds of the grid.

Gdal_contour.exe generates a vector contour line from a raster Dem.

Gdaltransform.exe is similar to Proj. Casts a projection transformation.

Nearblack.exe the black \ White cells in the grid to black or white. This can be used to fix the inaccuracies caused by the compression of lost information, so that it is considered transparent at the time of tessellation.

Gdal_grid.exe generate rasters from scattered points, which have interpolation meanings.

Ogrinfo.exe displaying information for ogr supported vector data

Ogr2ogr.exe for different simple vector format conversions.

Gdaladdo-Create pyramids within files to increase file opening and browsing speed.

Gdalbuildvrt-build a VRT from a list of datasets.

Gdaldem-dem analysis and visualization tools for slope, aspect, and mountain shadow analysis, as well as elevation separations rendering capabilities.

Rgb2pct.py-Converts a 24bit RGB image to a 8bit color table image.

Pct2rgb.py-Converts the 8bit color table image to a 24bit RGB image.

Gdal_merge.py-build a quick mosaic from a set of images.

gdal2tiles.py-generates a TMS tile structure that can be browsed using Google Earth (KML) or a generic web browser.

Gdal_rasterize-rasterization of vector data.

Gdal_retile.py-retiles a set of tiles and/orbuild tiled pyramid levels.

Gdal_proximity.py-compute a raster proximity map.

Gdal_polygonize.py-generate polygons from Raster.

Gdal_sieve.py-raster Sieve filter.

Gdal_fillnodata.py-interpolate in NoData regions.

Gdal-config-get options required to build software using Gdal.

Gdal Tools General Command

The following tools mainly refer to the help documentation provided in the official website of Gdal, in addition to some of my experience, Gdal official address is: http://gdal.org/gdal_utilities.html.

The following common command-line arguments are supported in all Gdal toolsets in the form of a two minus sign (-), which is described in detail below:

1.–version

The version information of the output gdal, which is the version number.

2.--formats

Output Gdal supports all image format descriptions. Includes read-only and read-write. The format support is described as follows: "RO" is a read-only driver; "RW" is a read-write driver (such as support for the Createcopy method); "rw+" is a read-write and update driver (such as support for the Create method), which supports all read-write update operations.

3.--format format

Output Gdal A single format-driven detail. The format name needs to be the format name that you want to output after--formats. such as Gtiff,hfa,pcisk and so on.

4.--optfile file

Reads a file of the specified name and passes the contents of it as a parameter to the list of command rows. If lines beginning with # are ignored. A multi-character parameter (that is, a space-separated argument) requires double quotation marks to keep it as a single parameter.

5.--config Key value

Set the configuration to set the specified key to a value so that they do not have to be set as an environment variable. Some command parameter keys are Gdal_cachemax (how much memory is used for caching) and Gdal_data (the Gdal data path). For example, after GDAL1.8, often found to not open the Chinese path of the file, then you can use this to set, specifically for "-configgdal_filename_is_utf8no". At the same time for each type of drive will have their own configuration, specific reference to the description of each driver. More configuration options refer to this URL: http://trac.osgeo.org/gdal/wiki/ConfigOptions.

6.--debug Value

Controls the printout of debug information. The on value indicates that the debug information output is allowed, and the off value indicates that the debug information is not output.

7.--help-general

Output command-line parameter help information for each tool. The contents of the different command outputs are different.

Here are some common commands that you can use to create files. The parameters required to create different formats are not the same, especially in special cases, such as the creation of the ERDAS IMG format requires no need to use compression and other special requirements. These parameters are typically started with a minus sign (-). The following is a brief description of these parameters.

8.-of format

Select the format in which you want to create a new file. This format is specified like Gtiff (GeoTiff format) or HFA (erdas format). All supported format lists can be listed with the--formats parameter. However, only the format list "(rw)" can be written and created. Many tools, if not specified, are created by default in GeoTiff format files. The file extension is not added automatically, and if you do not specify a suffix name for the file name, Gdal generally does not add any extensions. command-line parameter help information for each tool. The contents of the different command outputs are different.

9.-co Name=value

Create file options, many formats will have one or more creation parameters to control the details of file creation. For example, the IMG format of GeoTiff or erdas can be used to control compression with the creation parameters, or to control whether or not to store with sharding or partition.

The creation parameters that can be used are different depending on the format driver. Some simple formats do not create parameters at all. Although a format can list all available parameter lists with the "--format <format>" parameter, more detailed information can be found in the Format Introduction Web page. For different file formats, refer to the corresponding file format description page.

Ten.-a_srs SRS

Specifies the projection information for the output file (coordinate system). Output command-line parameter help information for each tool. The contents of the different command outputs are different. Several tools, such as Gdal_translate, Gdalwarp, can specify the coordinate system at the command line through similar-A_SRS (assign output SRS),-s_srs (source SRS),-t_srs (target SRS). These tools allow you to define a coordinate system in a series of formats (SRS is the spatial reference system spatialreference systems). SRS can usually be specified in several ways:

NAD27/NAD83/WGS84/WGS72: These common geographic coordinate systems can be used directly by name.

EPSG:N: Coordinate system (projection or geographic coordinates) can be selected by EPSG code. For example EPSG 27700 is the UK National Grid. More epsg coordinate systems can be found in the Gdal data files Gcs.csv and Pcs.csv (located in the Data folder in the Gdal directory).

proj.4 definition: A PROJ4 definition string can be used as a coordinate system definition. For example "+proj=utm +zone=11 +datum=wgs84". Note in the command line to keep the PROJ4 string together as a separate parameter (usually enclosed in double quotation marks).

OpenGIS wkt string: The OpenGIS standard defines a text format to describe a coordinate system as a part of a simple feature specification. This format is the internal working format of the coordinate system used in gdal. The file name that contains the wkt coordinate system description can be used as a coordinate system parameter, or the coordinate system element itself can also be used as a command-line parameter.

ESRI wkt Strings: Esri uses a streamlined OGC wkt format in their ArcGIS products (. prj files in ArcGIS), and this format is used in a file of a similar style to wkt. But the file name is to be ESRI:: prefix. such as "Esri::nad 1927 Stateplane wyomingwest FIPS 4904.prj".

Spatial reference URLs: You can use a spatial reference URL to specify, such as: http://spatialreference.org/ref/user/north-pacific-albers-conic-equal-area/.

FileName: You can use a file that contains a wkt, proj.4 string, or a coordinate system defined in XML/GML format.

Section Gdal Tool Description 1. Gdalinfo Output File Information

Usage:

Gdalinfo[--help-general] [-mm] [-stats][-hist] [-NOGCP] [-NOMD]

[-NOCT] [-NOFL] [-checksum] [-proj4] [-mdd domain]*

[-SD Subdataset] DatasetName

Parameter description:

The Gdalinfo program outputs a series of information gdal supported raster formats.

-mm

Forces the maximum minimum value for each band of the raster to be computed.

-stats

Read and realistic image statistics, if specified, will force the calculation of the statistics of the image, such as the maximum, minimum, mean, standard, etc. of each band.

-hist

Output histogram information for all bands.

-nogcp

Prevent the list of ground control points (GCP) from being printed. This can be very useful for a large number of GCP datasets. such as L1B AVHRR or Hdf4modis data, these data contain thousands of ground control points.

-nomd

Prohibit metadata printing, some datasets may contain a very high number of metadata strings.

-noct

Suppresses the output color table.

-checksum

Forces the calculation of the checksum of all bands in the DataSet.

-MDD Domain

Outputs the metadata information for the specified range.

-nofl

Displays only the first file information in the file list. GDAL1.9.0 begins to support this parameter.

-SD Subdataset

If the input dataset contains several sub-datasets, the specified number will be used instead of (starting at 1) for the full child dataset name. GDAL1.9.0 begins to support this parameter.

-proj4

The coordinate system of the output file is output as a string of type proj.4. GDAL1.9.0 begins to support this parameter.

Gdalinfo also outputs the following information (if any):

Format driver information for the current file

Grid data size (number of rows and columns)

File coordinate system (OGC wkt form)

Transformation parameters that the image is associated to a geography (currently does not contain a rotation factor)

Geographic boundary coordinates, if possible, a full geographic conversion parameter based on latitude and longitude (if Gcps is not)

Ground Control Point (GCPs)

All (including sub-raster metadata) file metadata

Band data type

Band Color information (Rgb,gray, etc.)

Band color Table information

Band Tile size (file block size)

Band description

Maximum band minimum value (already calculated)

Band checksum value (already computed)

Band meaningless value (NoData value)

Available thumbnail resolution for bands

Band unit type (e.g., whether the band's elevation is metric or imperial)

False color List of bands

Example:

Gdalinfof:/work/data/utm.tif

Driver:gtiff/geotiff

Sizeis 512, 512

CoordinateSystem is:

projcs["Nad27/utm zone 11N",

geogcs["NAD27",

datum["north_american_datum_1927",

spheroid["Clarke1866", 6378206.4,294.978698213901]],

primem["Greenwich", 0],

unit["degree", 0.0174532925199433]],

projection["Transverse_mercator"],

parameter["Latitude_of_origin", 0],

parameter["Central_meridian",-117],

parameter["Scale_factor", 0.9996],

parameter["false_easting", 500000],

parameter["False_northing", 0],

unit["metre", 1]]

Origin= (440720.000000,3751320.000000)

Pixelsize = (60.000000,-60.000000)

Cornercoordinates:

Upperleft (440720.000, 3751320.000) (117D38 ' 28.21 "W, 33d54 ' 8.47" N)

Lowerleft (440720.000, 3720600.000) (117D38 ' 20.79 "W, 33d37 ' 31.04" N)

Upperright (471440.000, 3751320.000) (117d18 ' 32.07 "w,33d54 ' 13.08" N)

Lowerright (471440.000, 3720600.000) (117d18 ' 28.50 "w,33d37 ' 35.61" N)

Center (456080.000, 3735960.000) (117D28 ' 27.39 "W, 33d45 ' 52.46" N)

Band1 block=512x16 Type=byte,colorinterp=gray

2. gdal_translate format Conversion

Usage:

Gdal_translate[--help-general]

[-ot{byte/int16/uint16/uint32/int32/float32/float64/

Cint16/cint32/cfloat32/cfloat64}][-strict]

[-of format] [-B band] [-mask Band] [-expand {Gray|rgb|rgba}]

[-outsize xsize[%] ysize[%]

[-unscale] [-scale [Src_min src_max[dst_min Dst_max]]

[-srcwin Xoff yoff xsize ysize] [-projwin Ulx uly LRx lry]

[-a_srs Srs_def] [-a_ullr Ulx uly Lrxlry] [-a_nodata value]

[-GCP Pixel line easting northing[elevation]]*

[-mo "Meta-tag=value"]* [-q][-sds]

[-co "Name=value"]* [-stats]

Src_dataset Dst_dataset

Parameter description:

The Gdal_translate tool can be used to convert raster data between different formats. You can also do operations such as extracting sub-rasters, resampling, and data type conversions.

-ot:type

Specifies the data type of the output band.

-strict:

For this conversion process, such as loss of data and other errors directly error, do not ignore processing. The previous parameters are called-not_strict, which means that they are treated with leniency without error.

-of format:

Select the output format. The default is GeoTiff (Gtiff). Note that the specified time is abbreviated with a format.

-B Band:

Select a band to output. The band number is numbered starting at 1. Multiple-B parameters can be used to choose to output a certain number of bands or to reorder the bands. Starting with GDAL1.8.0, the band can be set to "mask,1" (or direct mask) in terms of the first band of the input dataset as a mask band.

-mask Band:

(Starting from GDAL1.8.0) (GDAL >= 1.8.0) Select an input band as the mask band to create the output data. The number of bands is starting from 1, band can be set to none, to avoid copying the entire input dataset as a mask, otherwise by default ("Auto"), unless the mask is an alpha channel, or using the parameter-B mask to output, the parameter band can also be set to "mask,1 (or direct mask), the first band of the input dataset is used as a mask band.

-expand Gray|rgb|rgba:

(starting with GDAL1.6.0) expands a single-band file with color table information into an RGB tri-band file or an rgba four-band file. This is useful for data with output formats such as JPEG,JPEG2000,MRSID,ECW that do not support color tables. Grayscale values (starting with GDAL1.7.0) can also be expanded to a single dataset using the color table, but only one index of the grayscale level is included in the output file.

-outsize xsize[%] ysize[%]:

Sets the size of the output file. The size is expressed in pixels, unless marked with "%", at which point the output is the percentage of the input layer size.

-scale [Src_min Src_max [Dst_mindst_max]]:

Re-organizes the values of the input cells. Scale them from the Src_min~src_max range to the Dst_min ~ Dst_max range. If omitted, the output range will be 0~255. The input range is automatically calculated from the source data.

-unscale:

Presumably, this parameter is often useful when setting output file types with-ot by not scaling the data in the bands. (This parameter of English a bit around the mouth, not good translation, have to know the classmate trouble tell me).

-srcwin Xoff yoff xsize ysize:

Select a value window to copy values from the row and column position in the original image.

-projwin Ulx uly LRx lry:

Select a value window to copy data (similar to Srcwin) from the geographic coordinate range in the original image. The four values in the parameter, using the projected coordinates.

-a_srs Srs_def:

Forces the specified coordinate system to be projected on the output file. Srs_def can be the projection information for any commonly used GDAL/OGR format, such as WKT, Proj4, Epsg:n, or a file name that contains the WKT file.

-a_ullr Ulx uly LRx lry:

Forces the space Conversion boundary range (four to range of the image) for the specified output file. And the four to the range of the original image is ignored.

-a_nodata Value:

Specifies a meaningless value to the output band. Starting with GDAl1.8.0, you can set to none to use the NoData value from the original file as the NoData value of the output file.

-mo "Meta-tag=value":

If you can, set the key of the metadata to the output data and its corresponding value.

-co "Name=value":

Specify the special creation requirements for the output format with a single creation parameter. Multiple-co parameters can be used together. Creating parameters can refer to the individual data format descriptions.

-GCP Pixel line easting northingelevation:

Adds the specified ground control point to the output dataset. This option can be used multiple times to provide a range of ground control point Gcps. GCP format is: column number line number horizontal ordinate elevation value.

, q[

Quiet mode, do not output progress information and other non-error messages.

-SDS:

Copies all the child datasets in the file into their respective output files. Usually this parameter is used in the format of HDF or Ogdi, which has a sub-dataset.

-stats:

Forces the calculation (recalculation) of statistics for the data. This parameter has been supported since GDAL1.8.0.

Src_dataset:

Enter a dataset name, either a file name, or a URL address for a child dataset in a multi-dataset file (such as a sub-dataset in the HDF dataset).

Dst_dataset:

The output file name.

Example:

Convert Utm.tif to a GeoTiff file that is stored in chunks.

gdal_translate-of Gtiff-co "Tiled=yes" Utm.tif utm_tiled.tif

Create a JPEG compressed TIFF image, using an internal mask from an RGBA dataset.

Gdal_translate rgba.tifwithmask.tif-b 1-b2-b 3-mask 4-co Compress=jpeg-co Photometric=ycbcr--configgdal_tiff_interna L_mask YES

Create an RGBA image using a mask from an RGB data.

Gdal_translatewithmask.tif rgba.tif-b 1-b2-b 3-b Mask

3. Gdaladdo Build Pyramids

Usage:

Gdaladdo[-r{nearest,average,gauss,cubic,average_mp,average_magphase,mode}]

[-ro] [-clean] [--help-general]filename Levels

Parameter description:

The Gdaladdo tool can be used to build or rebuild pyramids for most supported formats. You can use one of the following resampling algorithms to reduce the resampling operation.

-r{nearest (default), Average,gauss,cubic,average_mp,average_magphase,mode}:

Specifies the Resampling method, which is nearest neighbor (default), mean value, Gaussian, cubic convolution, and so on.

-ro:

(Valid from GDAL1.6.0), open the data in a read-only manner to create an external pyramid (especially for GeoTiff).

-clean:

Delete all the pyramids. (Valid starting from GDAL1.7.0).

FileName

The file name of the pyramid to be created.

Levels:

The list of layer numbers to create a thumbnail. If you use the-clean option, it is ignored.

mode, (valid from GDAL1.6.0) Select the most common resampling method. AVERAGE_MP is an unsuitable, average_magphase image used for complex data spaces. Nearest and average are used for normal images. Nearest uses nearest neighbor sampling (simple sampling), which calculates the mean value of all valid values. Cubic sampling (valid from GDAL1.7.0) uses a 4x4 approximate cubic convolution core. Gauss sampling (valid from GDAL1.6.0) is calculated using the Gaussian kernel. This is better for images with high contrast and pattern boundaries. The general recommended sampling ratio is the 2,4,8,..., using 3x3 resampling as the calculation window for Gaussian sampling.

Gdaladdo will adhere to the correct nodata_values tuple (special data set metadata), so only a given RGB triples (in the case of an RGB image) as nodata values, rather than having separate nodata values for each band.

Selecting a zoom level value, such as 2, indicates that the thumbnail zoom level is 1/2 of the resolution on each dimension of the source image. If the file already has a thumbnail at the selected zoom level, the thumbnails at that zoom level will be recalculated and overwritten by the write.

Some formats do not support pyramids at all. Therefore many formats are outside the file with the extension. OVR storage pyramid, which is the case with TIFF. The GeoTiff format stores the pyramids directly in the original file. Unless specified by using the-ro tag. Creating pyramids in TIFF can be compressed by using Compress_overview configuration parameters. All GeoTiff supported compression methods can be obtained here (e.g.,--config compress_overviewdeflate).

Most drivers also support an alternate thumbnail format (using the ERDAS image format). To use this alternate format, use Use_rrd=yes to set the parameters. Doing so will put the pyramids created by the Gdal program into a secondary. Aux file so that the pyramids can be used directly in the Erdas or in ArcGIS. For information on how to create pyramids in erdas format using Gdal, refer to my blog: http://blog.csdn.net/liminlu0314/article/details/6127755.

Example:

Create pyramids inside the specified TIFF file:

Gdaladdo-r Average Abc.tif 2 4 8 16

Create an external compressed pyramid file from a erdas.img file:

Gdaladdo--config compress_overviewdeflateerdas.img 2 4 8 16

Create a Erdas Imagine format pyramid for a given JPEG file:

Gdaladdo--config use_rrd YES airphoto.jpg39 27 81

Introduction to some Gdal tool functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.