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的更多相关文章

  1. Kinect for Windows SDK开发学习相关资源

    Kinect for Windows SDK(K4W)将Kinect的体感操作带到了平常的应用学习中,提供了一种不同于传统的鼠标,键盘及触摸的无接触的交互方式,在某种程度上实现了自然交互界面的理想,即 ...

  2. 微信公众账号 Senparc.Weixin.MP SDK 开发教程 索引

    Senparc.Weixin.MP SDK从一开始就坚持开源的状态,这个过程中得到了许多朋友的认可和支持. 目前SDK已经达到比较稳定的版本,这个过程中我觉得有必要整理一些思路和经验,和大家一起分享. ...

  3. 高拍仪拍照SDK开发(良田影像S300L|S500L)

    高拍仪拍照SDK开发下载地址:点击下载 本SDK适用于:良田影像S300L|S500L 高拍仪如图: SDN开发包安装之后找到安装目录,如图: 大家找到各自需要的版本即可,需要注意的是如果需要上传图片 ...

  4. TortoiseSVN安装以及淘宝 TAE SDK 开发环境的搭建

    一.TortoiseSVN 的下载和安装 1.进入TortoiseSVN 官网下载地址http://tortoisesvn.net/downloads.html,根据自己的操作系统位数下载相应最新版本 ...

  5. SDK开发断点失效

    做SDK开发,一般会创建一个静态库工程,然后添加一个app的Target 可是,Xcode7创建的工程,app的Target中断点有效,能断住,为什么静态库的Target中的断点断不住呀. 断点断住发 ...

  6. Vmware Vsphere WebService SDK开发(第一讲)-基本知识学习

    刚开始这方面开发的时候,不知道如何下手,能够查到的资料特别少,而且看到很多网友和我一样也在找这方面的资料.接下来的一段时间我就结合自己所参与的项目,完成关于Vmware Vsphere WebServ ...

  7. 【转】微信公众账号 Senparc.Weixin.MP SDK 开发教程 索引

    微信公众账号 Senparc.Weixin.MP SDK 开发教程 索引 Senparc.Weixin.MP SDK从一开始就坚持开源的状态,这个过程中得到了许多朋友的认可和支持. 目前SDK已经达到 ...

  8. ArcObjects SDK(AE)10.1在vs2012安装的方法

    ArcObjects SDK(以下简称AO)10.1只支持vs2010,如果装了vs2012,再安装AO会提示一串鸡肠(英文),意思是AO10.1只支持vs2010 想在2012下安装,可以通过修改注 ...

  9. 微信公众账号 Senparc.Weixin.MP SDK 开发教程

    http://www.cnblogs.com/szw/archive/2013/05/14/weixin-course-index.html 微信公众账号 Senparc.Weixin.MP SDK ...

  10. Kinect for Windows SDK开发入门(一):开发环境配置

    [译]Kinect for Windows SDK开发入门(一):开发环境配置 前几天无意中看到微软发布了Kinect for windows sensor,进去看了一下Kinect应用的例子,发现K ...

随机推荐

  1. 示例:Service连接应用程序

    整体思路: 1.创建pod 2.创建关联上一步pod的service 3.使用不同的方式配置service从而能够在集群内部访问 4.使用ssl方式加密访问service 5.配置service为no ...

  2. 使用growpart扩容CentOS虚拟机磁盘

    说明 一块磁盘,比如有130G,但是只有100G拿来用了,安装俩分区,一个是swap,另一个是根分区/,根分区采用的是LVM逻辑卷管理. 现在要做的是把剩余的这空闲30G分配给根分区使用 这个并不是新 ...

  3. Notebook交互式完成目标检测任务

    摘要:本文将介绍一种在Notebook中进行算法开发的新方式,新手也能够快速训练自己的模型. 目标检测是计算机视觉中非常常用且基础的任务,但是由于目标检测任务的复杂性,往往令新手望而却步.本文将介绍一 ...

  4. 计算机网络(Learning Records)

    背景:没想到本专业并不开设这门课程,感觉过于逆天,之前开发的时候了解过相关知识 但是从来没有系统地学过,就自己看了书,总结一下 参考:<TCP/IP详解 卷1:协议> 概述 大多数网络应用 ...

  5. Python凯撒密码加解密

    #凯撒密码第一个版本 #加密 pxpt=input("请输入明文文本:") for p in pxpt: if 'a'<=p<='z': print(chr(ord(' ...

  6. 原生JavaScript

    原生JavaScript 为了方便查看. 所有的js和css代码都是嵌入式直接写在html代码中 1.js的引入方式 <!DOCTYPE html> <html lang=" ...

  7. String内建函数

    int length():返回字符串的长度: return value.lengthchar charAt(int index): 返回某索引处的字符return value[index]boolea ...

  8. linux下开机启动443程序无法访问解决方法

    前言:最近,有一个项目需要用到开机自动启动程序,所以就研究了一下,环境为redhat8,程序是node,使用forever来进行node程序的持久化,程序使用的是443端口,开启的是https 1.把 ...

  9. Mysql之PXC高可用

    PXC高可用 1.环境准备 pxc1: centos7 10.0.0.7 pxc2: centos7 10.0.0.17 pxc3: centos7 10.0.0.27 pxc4: centos7 1 ...

  10. 二、.Net Core搭建Ocelot

    上一篇文章介绍了Ocelot的基本概念:https://www.cnblogs.com/yangleiyu/p/15043762.html 本文介绍在.net core中如何使用ocelot. Oce ...