How to use gdal to manipulate images
How to use gdal to manipulate images, I believe that many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
GDAL (Geospatial Data Abstraction Library) is an open source raster spatial data conversion library under the X/MIT license agreement. It uses an abstract data model to express the various file formats supported. It also has a series of command-line tools for data conversion and processing.
GDAL provides support for a variety of raster data, including Arc/Info ASCII Grid (asc), GeoTiff (tiff), Erdas Imagine Images (img), ASCII DEM (dem) and other formats.
Use C # to develop gdal procedures, reference C# class libraries are not many, but need to be in the implementation directory, add a lot of C++ dll, otherwise there will be an error, missing dll files, specific can go to the Internet to download.
In the project of C #, the following dll needs to be referenced:
Gdal.AllRegister ()
/ / Chinese is supported
/ / Gdal.SetConfigOption ("GDAL_FILENAME_IS_UTF8", "YES")
Dataset ds = Gdal.Open (strFilePath, Access.GA_ReadOnly)
Band Band = ds.GetRasterBand (1)
/ / get the size of the image
Int width = Band.XSize
Int height = Band.YSize
/ / obtain coordinate transformation coefficients
Double [] adfGeoTransform = new double [6]
Ds.GetGeoTransform (adfGeoTransform)
/ / get the row number
Double dCol = 0.0, dRow = 0.0
Int dc = Convert.ToInt32 (dCol)
Int dr = Convert.ToInt32 (dRow)
DataType DT = DataType.GDT_CFloat32
/ / create a tiff file format
OSGeo.GDAL.Driver driver = Gdal.GetDriverByName ("GTiff")
Dataset dataset = driver.Create (testPath, fx, fy, 1, DT, null)
/ / Image conversion parameters
Dataset.SetGeoTransform (adfGeoTransform)
/ / projection conversion parameters
Dataset.SetProjection (ds.GetProjection ())
/ / write data in the image band
Dataset.GetRasterBand (1) .WriteRaster (0,0, fx, fy, data, fx, fy, 0,0)
Dataset.GetRasterBand (1) .FlushCache ()
Dataset.FlushCache ()
The above is an elevation data, read and write in tiff format, what is stored in the data is each point, and the elevation value on each point is written to the image sequentially, and the pixels on the tiff map should be corresponding to the elevation value of the spatial coordinates.
After reading the above, have you mastered how to use gdal to manipulate images? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!