GP学习(十)-Mosaic raster datasets to a file raster format
来源:互联网 发布:淘宝申请退货几天到账 编辑:程序博客网 时间:2024/05/29 10:11
<span style="color: rgb(255, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12.48px; line-height: 17.472px;"><strong>声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档</strong></span>
// Copyright 2010 ESRI// // All rights reserved under the copyright laws of the United States// and applicable international laws, treaties, and conventions.// // You may freely redistribute and use this sample code, with or// without modification, provided you include the original copyright// notice and use restrictions.// // See the use restrictions.// using System;using Microsoft.Win32;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.DataSourcesRaster;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.DataManagementTools;using ESRI.ArcGIS.Geoprocessor;using ESRI.ArcGIS.Geoprocessing;using ESRI.ArcGIS.DataSourcesGDB;namespace CreateFileRasterMosaic{ //Sample creating a file raster mosaic from rasters in a folder and its subfolders //Steps: // 1. Create an unmanaged PGDB raster catalog // 2. Load rasters in the input folder and its subfolders to the new raster catalog // 3. Create a mosaic file raster dataset from the unmanaged raster catalog class CreateFileRasterMosaic { //Local variables for data path //The TEMP directory will be used to create temporary raster catalog and output raster dataset //Remove temp.mdb in TEMP directory if it exists //You can substitute the paths with your data location static string inputFolder = @"C:\data"; static string outputFolder = @"C:\Temp"; static string outputName = "mosaic.tif"; static string tempRasterCatalog = "temp_rc"; static string tempPGDB = "temp.mdb"; static string tempPGDBPath = outputFolder + "\\" + tempPGDB; static string tempRasterCatalogPath = tempPGDBPath + "\\" + tempRasterCatalog; static void Main(string[] args) { ESRI.ArcGIS.esriSystem.AoInitialize aoInit = null; try { ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); aoInit = new AoInitializeClass(); esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcView); Console.WriteLine("License Checkout successful."); } catch (Exception exc) { // If it fails at this point, shutdown the test and ignore any subsequent errors. Console.WriteLine(exc.Message); } try { //Create temporary unmanaged raster catalog and load all rasters CreateUnmanagedRasterCatalog(); //Open raster catalog IRasterWorkspaceEx rasterWorkspaceEx = (IRasterWorkspaceEx)OpenRasterPGDBWorkspace(tempPGDBPath); IRasterCatalog rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(tempRasterCatalog); //Mosaic rasters in the raster catalog Mosaic(rasterCatalog); } catch (Exception exc) { Console.WriteLine(exc.Message); } Console.Write("Please press any key to close the application."); Console.ReadKey(); //Do not make any call to ArcObjects after ShutDown() call aoInit.Shutdown(); } static void CreateUnmanagedRasterCatalog() { try { //Use geoprocessing to create the geodatabase, the raster catalog, and load our directory //to the raster catalog. Geoprocessor geoprocessor = new Geoprocessor(); //Create personal GDB in the TEMP directory CreatePersonalGDB createPersonalGDB = new CreatePersonalGDB(); createPersonalGDB.out_folder_path = outputFolder; createPersonalGDB.out_name = tempPGDB; geoprocessor.Execute(createPersonalGDB, null); //Create an unmanaged raster catalog in the newly created personal GDB CreateRasterCatalog createRasterCatalog = new CreateRasterCatalog(); createRasterCatalog.out_path = tempPGDBPath; createRasterCatalog.out_name = tempRasterCatalog; createRasterCatalog.raster_management_type = "unmanaged"; geoprocessor.Execute(createRasterCatalog, null); //Load data into the unmanaged raster catalog WorkspaceToRasterCatalog wsToRasterCatalog = new WorkspaceToRasterCatalog(); wsToRasterCatalog.in_raster_catalog = tempRasterCatalogPath; wsToRasterCatalog.in_workspace = inputFolder; wsToRasterCatalog.include_subdirectories = "INCLUDE_SUBDIRECTORIES"; geoprocessor.Execute(wsToRasterCatalog, null); } catch (Exception exc) { Console.WriteLine(exc.Message); } } static void Mosaic(IRasterCatalog rasterCatalog) { try { //Mosaics all rasters in the raster catalog to an output raster dataset IMosaicRaster mosaicRaster = new MosaicRasterClass(); mosaicRaster.RasterCatalog = rasterCatalog; //Set mosaicking options, you may not need to set these for your data mosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH; mosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST; //Open output workspace IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass(); IWorkspace workspace = workspaceFactory.OpenFromFile(outputFolder, 0); //Save out to a target raster dataset //It can be saved to TIFF, IMG, GRID, BMP, GIF, JPEG2000, JPEG, Geodatabase, ect. ISaveAs saveas = (ISaveAs)mosaicRaster; saveas.SaveAs(outputName, workspace, "TIFF"); } catch (Exception exc) { Console.WriteLine(exc.Message); } } static IWorkspace OpenRasterPGDBWorkspace(string connStr) { Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory"); System.Object obj = Activator.CreateInstance(t); IWorkspaceFactory2 workspaceFactory = obj as IWorkspaceFactory2; return workspaceFactory.OpenFromFile(connStr, 0); } }}
0 0
- GP学习(十)-Mosaic raster datasets to a file raster format
- GP学习(八)—How to access a raster dataset and to create a raster dataset
- Mosaic/Mosaic To New Raster
- GP学习(七)—Accessing raster workspaces
- GP Raster Server
- AGG学习之十----FreeType库 raster方式绘制字符
- Point to Raster 工作原理
- 栅格结构(Raster data)
- ArcEngine Raster
- Renderers used to display raster data
- Python 实现ARCGIS中raster to ascii
- Raster数据的相关开发(一)
- Raster数据的相关开发(二)
- 插入光栅图纸(Raster Image)
- Raster Catalog和Raster Dataset的区别
- arcgis数据格式 raster to polygon出现不是整型的错误
- 光栅数据库Raster
- 经验 - R - Raster Package
- JAVA的自我修养
- 用递归函数和栈操作逆序一个栈
- 接口和抽象类区别
- Timus 1104 Don’t Ask Woman about Her Age
- UVALive 2889 Palindrome Numbers
- GP学习(十)-Mosaic raster datasets to a file raster format
- HDU 4352 XHXJ's LIS
- C#和JAVA利用BASE64实现图片编码解码
- 容斥原理 —— 求1~n有多少个数与k互质(二进制算法详细解释&模板)
- CodeForces 1B
- Java wait(long arg)方法的使用
- golang substring方法的几种实现
- NYOJ263精挑细选
- Java调用C++ API完整示例(dll)