柵格數(shù)據(jù)處理方法.doc_第1頁
柵格數(shù)據(jù)處理方法.doc_第2頁
柵格數(shù)據(jù)處理方法.doc_第3頁
柵格數(shù)據(jù)處理方法.doc_第4頁
柵格數(shù)據(jù)處理方法.doc_第5頁
已閱讀5頁,還剩9頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

柵格數(shù)據(jù)處理方法2009-03-09 20:271743人閱讀評論(2)收藏舉報轉(zhuǎn)自:/linghe/archive/2009/02/09/1386843.html兩個星期以來一直與柵格數(shù)據(jù)打交道,對AO的柵格部分應(yīng)該有了一定的理解,下面是自己的一點體會,希望高手指教:)1、柵格數(shù)據(jù)的存儲類型柵格數(shù)據(jù)一般可以存儲為ESRI GRID(由一系列文件組成),TIFF格式(包括一個TIF文件和一個AUX文件),IMAGINE Image格式 在AE中一般調(diào)用ISaveAs接口來保存柵格數(shù)據(jù)2、柵格數(shù)據(jù)集和柵格編目的區(qū)別一個柵格數(shù)據(jù)集由一個或者多個波段(RasterBand)的數(shù)據(jù)組成,一個波段就是一個數(shù)據(jù)矩陣。對于格網(wǎng)數(shù)據(jù)(DEM數(shù)據(jù))和單波段的影像數(shù)據(jù),表現(xiàn)為僅僅只有一個波段數(shù)據(jù)的柵格數(shù)據(jù)集,而對于多光譜影像數(shù)據(jù)則表現(xiàn)為具有多個波段的柵格數(shù)據(jù)集柵格編目(RasterCatalog)用于顯示某個研究區(qū)域內(nèi)各種相鄰的柵格數(shù)據(jù),這些相鄰的柵格數(shù)據(jù)沒有經(jīng)過拼接處理合成一副大的影像圖3、IRasterWorkspaceEx與IRasterWorkspace ,IRsterWorkspace2的區(qū)別1).IRasteWorkspaceEx接口主要是用來讀取GeoDatabase中的柵格數(shù)據(jù)集和柵格編目2) . IRasterWorkspace ,IRsterWorkspace2主要是用來讀取以文件格式存儲在本地的柵格數(shù)據(jù)4、加載柵格數(shù)據(jù)(以存儲在本地的柵格數(shù)據(jù)文件為例)1.直接用IRasterLayer接口打開一個柵格文件并加載到地圖控件IRasterLayer rasterLayer = new RasterLayerClass();rasterLayer.CreateFromFilePath(fileName); / fileName指存本地的柵格文件路徑axMapControl1.AddLayer(rasterLayer, 0);2. 用IRasterDataset接口打開一個柵格數(shù)據(jù)集IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();IWorkspace workspace;workspace = workspaceFactory.OpenFromFile(inPath, 0); /inPath柵格數(shù)據(jù)存儲路徑if (workspace = null)Console.WriteLine(Could not open the workspace.);return;IRasterWorkspace rastWork = (IRasterWorkspace)workspace;IRasterDataset rastDataset;rastDataset= rastWork.OpenRasterDataset(inName);/inName柵格文件名if (rastDataset = null)Console.WriteLine(Could not open the raster dataset.);return;5、如何讀取柵格數(shù)據(jù)的屬性和遍歷柵格數(shù)據(jù)柵格數(shù)據(jù)的屬性包括柵格大小,行數(shù),列數(shù),投影信息,柵格范圍等等,見下面代碼(假設(shè)當(dāng)前加載的柵格文件柵格值存儲方式為:UShort類型)IRasterProps rasterProps = (IRasterProps)clipRaster;int dHeight = rasterProps.Height;/當(dāng)前柵格數(shù)據(jù)集的行數(shù)int dWidth = rasterProps.Width; /當(dāng)前柵格數(shù)據(jù)集的列數(shù)double dX = rasterProps.MeanCellSize().X; /柵格的寬度double dY = rasterProps.MeanCellSize().Y; /柵格的高度IEnvelope extent=rasterProps.Extent; /當(dāng)前柵格數(shù)據(jù)集的范圍rstPixelType pixelType=rasterProps.PixelType; /當(dāng)前柵格像素類型IPnt pntSize = new PntClass();pntSize.SetCoords(dX, dY);IPixelBlock pixelBlock = clipRaster.CreatePixelBlock(pntSize);IPnt pnt = new PntClass();for (int i = 0; i dHeight; i+)for (int j = 0; j dWidth; j+)pnt.SetCoords(i, j);clipRaster.Read(pnt, pixelBlock);if (pixelBlock != null)object obj = pixelBlock.GetVal(0, 0, 0);MessageBox.Show( Convert.ToUInt32(obj).ToString();6、如何提取指定的范圍的柵格數(shù)據(jù)提取指定范圍內(nèi)的柵格數(shù)據(jù)通常用兩種方法IRasterLayerExport(esriCarto), IExtractionOp, IExtractionOp2 (esriSpatialAnalyst),IRasterLayerExport接口提供的柵格數(shù)據(jù)提取功能有限,只能以矩形范圍作為提取范圍,而IExtractionOp接口提供了多邊形,圓,屬性,矩形等幾種形式作為提取柵格數(shù)據(jù).1).IRasterLayerExport接口IRasterLayerExport rLayerExport = new RasterLayerExportClass();rLayerExport.RasterLayer = rasterLayer;/ rasterLayer指當(dāng)前加載的柵格圖層rLayerExport.Extent = clipExtent;/clipExtent指提取柵格數(shù)據(jù)的范圍if (proSpatialRef != null)rLayerExport.SpatialReference = proSpatialRef;/ proSpatialRef當(dāng)前柵格數(shù)據(jù)的投影信息IWorkspaceFactory pWF = new RasterWorkspaceFactoryClass();tryIWorkspace pRasterWorkspace = pWF.OpenFromFile(_folder, 0);/ _folder指柵格文件保存路徑IRasterDataset outGeoDataset = rLayerExport.Export(pRasterWorkspace, code, strRasterType);/調(diào)用ISaveAs接口將導(dǎo)出的數(shù)據(jù)集保存.Catch(Exception ex)Throw new Argumention(ex.Message);2IExtractionOp接口(調(diào)用此接口前,應(yīng)該先檢查空間許可)IExtractionOp extraction = new RasterExtractionOpClass();tryIGeoDataset geoDataset = extraction.Rectangle(IGeoDataset)clipRaster, clipExtent, true);IRaster raster = geoDataset as IRaster;if (raster != null)IWorkspaceFactory WF = new RasterWorkspaceFactoryClass();IWorkspace rasterWorkspace = WF.OpenFromFile(_folder, 0);ISaveAs saveAs = (ISaveAs)raster;saveAs.SaveAs(“Result.tif”, rasterWorkspace, TIFF);catch (Exception ex)MessageBox.Show(Ex.message);7柵格數(shù)據(jù)重采樣?xùn)鸥駭?shù)據(jù)的重采樣主要基于三種方法:最鄰近采樣(NEAREST),雙線性ILINEAR)和三次卷積采樣(CUBIC)。(1).最鄰近采樣:它用輸入柵格數(shù)據(jù)中最臨近柵格值作為輸出值。因此,在重采樣后的輸出柵格中的每個柵格值, 都是輸入柵格數(shù)據(jù)中真實存在而未加任何改變的值。這種方法簡單易用,計算量小,重采樣的速度最快。(2).雙線性采樣:此重采樣法取待采樣點(x,y)點周圍四個鄰點,在y方向(或X方向)內(nèi)插兩次,再在x方向(或y方向)內(nèi)插一次,得到(x,y)點的柵格值。(3).三次卷積采樣:這是進(jìn)一步提高內(nèi)插精度的一種方法。它的基本思想是增加鄰點來獲得最佳插值函數(shù)。取待計算點周圍相鄰的16個點,與雙線性采樣類似,可先在某一方向上內(nèi)插,如先在x方向上,每四個值依次內(nèi)插四次,再根據(jù)四次的計算結(jié)果在y方上內(nèi)插,最終得到內(nèi)插結(jié)果代碼示例:采用雙線性采樣IRasterGeometryProc rasterGeometryProc = new RasterGeometryProcClass();rasterGeometryProc.Resample(rstResamplingTypes.RSP_CubicConvolution, newCellSize, clipRaster);柵格數(shù)據(jù)重分類 (2009-01-10 10:10:09)標(biāo)簽:柵格 重分類 分類:AE二次開發(fā)public static IRasterLayer SetViewShedRenderer(IRaster pInRaster,string sField,string sPath)IRasterDescriptor pRD = new RasterDescriptorClass();pRD.Create(pInRaster, new QueryFilterClass(), sField);IReclassOp pReclassOp = new RasterReclassOpClass();IGeoDataset pGeodataset=pInRaster as IGeoDataset;IRasterAnalysisEnvironment pEnv = pReclassOp as IRasterAnalysisEnvironment;IWorkspaceFactory pWSF=new RasterWorkspaceFactoryClass();IWorkspace pWS = pWSF.OpenFromFile(sPath, 0);pEnv.OutWorkspace = pWS;object objSnap = null;object objExtent = pGeodataset.Extent;pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objExtent, ref objSnap);pEnv.OutSpatialReference = pGeodataset.SpatialReference;IRasterLayer pRLayer = new RasterLayerClass();IRasterBandCollection pRsBandCol = pGeodataset as IRasterBandCollection;IRasterBand pRasterBand = pRsBandCol.Item(0);pRasterBand.ComputeStatsAndHist();IRasterStatistics pRasterStatistic = pRasterBand.Statistics;double dMaxValue = pRasterStatistic.Maximum ;double dMinValue = pRasterStatistic.Minimum ;INumberRemap pNumRemap = new NumberRemapClass();pNumRemap.MapRange(dMinValue, 0, 0);pNumRemap.MapRange(0, dMaxValue, 1);IRemap pRemap = pNumRemap as IRemap;IRaster pOutRaster = pReclassOp.ReclassByRemap(pGeodataset, pRemap, false) as IRaster ;pRLayer.CreateFromRaster(pOutRaster);return pRLayer;柵格圖層和矢量圖層的屬性表瀏覽if (pLyr is IFeatureLayer)DataTable pTable = new DataTable();IFeatureLayer pFealyr = pLyr as IFeatureLayer;IFeatureClass pFCls = pFealyr.FeatureClass;string shape = ;if (pFCls.ShapeType = esriGeometryType.esriGeometryPoint)shape = Point;else if (pFCls.ShapeType = esriGeometryType.esriGeometryPolyline)shape = Polyline;else if (pFCls.ShapeType = esriGeometryType.esriGeometryPolygon)shape = Polygon;for (int i = 0; i pFCls.Fields.FieldCount; i+)pTable.Columns.Add(pFCls.Fields.get_Field(i).Name);IFeatureCursor pCursor = pFCls.Search(null, false);int ishape = pFCls.Fields.FindField(Shape);IFeature pFea = pCursor.NextFeature();while (pFea != null)DataRow pRow = pTable.NewRow();for (int i = 0; i pFCls.Fields.FieldCount; i+)if (i = ishape)pRowi = shape;continue;pRowi = pFea.get_Value(i).ToString();pTable.Rows.Add(pRow);pFea = pCursor.NextFeature();dataGridView1.DataSource = pTable;else if (pLyr is IRasterLayer)IRasterLayer pRlyr = pLyr as IRasterLayer;IRaster pRaster = pRlyr.Raster;IRasterProps pProp = pRaster as IRasterProps;pProp.PixelType = rstPixelType.PT_LONG;if (pProp.PixelType = rstPixelType.PT_LONG)IRasterBandCollection pBcol = pRaster as IRasterBandCollection;IRasterBand pBand = pBcol.Item(0);ITable pRTable = pBand.AttributeTable;DataTable pTable = new DataTable();for (int i = 0; i pRTable.Fields.FieldCount; i+)pTable.Columns.Add(pRTable.Fields.get_Field(i).Name);ICursor pCursor= pRTable.Search(null, false);IRow pRrow= pCursor.NextRow();while (pRrow != null)DataRow pRow = pTable.NewRow();for (int i =0 ;ipRrow .Fields .FieldCount ;i+)pRowi = pRrow.get_Value(i).ToString () ;pTable.Rows.Add(pRow);pRrow = pCursor.NextRow();dataGridView1.DataSource = pTable;創(chuàng)建柵格數(shù)據(jù)集 (2008-04-20 14:14:05)標(biāo)簽:arcgis engine c 代碼 it 分類:三文魚的GIS關(guān)鍵詞:創(chuàng)建柵格數(shù)據(jù)集 IRasterWorkspace2 IRasterDataset CreateRasterDataset C#public IRasterDataset CreateFileRasterDataset(string directoryName, string fileName)/ This function creates a new img file in the given workspace/ and then assigns pixel valuestryIRasterDataset rasterDataset = null;IPoint originPoint = new PointClass();originPoint.PutCoords(0, 0);/ Create the datasetIRasterWorkspace2 rasterWorkspace2 = null;rasterWorkspace2 = CreateRasterWorkspace(directoryName);rasterDataset = rasterWorkspace2.CreateRasterDataset(fileName, IMAGINE Image, originPoint, 200, 100, 1, 1, 1, rstPixelType.PT_UCHAR, new UnknownCoordinateSystemClass(), true);IRawPixels rawPixels = null;IPixelBlock3 pixelBlock3 = null;IPnt pixelBlockOrigin = null;IPnt pixelBlockSize = null;IRasterBandCollection rasterBandCollection;IRasterProps rasterProps;/ QI for IRawPixels and IRasterPropsrasterBandCollection = (IRasterBandCollection)rasterDataset;rawPixels = (IRawPixels)rasterBandCollection.Item(0);rasterProps = (IRasterProps)rawPixels;/ Create pixelblockpixelBlockOrigin = new DblPntClass();pixelBlockOrigin.SetCoords(0, 0);pixelBlockSize = new DblPntClass();pixelBlockSize.SetCoords(rasterProps.Width, rasterProps.Height);pixelBlock3 = (IPixelBlock3)rawPixels.CreatePixelBlock(pixelBlockSize);/ Read pixelblockrawPixels.Read(pixelBlockOrigin, (IPixelBlock)pixelBlock3);/ Get pixeldata arraySystem.Object, pixelData;pixelData = (System.Object,)pixelBlock3.get_PixelDataByRef(0);/ Loop through all the pixels and assign valuefor (int i = 0; i rasterProps.Width; i+)for (int j = 0; j rasterProps.Height; j+)pixelDatai, j = (i * j) % 255;/ Write the pixeldata backSystem.Object cachePointer;cachePointer = rawPixels.AcquireCache();rawPixels.Write(pixelBlockOrigin, (IPixelBlock)pixelBlock3);rawPixels.ReturnCache(cachePointer);/ Return raster datasetreturn rasterDataset;catch (Exception ex)System.Diagnostics.Debug.WriteLine(ex.Message);return null;public IRasterWorkspace2 CreateRasterWorkspace(string pathName)/ Create RasterWorkspaceIWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();return workspaceFactory.OpenFromFile(pathName, 0) as IRasterWorkspace2;public IRasterDataset tin2raster(string tempBathyTIN,string geoPath, string gridName)string tinFolder = System.IO.Path.GetDirectoryName(tempBathyTIN);string tinName = System.IO.Path.GetFileName(tempBathyTIN);IRasterDataset rasterDataset = new RasterDatasetClass();trystring rasterPath = System.IO.Path.GetDirectoryName(geoPath);IWorkspaceFactory TinWF = new TinWorkspaceFactory();ITinWorkspace TinWK = TinWF.OpenFromFile(tinFolder,0)as ITinWorkspace;ITinAdvanced2 tinAd = TinWK.OpenTin(tinName) as ITinAdvanced2;IEnvelope extent = tinAd.Extent;IPoint origin = extent.LowerLeft;origin.X = origin.X - (5 * 0.5);origin.Y = origin.Y - (5 * 0.5);int nCol = (int)Math.Round(extent.Width / 5) + 1;int nRow = (int)Math.Round(extent.Height / 5) +1;ISpatialReference2 spatialRef = (ISpatialReference2)extent.SpatialReference;IWorkspaceFactory rasterWF = new RasterWorkspaceFactoryClass();IRasterWorkspace2 workSpace = (IRasterWorkspace2)rasterWF.OpenFromFile(rasterPa

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論