Work with Raster Layers using GIS C# Library
Contents
[
Hide
]
Working with multi-band raster on GeoTIFF samples
GeoTIFF is one of the most widely used raster formats among GIS Software. Aspose.GIS lets you work with the GeoTIFF raster format.
Read general data in multi-band raster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
string filesPath = RunExamples.GetDataDir(); | |
using (var layer = Drivers.GeoTiff.OpenLayer(Path.Combine(filesPath, "raster50x50.tif"))) | |
{ | |
// read and print raster | |
var cellSize = layer.CellSize; | |
var extent = layer.GetExtent(); | |
var spatialRefSys = layer.SpatialReferenceSystem; | |
var code = spatialRefSys == null ? "'no srs'" : spatialRefSys.EpsgCode.ToString(); | |
var bounds = layer.Bounds; | |
var bandCount = layer.BandCount; | |
Console.WriteLine($"cellSize: {cellSize}"); | |
Console.WriteLine($"extent: {extent}"); | |
Console.WriteLine($"spatialRefSys: {code}"); | |
Console.WriteLine($"bounds: {bounds}"); | |
Console.WriteLine($"bandCount: {bandCount}"); | |
// read and print bands | |
for (int i = 0; i < layer.BandCount; i++) | |
{ | |
var dataType = layer.GetBand(i).DataType; | |
var hasNoData = !layer.NoDataValues.IsNull(); | |
var statistics = layer.GetStatistics(i); | |
Console.WriteLine(); | |
Console.WriteLine($"Band: {i}"); | |
Console.WriteLine($"dataType: {dataType}"); | |
Console.WriteLine($"statistics: {statistics}"); | |
Console.WriteLine($"hasNoData: {hasNoData}"); | |
if (hasNoData) | |
Console.WriteLine($"noData: {layer.NoDataValues[i]}"); | |
} | |
} |
Read values line by line
Read value of specified type
Analyze rasters values use LINQ or Expression methods
Read raw bits in rasters
Working with single-band raster format on Esri ASCII samples
The EsriAscii format always has only one band.