GP学习(十)-Mosaic raster datasets to a file raster format
<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 catalogclass 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 locationstatic 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 rastersCreateUnmanagedRasterCatalog();//Open raster catalogIRasterWorkspaceEx rasterWorkspaceEx = (IRasterWorkspaceEx)OpenRasterPGDBWorkspace(tempPGDBPath);IRasterCatalog rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(tempRasterCatalog);//Mosaic rasters in the raster catalogMosaic(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() callaoInit.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 directoryCreatePersonalGDB 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 GDBCreateRasterCatalog 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 catalogWorkspaceToRasterCatalog 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 datasetIMosaicRaster mosaicRaster = new MosaicRasterClass();mosaicRaster.RasterCatalog = rasterCatalog;//Set mosaicking options, you may not need to set these for your datamosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH;mosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST;//Open output workspaceIWorkspaceFactory 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);}}
}
GP学习(十)-Mosaic raster datasets to a file raster format相关推荐
- GP学习(八)—How to access a raster dataset and to create a raster dataset
声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档 How to access a raster dataset Summary A raster dataset can be s ...
- GP学习(六)—Creating geodatabase and connecting geodatabase
声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档 Creating geodatabases Summary This topic explains how to create ...
- 2017年深度学习十大趋势预测
2017年深度学习十大趋势预测 本文作者曾经多次预测了技术发展的趋势,最近的一次预测是"2011年软件发展的趋势与预测".10项预言中,准确地命中了6项,比如JavaScript ...
- 强化学习(十九) AlphaGo Zero强化学习原理
在强化学习(十八) 基于模拟的搜索与蒙特卡罗树搜索(MCTS)中,我们讨论了MCTS的原理和在棋类中的基本应用.这里我们在前一节MCTS的基础上,讨论下DeepMind的AlphaGo Zero强化学 ...
- 强化学习(十六) 深度确定性策略梯度(DDPG)
在强化学习(十五) A3C中,我们讨论了使用多线程的方法来解决Actor-Critic难收敛的问题,今天我们不使用多线程,而是使用和DDQN类似的方法:即经验回放和双网络的方法来改进Actor-Cri ...
- 强化学习(十五) A3C
在强化学习(十四) Actor-Critic中,我们讨论了Actor-Critic的算法流程,但是由于普通的Actor-Critic算法难以收敛,需要一些其他的优化.而Asynchronous Adv ...
- NLP:LSTM之父眼中的深度学习十年简史《The 2010s: Our Decade of Deep Learning / Outlook on the 2020s》的参考文献
NLP:LSTM之父眼中的深度学习十年简史<The 2010s: Our Decade of Deep Learning / Outlook on the 2020s>的参考文献 目录 T ...
- OpenCV与图像处理学习十六——模板匹配
OpenCV与图像处理学习十六--模板匹配 一.模板匹配介绍 二.代码应用 一.模板匹配介绍 模板匹配是一种最原始.最基本的模式识别方法,研究某一特定目标的图像位于图像的什么地方,进而对图像进行定位. ...
- OpenCV与图像处理学习十五——LBP纹理特征(含代码)
OpenCV与图像处理学习十五--LBP纹理特征(含代码) 一.LBP介绍 二.LBP原理 三.代码应用 一.LBP介绍 LBP(Local Binary Pattern, 局部二值模式) , 是一种 ...
最新文章
- Docker安装部署MongoDB及MySql和MongoDB的语法对比
- iBATIS.NET
- Angular form学习笔记
- python添加时间戳_在python中添加时间戳
- hash table(开放寻址法-双重散列实现的哈希表)
- c语言中字符数字加'0',C语言中的NULL与转义字符'\0'以及数值0的关系
- 万达影视发布声明:不存在所谓的从《流浪地球》撤资
- Java-GuardedBlocks与BusyWaitting忙等待
- Android系统启动流程源码分析
- protubuffer for windows配置指南!
- Page.Validate()方法
- 京东今天还在用 .NET 架构的原因是什么?
- windows10程序员计算机,Win10计算器程序员模式如何移位?
- TD通过artnet控制电脑灯的操作
- android studio深色模式,Xamarin 中的深色模式
- STM32 WAVWM8978简介
- 获取苹果设备的UDID
- vue项目用qrcodejs2生成多个二维码的实现
- 树莓派CM4基于emmc安装Ubuntu系统及初始配置
- WPS word文档插入图片显示不全