创建FILE GEODATABASE 和栅格目录及向栅格目录中添加影像
using System;
using System.IO;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.DataManagementTools;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Carto;
namespace RasterOperation
{
public class RasterCatalogOperation
{
/// <summary>
/// fileGDB路径
/// </summary>
public string FileGDBPath
{
get ;
set ;
}
/// <summary>
/// 栅格数据目录
/// </summary>
public string SourceRasterDic
{
get;
set;
}
/// <summary>
/// 栅格目录名称
/// </summary>
public string RasterDSName
{
get;
set;
}
/// <summary>
/// 栅格坐标系
/// </summary>
public ISpatialReference RasterSpRf
{
get;
set;
}
/// <summary>
/// 矢量坐标系
/// </summary>
public ISpatialReference GeometrySpRf
{
get;
set;
}
/// <summary>
/// 栅格目录转换为图层
/// </summary>
/// <param name="folderName">目录名</param>
/// <param name="datasetName">数据集名</param>
/// <returns>要素图层</returns>
public ILayer AddRasterCatalogLayer(string folderName, string datasetName)
{
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
try
{
IWorkspace workspc = workspaceFactory.OpenFromFile(folderName, 0);
IRasterWorkspaceEx pRaterWs = (IRasterWorkspaceEx)workspc;
IRasterCatalog rasterCatalog = pRaterWs.OpenRasterCatalog(datasetName);
ESRI.ArcGIS.Carto.IGdbRasterCatalogLayer rastercatalogLayer = new
GdbRasterCatalogLayerClass();
rastercatalogLayer.Setup((ITable)rasterCatalog);
//Add it to map if the layer is valid.
if (!(rastercatalogLayer == null))
{
return rastercatalogLayer as ILayer;
}
else
return null;
}
catch
{
return null;
}
//Create a raster catalog layer.
}
/// <summary>
/// 创建FileGDB
/// </summary>
/// <param name="fullPath">路径名</param>
public void CreateFileGDB(string fullPath)
{
if (!Directory.Exists(fullPath))
{
IWorkspaceFactory2 wsFctry = new FileGDBWorkspaceFactoryClass();
wsFctry.Create(System.IO.Path.GetDirectoryName(fullPath),
System.IO.Path.GetFileName(fullPath), null, 0);
FileGDBPath = fullPath;
wsFctry = null;
}
}
/// <summary>
/// 创建RasterCatalog
/// </summary>
/// <param name="path">路径</param>
/// <param name="catalogName">名称</param>
/// <param name="rasterCoordSys">栅格坐标系</param>
/// <param name="geometryCoordsys">矢量坐标系</param>
public void CreateRasterCatalog_GP(string path, string catalogName, ISpatialReference rasterCoordSys, ISpatialReference geometryCoordsys)
{
//坐标转换
//Coordinate system for raster column
IGPCoordinateSystem rSR = new GPCoordinateSystemClass();
rSR.SpatialReference = rasterCoordSys;
//Coordinate system for geometry column
IGPSpatialReference gSR = new GPSpatialReferenceClass();
gSR.SpatialReference = geometryCoordsys;
//初始化GeoProcessor
ESRI.ArcGIS.Geoprocessor.Geoprocessor geoProcessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
RasterDSName = catalogName;
//创建工具
CreateRasterCatalog createRasterCatalog = new CreateRasterCatalog();
//设置参数
createRasterCatalog.out_path = path;
createRasterCatalog.out_name = catalogName;
createRasterCatalog.raster_spatial_reference = rSR;
createRasterCatalog.spatial_reference = gSR;
//利用工具创建RasterCatalog
geoProcessor.Execute(createRasterCatalog, null);
//ReturnMessages(geoProcessor);
}
//GP message handling
public void ReturnMessages(Geoprocessor gp)
{
if (gp.MessageCount > 0)
{
for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
{
Console.WriteLine(gp.GetMessage(Count));
}
}
}
//static string rasterFolder = @"c:\tempdata";
//static string outRC = @"Database Connections\connection to raster.sde\rc_203";
//LoadDirtoRasterCatalog(outRC, rasterFolder);
/// <summary>
/// 输入整个目录到库中
/// </summary>
/// <param name="outRasterCatalog">目标栅格库全路径</param>
/// <param name="inputDir">输入目录</param>
public void LoadDirtoRasterCatalog(string outRasterCatalog, string inputDir)
{
if (!Directory.Exists(inputDir))
{
System.Windows.Forms.MessageBox.Show("路径不正确,请重新输入", "提示");
return;
}
//初始化 GeoProcessor
ESRI.ArcGIS.Geoprocessor.Geoprocessor geoProcessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
//设置参数
IVariantArray parameters = new VarArrayClass();
//输入的文件夹目录
parameters.Add(inputDir);
//目标栅格库路径
parameters.Add(outRasterCatalog);
//Execute the tool to load rasters in the directory to raster catalog
geoProcessor.Execute("WorkspaceToRasterCatalog", parameters, null);
// ReturnMessages(geoProcessor);
}
/// <summary>
/// 选择要素的坐标系
/// </summary>
/// <param name="refFileName"></param>
/// <returns></returns>
public ISpatialReference InputReferece()
{
System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
if (SourceRasterDic != string.Empty || SourceRasterDic != " ")
{
openFileDialog.InitialDirectory = SourceRasterDic;
}
openFileDialog.Title = "加载图层数据";
openFileDialog.Filter = "Tif文件(*.tif)|*.tif|Shp文件(*.shp)|*.shp|Jpg文件(*.jpg)|*.jpg|Bmp文件(*.bmp)|*.bmp|Gif文件(*.gif)|*.gif|Img文件(*.img)|*.img|Png文件(*.png)|*.png|Tiff文件(*.tiff)|*.tiff";
openFileDialog.Multiselect = false;
openFileDialog.DefaultExt = "*.tif|*.shp";
openFileDialog.SupportMultiDottedExtensions = true;
string refFileName = string.Empty;
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
refFileName = openFileDialog.FileName;
}
else
{
return null;
}
IWorkspaceFactory pWorkspaceFactory = null;
string p = System.IO.Path.GetExtension(refFileName);
string fileNameWithoutExtentsion = System.IO.Path.GetFileNameWithoutExtension(refFileName);
string pathName = System.IO.Path.GetDirectoryName(refFileName);
string fileName = System.IO.Path.GetFileName(refFileName);
if (p == ".shp" || p == ".SHP")
{
IFeatureWorkspace ws;
IFeatureClass pFeatureClass;
pWorkspaceFactory = new ShapefileWorkspaceFactory();
ws = pWorkspaceFactory.OpenFromFile(pathName, 0) as IFeatureWorkspace;
pFeatureClass = ws.OpenFeatureClass(fileName);
ws = null;
return (pFeatureClass as IGeoDataset).SpatialReference;
}
if (p == ".jpg" || p == ".bmp" || p == ".gif" || p == ".img" || p == ".png" || p == ".tif" || p == ".tiff"
|| p == ".JPG" || p == ".BMP" || p == ".GIF" || p == ".IMG" || p == ".PNG" || p == ".TIF" || p == ".TIFF")
{
IRasterLayer pRasterLayer = new RasterLayerClass();
IRasterWorkspace pRasterWorkspace;
IRaster pRaster;
IRasterDataset pRasterDataset;
IWorkspace pWorkspace;
pWorkspaceFactory = new RasterWorkspaceFactoryClass();
pWorkspace = pWorkspaceFactory.OpenFromFile(pathName, 0);//0
pRasterWorkspace = pWorkspace as IRasterWorkspace;
pRasterDataset = pRasterWorkspace.OpenRasterDataset(fileName);
pRaster = pRasterDataset.CreateDefaultRaster();
pRasterLayer.CreateFromRaster(pRaster);
IRasterProps pRasterProps = pRasterLayer.Raster as IRasterProps;
return pRasterProps.SpatialReference;
}
return null;
}
/// <summary>
/// 获取要素数据集
/// </summary>
/// <param name="workspace">工作空间</param>
/// <returns>要素数据集</returns>
public IFeatureClass GetFirstFClass(IWorkspace workspace)
{
IFeatureClass FClass = null;
IEnumDataset enumDataset = workspace.get_Datasets(esriDatasetType.esriDTAny);
enumDataset.Reset();
IDataset perFeatSet = enumDataset.Next();
while (perFeatSet != null)
{
esriDatasetType getDatasetType = perFeatSet.Type;
switch (getDatasetType)
{
case esriDatasetType.esriDTFeatureClass:
ILayerFactoryHelper layerFactoryHelper = new LayerFactoryHelperClass();
IEnumLayer enumLayer = layerFactoryHelper.CreateLayersFromName(perFeatSet.FullName);
enumLayer.Reset();
ILayer layer = enumLayer.Next();
while (layer != null)
{
//筛选出第一个面状要素数据集
if (layer is IFeatureLayer &&
(layer as IFeatureLayer).FeatureClass.ShapeType
== ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
{
return (layer as IFeatureLayer).FeatureClass;
}
layer = enumLayer.Next();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(enumLayer);
break;
case esriDatasetType.esriDTFeatureDataset:
case esriDatasetType.esriDTTable:
case esriDatasetType.esriDTRasterDataset:
break;
default:
break;
}
perFeatSet = enumDataset.Next();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(enumDataset);
return FClass;
}
}
}
来自:http://www.cnblogs.com/wylaok/archive/2012/07/20/2600660.html
创建FILE GEODATABASE 和栅格目录及向栅格目录中添加影像的更多相关文章
- 黑马基础阶段测试题:创建一个存储字符串的集合list,向list中添加以下字符串:”C++”、”Java”、” Python”、”大数据与云计算”。遍历集合,将长度小于5的字符串从集合中删除,删除成功后,打印集合中的所有元素
package com.swift; import java.util.ArrayList; import java.util.List; import java.util.ListIterator; ...
- Java File文件操作 创建文件\目录,删除文件\目录
Java手册 java.io 类 File java.lang.Object java.io.File 所有已实现的接口: Serializable, Comparable<File> p ...
- File 创建一个空目录,创建一个多级目录,删除一个目录
package seday03; import java.io.File; /** * 创建一个空目录,* @author xingsir*/public class MkDirDemo { publ ...
- File常用的方法操作、在磁盘上创建File、获取指定目录下的所有文件、File文件的重命名、将数据写入File文件
文章目录 1.基本介绍 2.构造方法 3.常用的方法 4.代码实例 4.1 创建文件和目录(目录不存在) 4.1.1 代码 4.1.2 测试结果 4.2 测试目录存在的情况.直接写绝对的路径名 4.2 ...
- CentOS 创建SVN 服务器,并且自动同步到WEB 目录
CentOS 创建SVN 服务器,并且自动同步到WEB 目录 标签: centossvnsubversion服务器 2013-12-06 10:09 5492人阅读 评论(0) 收藏 举报 分类: ...
- 2、创建File类对象
既然是内置类,那么我们创建对象时自然要看它封装好的构造函数咯,由下图的4中构造函数我们可知有4种办法来创建File对象 具体代码如下 public class Demo { public static ...
- Java基础---Java---IO流-----File 类、递归、删除一个带内容的目录、列出指定目录下文件夹、FilenameFilte
File 类 用来将文件或者文件夹封装成对象 方便对文件与文件夹进行操作. File对象可以作为参数传递给流的构造函数 流只用操作数据,而封装数据的文件只能用File类 File类常见方法: 1.创建 ...
- VNC XEN 双鼠标问题 以及 使用 virt-manager 工具创建的 Xen 虚拟机配置文件不在 /etc/xen/ 目录中了
0.本人用的是Ubuntu 12.04,在其中安装xen 4.1,用的是virt-manager安装虚拟机 1.VNC XEN 双鼠标问题,在配置文件中加入: 找到:(usb 1),在之后加入: (u ...
- linux下编译qt5.6.0静态库(使用./configure --help来看看都有哪些参数。超详细,有每一个模块的说明。如果改变了安装的目录,需要到安装目录下的bin目录下创建文件qt.conf)(乌合之众)good
linux下编译qt5.6.0静态库 linux下编译qt5.6.0静态库 configure生成makefile 安装选项 Configure选项 第三方库: 附加选项: QNX/Blackberr ...
随机推荐
- hive优化之------控制hive任务中的map数和reduce数
一. 控制hive任务中的map数: 1. 通常情况下,作业会通过input的目录产生一个或者多个map任务. 主要的决定因素有: input的文件总个数,input的文件大小,集群设置的 ...
- Android滑动动画ViewFlipper和视频播放VideoView的使用
Android滑动动画,可以用ViewPager或者ViewFlipper实现. ViewPager自带触摸滑动功能,结合Fragment使用很好,来自补充组件android-support-v4.j ...
- 【转】Maven实战(五)---两个war包的调用
原博文出自于: http://blog.csdn.net/liutengteng130/article/details/42879803 感谢! 开篇前提 1.为什么要用两个war包的调用? ...
- Linux服务器集群系统(一)(转)
add by zhj:虽然是2002年的文章,但读来还是收益良多.在 章文嵩:谈LVS及阿里开源背后的精彩故事 中LVS发起人及主要贡献者谈了LVS的开发过程及阿里开源的一些故事 原文:http:// ...
- work_6
这次的作业是阅读C++11的新特性并提出问题,作为一个大部分代码都是用C++的基本语法并没有特别关注C++一代又一代新特性的学生来说,首先我阅读了一些关于新特性的文章.为了更快的理解,我首先选择了阅读 ...
- 【转】使用JavaScriptCore在JS和OC间通信
http://www.cocoachina.com/ios/20160623/16796.html iOS 开发中,我们时不时的需要加载一些 Web 页面,一些需求使用 Web 页面来实现可以更可控, ...
- 简谈 JavaScript、Java 中链式方法调用大致实现原理
相信,在 JavaScript .C# 中都见过不少链式方法调用,那么,其中实现该类链式调用原理,大家有没有仔细思考过?其中 JavaScript 类库:jQuery 中就存在大量例子,而在 C# 中 ...
- java读取properties的工具类PropertiesUtil
package org.properties.util; import java.io.FileInputStream; import java.io.FileOutputStream; import ...
- Unity中关于等待的函数
public void InvokeRepating(string methodName,float time,float repeatRate); 语法 注: 1.methodeName为调用的方法 ...
- CentOS6.4 64位系统安装jdk
1. CentOS操作安装好了以后,系统自带了openJDK,先查看相关的安装信息: $rpm -qa | grep java tzdata-java-2013b-1.el6.noarchjava-1 ...