Gdal comprehensive sorting-7: Introduction to gdal Utility

Source: Internet
Author: User
Document directory
  • 1. gdalinfo output file information
  • 2. gdal_translate format conversion
  • 3. Create a pyramid in gdaladdo

On the Internet, I can see that this article is fully written, and it is in Chinese. I just turned around and learned it.
Some of the content is repeated, but it does not affect. Very good information.

Mainly from http://blog.csdn.net/liminlu0314? Viewmode = Contents

Introduction to some gdal tools


Gdalinfo.exe displays information about various grid files supported by gdal.

Gdal_translate.exe is converted between different formats. At the same time, some tasks such as cutting, re-sampling, and changing the pixel ratio are potentially executed.

Gdalwarp.exe projection conversion and projection binding. You can also perform image mosaic. This program can re-project the supported projection, and if the image ("Raw" with) control information can also store GCPs and images together

Gdaltindex.exe creates the SHP file for the grid index. It creates a record for each raster data: an attribute containing the raster name and a polygon consisting of the outer border of the raster.

Gdal_cmd.exe generates vector contour lines from a grid DEM.

Gdaltransform.exe is similar to proj. Projection conversion.

Nearblack.exe sets the black/white pixels in the grid to black or white. This can be used to fix the inaccuracy caused by compression loss of information, so that it can be viewed as transparent during mosaic.

Gdal_grid.exe generates a grid from Scattered Points, which indicates interpolation.

Ogrinfo.exe displays information about vector data supported by OGR.

Ogr2ogr.exe converts different simple vector formats.

Gdaladdo-create a pyramid in a file to increase the file opening and browsing speed.

Gdalbuildvrt-Build a VRT from a list of datasets.

Gdaldem-DEM analysis and visualization tools can be used for slope, slope aspect, and shadow analysis, as well as elevation color separation rendering.

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

Pct2rgb. py-converts an 8-bit color table image to a 24-bit RGB image.

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

Gdal2tiles. py-generates the TMS tile structure, which can be viewed by Google Earth (kml) or a general web browser.

Gdal_rasterize-Raster 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.

Common commands for gdal tools

The following tools mainly refer to the help documentation provided on the gdal official website and some of my experiences. The official gdal address is http://gdal.org/gdal_utilities.html.

 

In all gdal tool sets, the following common command line parameters are supported. Generally, the form starts with two minus signs (--). The following details:

 

1.-version

Output the version information of gdal, that is, the version number.

 

2. -- formats

Output The format description of all images supported by gdal. Including read-only and read-write. The supported formats are as follows: "Ro" is a read-only driver; "RW" is a read/write driver (for example, the createcopy method is supported ); "RW +" is a read/write and update driver (such as supporting the create method) and supports all read/write update operations.

 

3. -- format

Output the details of the gdal driver in a single format. The format name must be after -- formats to list the format names to be output. For example, gtiff, HFA, and pcisk.

 

4. -- optfile File

Read the file with the specified name and pass the content as a parameter to the command line list. If the row starting with # is ignored. Parameters composed of multiple characters (parameters separated by spaces in the middle) must be enclosed in double quotation marks to ensure that they are a single parameter.

 

5. -- Config Key Value

Set the configuration and set the specified key to a value, so that you do not have to set them as environment variables. Some command parameter keys are gdal_cachemax (MB of memory used for caching) and gdal_data (gdal data path ). For example, after gdal1.8, you may often find files that cannot open the Chinese path. You can use this to set it to "-configgdal_filename_is_utf8no ". Each driver has its own configuration. For more information, see the description of each driver. For more configuration options, see http://trac.osgeo.org/gdal/wiki/configoptions.

 

6. -- debug value

Control the output of debugging information. The on value indicates that debugging information is allowed to be output, and the off value indicates that debugging information is not output.

 

7. -- Help-General

The command line parameter help information of each tool is output. Different command outputs have different content.

The following are some common commands used to create files. Parameters required for creating different formats are different, especially in special cases, for example, the IMG format of the created ERDAS does not need to be compressed. These parameters generally start with a minus sign. The following is a simple description of these parameters.

8.-Of format

Select the format of the file to be created. This format is specified to be similar to gtiff (geotiff format) or HFA (ERDAS format ). You can use the -- formats parameter to list all supported formats. However, only the format List "(RW)" can be written and created. If not specified by many tools, files in geotiff format are created by default. The file extension is not automatically added. If no extension is specified for the file name, gdal generally does not add any extension. Command Line Parameter help information of each tool. Different command outputs have different content.

 

9.-Co name = Value

File Creation option. Many formats 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 creation parameters, or whether to use sharding or splitting for storage.

 

The available creation parameters vary depending on the format driver. In some simple formats, no parameters are created. Although a format can use the "-- format <format>" parameter to list all available parameter lists, more detailed information can be found on the format overview page. For different file formats, see the corresponding file format description webpage.

 

10.-a_srs SRS

Specifies the projection information of the output file (Coordinate System ). The command line parameter help information of each tool is output. Different command outputs have different content. Several tools (such as gdal_translate and gdalwarp) can be used in the command line like-a_srs (allocate output SRs),-s_srs (source SRs),-t_srs (target SRs) to specify the coordinate system. These tools allow defining coordinate systems in a series of formats (SRS is the space Reference System spatialreference system ). SRS can be specified in the following ways:

 

Nad27/nad83/WGS84/wgs72: these common geographic coordinate systems can be directly used by name.

Epsg: N: the coordinate system (projection or geographic coordinate) can be selected using the epsg code. For example, epsg 27700 is a UK country grid. More epsgloud systems can be found in the gdaldata file gcs.csvand pcs.csv (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 that you must keep the proj4 string together in the command line as a separate parameter (generally caused by double quotation marks ).

OpenGIS WKT string: the OpenGIS standard defines a text format to describe the coordinate system as a part of the Simple Element specification. This format is the internal operating 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 can also be used as a command line parameter.

Esri wkt string: ESRI in their ArcGIS product (in ArcGIS. prj file) uses a simplified ogc wkt format, and this format is used in a file similar to the WKT style. However, the file name must be prefixed with ESRI. For example, "ESRI: Sad 1927 stateplane wyomingwest FIPS 4904.prj ".

Space Reference URL urls: You can specify a space Reference URL, for example, http://spatialreference.org/ref/user/north-pacific-albert s-conic-equal-area /.

File Name: You can use a string containing WKT and proj.4, or a file defined by the coordinate system in XML/GML format.

Part of 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 in the Grid Format supported by gdal.

-Mm

Forcibly calculate the maximum and minimum values of each band in the grid.

-Stats

If this parameter is specified, the statistical information of the image, such as the maximum value, minimum value, average value, and standard deviation of each band, is calculated forcibly.

-Hist

Outputs the histogram information of all bands.

-Nogcp

Do not print the GCP list. This may be very useful for a large number of GCP datasets. For example, l1b AVHRR or hdf4modemdata contains thousands of ground control points.

-Nomd

Disable metadata printing. Some datasets may contain a large number of metadata strings.

-Noct

Disable the output of the color table.

-Checksum

 

Calculate the checksum of all bands in the dataset.

-MDD domain

Outputs the metadata information of the specified region.

-Nofl

Only the first file in the file list is displayed. Gdal1.9.0 supports this parameter.

-SD subdataset

If the input dataset contains several subdatasets, the specified number is used instead of the complete subdataset name (starting from 1. Gdal1.9.0 supports this parameter.

-Proj4

The coordinate system of the output file is output according to the string of the proj.4 type. Gdal1.9.0 supports this parameter.

Gdalinfo also outputs the following information (if any ):

Driver information of the current file format

Grid Data size (number of rows and columns)

File coordinate system (in the form of ogc wkt)

Conversion parameters for image association to geography (currently not including rotation coefficient)

Geographic boundary coordinates. If possible, there are complete Geographic conversion Parameters Based on longitude and latitude (not for GCPs)

Ground Control Point (GCPs)

All (including sub-grid 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 and minimum band values (calculated)

Band checksum value (calculated)

Band meaningless value (nodata value)

Resolution of the thumbnail available in the band

Band unit type (for example, whether the height of the band is meter or imperial)

Fake 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 perform operations such as extracting sub-grids, re-sampling, and data type conversion.

-Ot: Type

Specifies the Data Type of the output band.

-Strict:

If errors such as data loss occur during the conversion process, the system directly reports an error and does not ignore the error. The previous parameter "-not_strict" indicates that the parameter is extended and no error is reported.

-Of format:

Select the output format. The default value is geotiff (gtiff ). Note that the specified format is abbreviated.

-B Band:

Select a band for output. The band number starts from 1. Multiple-B parameters can be used to output several bands or sort the bands again. From gdal1.8.0, the band can be set to "Mask, 1" (or directly mask) to use the first band of the input dataset as a mask band.

 

-Mask band:

(From gdal1.8.0) (gdal> = 1.8.0) Select an input band as the mask band for creating output data. The number of bandwidths starts from 1, and the 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, alternatively, you can use the-B mask parameter for output. The band parameter can also be set to "Mask, 1" (or directly mask). The first band of the input dataset is used as a mask band.

-Expand gray | RGB | rgba:

(From gdal1.6.0) split a single-band file with the color table information into an RGB three-band file or an rgba four-band file. It is useful for data that does not support the color table, such as JPEG, MPEG-4, mrsid, and ECW. Grayscale values (starting from gdal1.7.0) can also be expanded into a dataset using a color table, but the output file only contains an index at the gray level.

-Outsize xsize [%] ysize [%]:

Set the size of the output file. The size is in the unit of the pixel. Unless marked with "%", it indicates that the output is the percentage of the input layer size.

-Scale [src_min src_max [dst_mindst_max]:

Reorganize and enter the object meta value. Extract them from src_min ~ Scale src_max to dst_min ~ Within the dst_max range. If omitted, the output range is 0 ~ 255. The input range is automatically calculated from the source data.

-Unscale:

This parameter is often useful when you use-OT to set the output file type without scaling or converting data in the band. (The English language of this parameter is a bit difficult to translate. If you know it, please let me know ).

-Srcwin xoff yoff xsize ysize:

 

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

-Projwin ulx uly lrx lry:

Select a value window to copy data (similar to srcwin) in the original geographic coordinate range of the original image ). The projection Coordinates Used for the four values in the parameter.

-A_srs srs_def:

Forcibly specify the coordinate system for output file projection. Srs_def can be any commonly used projection information in gdal/OGR format, such as WKT, proj4, epsg: N, or a file name containing WKT.

-A_ullr ulx uly lrx lry:

Force specify the boundary range of space conversion for the output file (the four to the range of the image ). And ignore the four-to-one range of the original image.

-A_nodata value:

Specify a meaningless value to the output band. From gdal1.8.0, you can set it to none to use the nodata value in the original file as the output file's nodata value.

-Mo "META-TAG = value ":

If possible, set a metadata key and corresponding value for the output data.

-Co "name = value ":

You can use a creation parameter to specify the special creation requirements for the output format. Multiple-Co parameters can be combined. For details about the creation parameters, refer to the description of each data format.

-GCP pixel line easting northingelevation:

Add the specified ground control point to the output dataset. This option can be used multiple times to provide a series of ground control points GCPs. The GCP format is: column number, line number, horizontal coordinate, vertical coordinate, elevation value.

-Q:

Quiet Mode. No progress information or other non-error information is output.

 

-SDS:

Copy all the child datasets in the file to their respective output files. This parameter is usually used in the format of a child dataset such as HDF or ogdi.

-Stats:

Forcibly calculate (re-calculate) The statistical information of the data. This parameter is supported since gdal1.8.0.

Src_dataset:

Enter the dataset name, which can be the file name or the URL of A subdataset in a multi-dataset file (for example, a subdataset in the hdf dataset ).

Dst_dataset:

Output file name.

Example:

Convert UTM. tif into a geotiff file that is stored in blocks.

Gdal_translate-of gtiff-Co "tiled = yes" UTM. tif utm_tiled.tif

Create a JPEG compressed TIFF image and use 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_intern_internal_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. Create a pyramid in gdaladdo

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 create or reconstruct a pyramid for most supported formats. You can use one of the following sampling algorithms to reduce the number of sampling operations.

-R {nearest (default), average, Gauss, cubic, average_mp, average_magphase, mode }:

Specify the sampling method, including the nearest neighbor (default), mean, Gaussian, and cubic convolution.

-Ro:

(Effective from gdal1.6.0). Open the data in read-only mode to create an external pyramid (especially for geotiff ).

-Clean:

Delete all the pyramids. (Effective from gdal1.7.0 ).

Filename:

Name of the file to create a pyramid.

Levels:

Create a list of layer numbers for a thumbnail. If the-clean option is used, it will be ignored.

Mode. (effective from gdal1.6.0) select the most common sampling method. Average_mp is not suitable for use. average_magphase is used for the image of the complex data space. Nearest and average are used for common images. Nearest uses the nearest sampling (simple sampling), which calculates the mean of all valid values. Cubic sampling (effective from gdal1.7.0) uses a 4x4 approximate cubic convolution kernel. Gaussian sampling (effective from gdal1.6.0) using Gaussian Kernel computing. This is a good choice for images with high contrast and clear image boundaries. The recommended sampling ratio is 2, 4, 8 ,..., 3x3 sampling is used as the Gaussian sampling calculation window.

Gdaladdo will comply with the correct nodata_values tuples (Special dataset metadata). Therefore, only one given RGB Triplet (in the case of an RGB image) is used as the nodata value, instead of having independent nodata values for each band.

Select a zoom level value. For example, 2 indicates that the scaled down degree is 1/2 of the Resolution of each dimension of the source image. If a thumbnail already exists at the selected zoom level, the thumbnail at this zoom level will be recalculated and overwritten.

Some formats do not support pyramid at all. Therefore, many formats store the pyramid with the extension. Ovr outside the file. That is true for Tiff. The geotiff format directly stores the pyramid in the original file. Unless specified using the-ro tag. You can use compress_overview to compress the creation pyramid in Tiff. All compression methods supported by geotiff can be obtained here (for example, -- config compress_overviewdeflate ).

Most drivers also support an alternative thumbnail format (using the ERDAS image format ). To use this alternate format, use use_rrd = yes to set parameters. In this way, the pyramid created by the gdal program will be placed in a secondary. aux file so that the pyramid can be directly used in ERDAS or ArcGIS. For more information about how to use gdal to create the ERDAS pyramid, see my blog: http://blog.csdn.net/liminlu0314/article/details/6127755.

Example:

Create a pyramid inside the specified TIFF file:

Gdaladdo-r average ABC. tif 2 4 8 16

Create an external compressed pyramid file from an ERDAS. imgfile:

Gdaladdo -- config compress_overviewdeflateerdas.img 2 4 8 16

Create an ERDAS Imagine format pyramid for a given JPEG file:

 

Gdaladdo -- config use_rrd Yes airphoto.jpg 39 27 81

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.