ArcObjects SDK开发 011 RasterLayer
1、RasterLayer的结构
图层的话,除了FeatureLayer外,用的最多的就是RasterLayer了。较FeatureLayer而言,RasterLayer比较简单,这点可以从栅格图层的属性对话框中可以看出。

其中General选项卡对应着RasterLayer继承实现的ILayerGeneralProperties接口,Source选项卡对应IRasterLayer的Ratser属性,Display选项卡对应着ILayerEffects接口,Symbology选项卡对应着IRasterLayer的Renderer属性。
2、IRaster接口
IRasterLayer的Raster属性返回的是IRaster接口类型。其指的是实际的栅格数据源,我们一般存储为tif或者img文件。Raster类实现了IRaster接口,同时Raster还继承了以下接口。

其中通过IRaster可以分块读取栅格数据的像元信息,并可以设置重采样方式。IRaster2接口提供了一些像素与地图坐标相互转换的函数。IRasterBandCollection接口可以读取栅格数据包含的波段信息。IRasterEdit接口提供了修改栅格数据像元值的功能。IRasterProps提供了栅格数据的属性信息。ISaveAs接口提供了栅格数据的保存功能。
不过我们一般很少用IRaser接口去修改栅格数据,主要还是靠调用ArcToolbox里面的工具来处理。
3、IRasterRenderer接口
该接口为栅格图层渲染接口,通过RasterLayer的Renderer可以获取或设置。继承该接口的类如下图所示。

其中我们常用的有RasterClassifyColorRampRenderer,分级别渲染,例如显示某个区域内的人口密度数据的栅格数据文件,就可以按照不同的颜色进行分段显示。
RasterUniqueValueRenderer,唯一值渲染,例如土地分类数据,就可以把耕地、林地、草地、城市用地等按照不同的颜色显示。
RasterStretchColorRampRenderer,拉伸渲染,一般我们显示Dem数据的时候都会使用这种渲染方式。
每种渲染方式如何设置,都可以参考ArcMap中的参数设置界面以及SDK帮助。
4、打开栅格数据
我们常用的栅格数据主要有tif和img格式。打开栅格数据有多种方法,我习惯用RasterLayer的CreateFromFilePath函数打开栅格数据,这这种方式比较简单。代码如下。
var myRasterLayer = new RasterLayerClass();
myRasterLayer.CreateFromFilePath(this.DEMFilePath);
5、创建栅格数据文件
我们可以使用IWorkSpace来创建栅格数据文件。
public static IRasterDataset CreateRasterDataset(string Path, string FileName)
{
try
{
IRasterWorkspace2 rasterWs = OpenRasterWorkspace(Path);
//Define the spatial reference of the raster dataset.
ISpatialReference sr = new UnknownCoordinateSystemClass();
//Define the origin for the raster dataset, which is the lower left corner of the raster.
IPoint origin = new PointClass();
origin.PutCoords(15.0, 15.0);
//Define the dimensions of the raster dataset.
int width = 100; //This is the width of the raster dataset.
int height = 100; //This is the height of the raster dataset.
double xCell = 30; //This is the cell size in x direction.
double yCell = 30; //This is the cell size in y direction.
int NumBand = 1; // This is the number of bands the raster dataset contains.
//Create a raster dataset in TIFF format.
IRasterDataset rasterDataset = rasterWs.CreateRasterDataset(FileName, "TIFF",
origin, width, height, xCell, yCell, NumBand, rstPixelType.PT_UCHAR, sr,
true);
//If you need to set NoData for some of the pixels, you need to set it on band
//to get the raster band.
IRasterBandCollection rasterBands = (IRasterBandCollection)rasterDataset;
IRasterBand rasterBand;
IRasterProps rasterProps;
rasterBand = rasterBands.Item(0);
rasterProps = (IRasterProps)rasterBand;
//Set NoData if necessary. For a multiband image, a NoData value needs to be set for each band.
rasterProps.NoDataValue = 255;
//Create a raster from the dataset.
IRaster raster = rasterDataset.CreateFullRaster();
//Create a pixel block using the weight and height of the raster dataset.
//If the raster dataset is large, a smaller pixel block should be used.
//Refer to the topic "How to access pixel data using a raster cursor".
IPnt blocksize = new PntClass();
blocksize.SetCoords(width, height);
IPixelBlock3 pixelblock = raster.CreatePixelBlock(blocksize)as IPixelBlock3;
//Populate some pixel values to the pixel block.
System.Array pixels;
pixels = (System.Array)pixelblock.get_PixelData(0);
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
if (i == j)
pixels.SetValue(Convert.ToByte(255), i, j);
else
pixels.SetValue(Convert.ToByte((i * j) / 255), i, j); pixelblock.set_PixelData(0, (System.Array)pixels);
//Define the location that the upper left corner of the pixel block is to write.
IPnt upperLeft = new PntClass();
upperLeft.SetCoords(0, 0);
//Write the pixel block.
IRasterEdit rasterEdit = (IRasterEdit)raster;
rasterEdit.Write(upperLeft, (IPixelBlock)pixelblock);
//Release rasterEdit explicitly.
System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);
return rasterDataset;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
return null;
}
}
public static IRasterWorkspace2 OpenRasterWorkspace(string PathName)
{
//This function opens a raster workspace.
try
{
IWorkspaceFactory workspaceFact = new RasterWorkspaceFactoryClass();
return workspaceFact.OpenFromFile(PathName, 0)as IRasterWorkspace2;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
return null;
}
}
我们一般创建的时候,会调用ArcToolbox中的工具去创建。
ArcObjects SDK开发 011 RasterLayer的更多相关文章
- Kinect for Windows SDK开发学习相关资源
Kinect for Windows SDK(K4W)将Kinect的体感操作带到了平常的应用学习中,提供了一种不同于传统的鼠标,键盘及触摸的无接触的交互方式,在某种程度上实现了自然交互界面的理想,即 ...
- 微信公众账号 Senparc.Weixin.MP SDK 开发教程 索引
Senparc.Weixin.MP SDK从一开始就坚持开源的状态,这个过程中得到了许多朋友的认可和支持. 目前SDK已经达到比较稳定的版本,这个过程中我觉得有必要整理一些思路和经验,和大家一起分享. ...
- 高拍仪拍照SDK开发(良田影像S300L|S500L)
高拍仪拍照SDK开发下载地址:点击下载 本SDK适用于:良田影像S300L|S500L 高拍仪如图: SDN开发包安装之后找到安装目录,如图: 大家找到各自需要的版本即可,需要注意的是如果需要上传图片 ...
- TortoiseSVN安装以及淘宝 TAE SDK 开发环境的搭建
一.TortoiseSVN 的下载和安装 1.进入TortoiseSVN 官网下载地址http://tortoisesvn.net/downloads.html,根据自己的操作系统位数下载相应最新版本 ...
- SDK开发断点失效
做SDK开发,一般会创建一个静态库工程,然后添加一个app的Target 可是,Xcode7创建的工程,app的Target中断点有效,能断住,为什么静态库的Target中的断点断不住呀. 断点断住发 ...
- Vmware Vsphere WebService SDK开发(第一讲)-基本知识学习
刚开始这方面开发的时候,不知道如何下手,能够查到的资料特别少,而且看到很多网友和我一样也在找这方面的资料.接下来的一段时间我就结合自己所参与的项目,完成关于Vmware Vsphere WebServ ...
- 【转】微信公众账号 Senparc.Weixin.MP SDK 开发教程 索引
微信公众账号 Senparc.Weixin.MP SDK 开发教程 索引 Senparc.Weixin.MP SDK从一开始就坚持开源的状态,这个过程中得到了许多朋友的认可和支持. 目前SDK已经达到 ...
- ArcObjects SDK(AE)10.1在vs2012安装的方法
ArcObjects SDK(以下简称AO)10.1只支持vs2010,如果装了vs2012,再安装AO会提示一串鸡肠(英文),意思是AO10.1只支持vs2010 想在2012下安装,可以通过修改注 ...
- 微信公众账号 Senparc.Weixin.MP SDK 开发教程
http://www.cnblogs.com/szw/archive/2013/05/14/weixin-course-index.html 微信公众账号 Senparc.Weixin.MP SDK ...
- Kinect for Windows SDK开发入门(一):开发环境配置
[译]Kinect for Windows SDK开发入门(一):开发环境配置 前几天无意中看到微软发布了Kinect for windows sensor,进去看了一下Kinect应用的例子,发现K ...
随机推荐
- 使用filebeat过滤掉部分字段
host,agent,ecs三个字段也是不让drop的 processors: - drop_fields: fields: ["log","input",&q ...
- Elasticsearch不支持事务有什么好的弥补方案
1.问题 源自星球同学的提问:es如何与hive或mysql结合使用?es不支持事务有什么好的弥补方案吗? 2.事务的核心概念 如果一个数据库声称支持事务的操作,那么该数据库必须要具备以下ACID四个 ...
- MySQL数据库安装保姆教程及问题解决
使用Mysql的zip压缩包解压版,下载之后需进行一定的配置,才能使用它. 下面对Mysql压缩包版的安装方法进行详细的描述,如有疑问或错误,望及时反馈. 首先,mysql的官方下载地址点我进行下载 ...
- PAT (Basic Level) Practice 1022 D进制的A+B 分数 20
输入两个非负 10 进制整数 A 和 B (≤230−1),输出 A+B 的 D (1<D≤10)进制数. 输入格式: 输入在一行中依次给出 3 个整数 A.B 和 D. 输出格式: 输出 A+ ...
- LeetCode - 数组的改变和移动
1. 数组的改变和移动总结 1.1 数组的改变 数组在内存中是一块连续的内存空间,我们可以直接通过下标进行访问,并进行修改. 在Java中,对于List类型来说,我们可以通过set(idx, elem ...
- 给nsis窗口添加立体阴影
利用SetClassLong函数给nsis窗口添加了阴影,看起来很酷^_^ System::Call `user32::SetClassLong(i$HWNDPARENT,i${GCL_STYLE}, ...
- Seal-Report: 开放式数据库报表工具
Seal Report是.Net的一个基于Apache 2.0 开源工具,完全用C# 语言编写,最新的6.6 版本采用.NET 6,github: https://github.com/ariacom ...
- leetcode刷题记录之25(集合实现)
题目描述: 给你链表的头节点 head ,每 k 个节点一组进行翻转,请你返回修改后的链表. k 是一个正整数,它的值小于或等于链表的长度.如果节点总数不是 k 的整数倍,那么请将最后剩余的节点保持原 ...
- MergeOption.NoTracking的使用
前两天项目维护出现一个bug,报错信息是提交出错:AcceptChanges 无法继续,因为该对象的键值与 ObjectStateManager 中的另一个对象冲突.请在调用 AcceptChange ...
- 华为云ubunbu部署.NetCore3.1项目(DDD商城)
提前项目打包发布,文件传输工具Filezilla,注意是选择sftp协议,将publish文件传到/home文件夹下 第一步 .NetCoreSDK安装 微软官方的文档https://docs.mi ...