PIE SDK柵格數據集的讀寫

 

1. 功能簡介

    柵格數據包含不少信息,在數據的運用中須要對數據的信息進行讀取或寫入,目前PIE SDK支持多種數據格式的數據讀取和寫入,下面對柵格數據格式的數據讀寫功能進行介紹。ide

2. 功能實現說明

2.1. 實現思路及原理說明

第一步spa

獲取要讀取的柵格數據code

第二步視頻

讀取柵格數據對象

第三步blog

寫入柵格數據並賦值投影教程

2.2. 核心接口與方法

接口/類接口

方法/屬性ip

說明ci

 

 

IRasterDataset

GetBandCount()

獲取波段數

GetRasterBand(int nIndex)

獲取柵格波段對象

GetRasterDataType()

獲取柵格數據類型

Read(int nx, int ny, int nWid, int nHei, int nBufXSize, int nBufYSize, IList<int> bandMap)

柵格數據集讀取數據

2.3. 示例代碼

項目路徑

百度雲盤地址下/PIE示例程序/04數據操做/12柵格數據集的讀寫

數據路徑

百度雲盤地址下/PIE示例數據/柵格數據/04.World/World.tif

視頻路徑

百度雲盤地址下/PIE視頻教程/04數據操做/12柵格數據集的讀寫.avi

示例代碼

 1          /// <summary>
 2         /// 柵格數據集的讀寫
 3         /// </summary>
 4         /// <param name="sender"></param>
 5         /// <param name="e"></param>
 6         private void toolStripButton_ReadRasterData_Click(object sender, EventArgs e)
 7         {
 8             string rPathLBT = @"D:\Data\World.tif";
 9             IRasterDataset rDataset = DatasetFactory.OpenRasterDataset(rPathLBT, OpenMode.ReadOnly);
10             int bandCount = rDataset.GetBandCount();
11             IRasterBand rasterband = rDataset.GetRasterBand(bandCount - 1);
12             PixelDataType type = rasterband.GetRasterDataType();
13 
14             int[] bandMap = new int[bandCount];
15             for (int i = 0; i < bandCount; i++)
16             {
17                 bandMap[i] = i + 1;
18             }
19             UInt16[] buf = new UInt16[500 * 500 * bandCount];
20             bool ok = rDataset.Read(0, 0, 500, 500, buf, 500, 500, type, bandCount, bandMap);
21 
22             //獲取投影
23             string rPathGLL = @"D:\Data\World.tif";
24             IRasterDataset rDatasetGLL = DatasetFactory.OpenRasterDataset(rPathGLL, OpenMode.ReadOnly);
25             ISpatialReference spGLL = rDatasetGLL.SpatialReference;
26             string stGLL = spGLL.ExportToWkt();
27 
28             //寫入數據並賦值投影
29             string rPathSaveGLL = @"D:\Data\World_new.tif";
30             IRasterDataset rasterDatasetSave = DatasetFactory.CreateRasterDataset(rPathSaveGLL, 500, 500, bandCount, type, "GTIFF", null);
31             ok = rasterDatasetSave.Write(0, 0, 500, 500, buf, 500, 500, type, bandCount, bandMap);
32             rasterDatasetSave.SpatialReference = SpatialReferenceFactory.CreateSpatialReference(stGLL);
33 
34             ((IDisposable)rasterDatasetSave).Dispose();
35             rasterDatasetSave = null;
36             ILayer layer = PIE.Carto.LayerFactory.CreateDefaultLayer(rPathSaveGLL);
37             mapControlMain.FocusMap.AddLayer(layer);            mapControlMain.ActiveView.PartialRefresh(PIE.Carto.ViewDrawPhaseType.ViewAll);
38         } 
View Code

2.4. 示例截圖

相關文章
相關標籤/搜索