4: (C # Use the gdal Library) create an image file

Source: Internet
Author: User

Before creating an image, you must first reference the registration function gdal. allregister () of the gdal library ()

1: gdal-supported image formats

First, you must specify the image formats supported by gdal,

The image formats supported by gdal are listed in the http://www.gdal.org/formats_list.html, each of which corresponds to a driver in gdal ),

Tables on the webpage

The first column (long format name) is the description of the image format. Click this column to view the detailed information of this format through the link, including the creation parameters of this format.

The second column (CODE) is the code in the gdal format, which is also the name of the driver,

The third column (Creation) indicates whether the format supports image creation.

The fourth column (georeferencing) is unknown. It may be whether space information can be assigned to the format.

The Fifth Column (maximum file size) is the image size limit.

The sixth column (compiled by default) indicates whether the format is supported by default, or whether it needs support from other plug-ins.

2: Get the driver

To create an image in gdal, you must first specify the format of the image to be created and obtain the driver of the image format:

Driver d = gdal. getdriverbyname ("HFA ");

Use this function to obtain the driver of the image format. The parameter is the driver name, which can be queried in the second column of the table above. For example, HFA is the driver name of erdas img.

3: Driver attributes (metadata)
Each driver has some attributes. getmetadata ("") can be obtained. The result is a string array with the same content as that found on the webpage, including: whether to allow creation, whether to copy and create, and supported pixel concentration types, supported creation Parameters

4: Call the create function to create an image.
After obtaining the driver, use

d.Create(string uft8_path,int xSize,int ySize,int bands,DataType eType,string[] options)

Function to create an image

The parameter of this function is:

Uft8_path: Image path

Xsize: width (pixel value)

Ysize: Height

Bands

Datatype: pixel depth, which can be set to byte, float, Int, etc.

Options: You can set options for creating an image. gdal sets different creation parameters for different formats. For details, refer to the image formats described above.

The return value of this function is dataset, which is the same as the dataset obtained by opening the image in the previous file. You can operate the image data on this basis.

Example code of the create function:

1)Dataset dsout = d.Create(this.cut_savePathBox.Text, width, height, bands.Length, DataType.GDT_Byte, null);2)Dataset dsout = d.Create(this.cut_savePathBox.Text, width, height, bands.Length, DataType.GDT_Byte, n new string[] { "AUX=YES", "STATISTICS=YES" });

5. Call the createcopy function to create a copy.

The createcopy function allows you to create a copy image from an opened image and retain some basic information about the original image, such as width and height, number of bands, coordinates, and offset.

d.CreateCopy(string utf8_path,Dataset src,int strict,string [] options,GDALProcessFuncDelegate callback,string callback_data)

The parameters are as follows:

Utf8_path: Path

SRC: open image data

Strict: If the value is 0 or 1, if the value is not, it means that even if the original data cannot be accurately matched into the target data, the program will still execute the createcopy method without causing a fatal error. This error may be because the output format does not support the Data Type of the input data format metadata, or the target data does not support the write space reference. [this parameter is transferred from http://www.gissky.net/article/645.htm]

Options: Same as the CREATE FUNCTION

Callback, callback_data: input a delegate to display the progress of Data creation in real time. It can be set to null if not needed.

For example:

Dataset ds = d.CreateCopy(path,dsin,1,null,null,null);


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.