Změna projekce nebo transformace rastrových vrstev v GIS pomocí C#
Contents
[
Hide
]
Změna projekce vrstvy do prostorového referenčního systému WGS84 na vzorcích GeoTIFF
API Aspose.GIS vám umožňuje převést rastrovou vrstvu z jednoho prostorového referenčního systému do jiného a aplikovat nové velikosti, jak je ukázáno v následujícím kódu.
This file contains hidden or 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, "raster_float32.tif"))) | |
using (var warped = layer.Warp(new WarpOptions(){Height = 40, Width = 40, TargetSpatialReferenceSystem = SpatialReferenceSystem.Wgs84})) | |
{ | |
// read and print raster | |
var cellSize = warped.CellSize; | |
var extent = warped.GetExtent(); | |
var spatialRefSys = warped.SpatialReferenceSystem; | |
var code = spatialRefSys == null ? "'no srs'" : spatialRefSys.EpsgCode.ToString(); | |
var bounds = warped.Bounds; | |
var bandCount = warped.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 < warped.BandCount; i++) | |
{ | |
var dataType = warped.GetBand(i).DataType; | |
var hasNoData = !warped.NoDataValues.IsNull(); | |
var statistics = warped.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: {warped.NoDataValues[i]}"); | |
} | |
} |
Změna velikosti buněk v rastrové vrstvě na vzorcích GeoTIFF
API Aspose.GIS vám umožňuje změnit velikost buněk v rastrové vrstvě, jak je ukázáno v následujícím kódu.
This file contains hidden or 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, "raster_float32.tif"))) | |
{ | |
Extent sourceExtent = layer.GetExtent(); | |
var newExtent = new Extent( | |
sourceExtent.XMin, | |
sourceExtent.YMin, | |
sourceExtent.XMin + sourceExtent.Width * 0.5, | |
sourceExtent.YMax + sourceExtent.Height * 0.5, | |
layer.SpatialReferenceSystem); | |
using (var warped = layer.Warp(new WarpOptions() { CellWidth = 120, CellHeight = 120, TargetExtent = newExtent })) | |
{ | |
// read and print raster | |
var cellSize = warped.CellSize; | |
var extent = warped.GetExtent(); | |
var spatialRefSys = warped.SpatialReferenceSystem; | |
var code = spatialRefSys == null ? "'no srs'" : spatialRefSys.EpsgCode.ToString(); | |
var bounds = warped.Bounds; | |
Console.WriteLine($"cellSize: {cellSize}"); | |
Console.WriteLine($"source extent: {sourceExtent}"); | |
Console.WriteLine($"target extent: {extent}"); | |
Console.WriteLine($"spatialRefSys: {code}"); | |
Console.WriteLine($"bounds: {bounds}"); | |
} | |
} |