ArcEngine 栅格数据 总结
Posted 杨千羽
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ArcEngine 栅格数据 总结相关的知识,希望对你有一定的参考价值。
<header id="header">
<nav class="nav-container group" id="nav-mobile">
<div class="nav-toggle"><i class="fa fa-bars"></i></div>
<div class="nav-text"><!-- put your mobile menu text here --></div>
<div class="nav-wrap container"><ul id="menu-gis%e4%b8%bb%e8%a6%81%e7%9b%ae%e5%bd%95" class="nav container-inner group"><li id="menu-item-35143" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-35143"><a href="https://www.giserdqy.com/gis/gisknowledge/">GIS理论</a></li>
<div class="container"> <div class="container-inner"> <div class="toggle-search"><i class="fa fa-search"></i></div> <div class="search-expand"> <div class="search-expand-inner"> <form method="get" class="searchform themeform" action="https://www.giserdqy.com/"> <div> <input type="text" class="search" name="s" onblur="if(this.value=='')this.value='To search type and hit enter';" onfocus="if(this.value=='To search type and hit enter')this.value='';" value="To search type and hit enter"> </div>
</nav><!--/#nav-mobile--> <div class="container-inner group"> <div class="group pad"> <p class="site-title"><a href="https://www.giserdqy.com/" rel="home">GIS开发者</a></p> <p class="site-description">gis,openlayers,leaflet,gis应用,geoai,geoserver,cesium,python,arcpy,arcmap,webgis</p> </div> <nav class="nav-container group" id="nav-header"> <div class="nav-toggle"><i class="fa fa-bars"></i></div> <div class="nav-text"><!-- put your mobile menu text here --></div> <div class="nav-wrap container"><ul id="menu-%e6%a0%b8%e5%bf%83%e7%9b%ae%e5%bd%95" class="nav group"><li id="menu-item-35187" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-home menu-item-35187"><a href="https://www.giserdqy.com/">首页</a></li>
</div><!--/.container--> <script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</header><!--/#header--> <div class="container" id="page"> <div class="container-inner"> <div class="main"> <div class="main-inner group">
<div class="page-title pad group"> <ul class="meta-single group"> <li class="category"><a href="https://www.giserdqy.com/arcengine/" rel="category tag">ArcEngine</a></li> </ul>
<article class="post-26805 post type-post status-publish format-standard has-post-thumbnail hentry category-arcengine tag-arcengine tag-arcengine--"> <div class="post-inner group"> <p id="breadcrumbs"><span><span><a href="https://www.giserdqy.com/">首页</a> » <span><a href="https://www.giserdqy.com/arcengine/">ArcEngine</a> » <span class="breadcrumb_last" aria-current="page">ArcEngine 栅格数据 总结</span></span></span></span></p> <h1 class="post-title">ArcEngine 栅格数据 总结</h1> <div class="bdsharebuttonbox bdshare-button-style0-24" data-bd-bind="1563003962454"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_mshare" data-cmd="mshare" title="分享到一键分享"></a><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a><a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a><a href="#" class="bds_youdao" data-cmd="youdao" title="分享到有道云笔记"></a><a href="#" class="bds_twi" data-cmd="twi" title="分享到Twitter"></a><a href="#" class="bds_fbook" data-cmd="fbook" title="分享到Facebook"></a><a href="#" class="bds_linkedin" data-cmd="linkedin" title="分享到linkedin"></a><a href="#" class="bds_copy" data-cmd="copy" title="分享到复制网址"></a><a href="#" class="bds_print" data-cmd="print" title="分享到打印"></a></div>
<p class="post-byline">by <a href="https://www.giserdqy.com/author/dqy/" title="由giser发布" rel="author">giser</a> · 2019-04-05</p> <div class="clear"></div> <div class="entry "> <div class="entry-inner"> <div id="ez-toc-container" class="counter-hierarchy counter-decimal">
目录
本文大部分内容参考AO帮助文档和ArcMap帮助文档,大家实际使用中遇到的问题也可以在本帖下方留言交流,谢谢!
欢迎浏览,拒绝转载!基础知识
栅格数据是由一系列等间距的格网矩阵组成,用来表达完整的主题、光谱、图像信息。
栅格数据模型分为栅格数据集(Raster dataset)、栅格目录(Raster catalog)、镶嵌数据集(Mosaic dataset)。他们以文件系统、个人地理数据库、文件地理数据库、企业地理数据库为数据源进行存储。栅格数据集也就是我们经常所得的jpg、tif文件等, ArcGIS 将这些栅格数据抽象为 RasterDataset,栅格数据集就代表了磁盘中的一个文件,它由一个或多个波段组成。在使用栅格数据集的时候,栅格数据会被转换成 IMG 文件存储在数据库中。我们可以对栅格数据集进行一些操作,如改变空间参考,建立影像金字塔等。
栅格目录,正如其名字一样是一个目录,跟书的目录相似,它记录了一个或者多个栅格数据集,每一个栅格数据集都作为一条记录存储在栅格目录中。栅格目录对栅格数据集的管理有两种方式,托管和非托管。托管方式的时候,栅格数据是存储在数据库中, 非托管的时候,栅格目录记录了栅格数据集的路径,也就是栅格数据并没有存储在数据库中。当我们删除一条记录的时候,对我们的栅格数据没有任何影响。
镶嵌数据集可以说是栅格数据集和栅格目录的混合技术,它的存储方式和栅格目录类似,但是在使用的时候和普通的栅格数据集是一样的,镶嵌数据集用于管理和发布海量多分辨率,多传感器影像,对栅格数据提供了动态镶嵌和实时处理的功能。
对文件地理数据库、个人地理数据库和 ArcSDE 地理数据库中的栅格存储加以比较:
类图
在线地址:传送门
本地路径:本地路径:如 C:\\Program Files (x86)\\ArcGIS\\DeveloperKit10.2\\Diagrams\\DataSourcesRasterObjectModel.pdf
##和栅格数据集有关的GP工具
栅格数据接口使用示例
打开栅格数据工作空间
//Open a file geodatabase workspace as RasterWorkspace.
static IRasterWorkspaceEx OpenFGDB(string FGDBPath)
//FGDBPath string example: c:\\data\\raster.gdb.
IWorkspaceFactory2 workspaceFactory = new FileGDBWorkspaceFactoryClass();
return (IRasterWorkspaceEx)workspaceFactory.OpenFromFile(FGDBPath, 0);
//Open an ArcSDE workspace as RasterWorkspace.
static IRasterWorkspaceEx OpenSDE(string conString)
//conString example: SERVER=ais;INSTANCE=9200;VERSION=sde.DEFAULT;USER=raster;PASSWORD=raster.
IWorkspaceFactory2 workspaceFactory = new SdeWorkspaceFactoryClass();
return (IRasterWorkspaceEx)workspaceFactory.OpenFromString(conString, 0);
//Open an accessed workspace as RasterWorkspace.
static IRasterWorkspaceEx OpenAccess(string PGDBPath)
//FGDBPath string example: c:\\data\\rasters.mdb.
IWorkspaceFactory2 workspaceFactory = new AccessWorkspaceFactoryClass();
return (IRasterWorkspaceEx)workspaceFactory.OpenFromFile(PGDBPath, 0);
//Open a file workspace as RasterWorkspace.
static IRasterWorkspace OpenFileWorkspace(string wsPath)
//wsPath example: c:\\data\\rasters.
IWorkspaceFactory workspaceFact = new RasterWorkspaceFactoryClass();
return (IRasterWorkspace)workspaceFact.OpenFromFile(wsPath, 0);
打开栅格数据集
IRasterDataset rasterDataset = rasterWorkspace.OpenRasterDataset(datasetName);
IRasterDataset rasterDataset = rasterWorkspaceEx.OpenRasterDataset(datasetName);
创建栅格数据集
- Creating a raster dataset(创建以文件存储的栅格数据集,如TIFF)
1)Create a workspace.创建工作空间
2)Create a TIFF file with specified width, height, pixel type, cell size, and other necessary dimensions.创建一个TIFF文件,并指定它的宽度,高度,像素类型、像元大小和其他必要的维度。
3)Use the IPixelBlock and IRasterEdit interfaces to edit the pixel values.使用IPixelBlock 和 IRasterEdit 接口来编辑像元的值。
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;
- Creating a raster dataset in a geodatabase(创建以GDB存储的栅格数据集,如GRID)
1)Create a file geodatabase workspace factory.创建哥FGDB的工作工厂对象。
2)Create a raster workspace and query IRasterWorkspaceEx.创建一个栅格工作空间对象并且转换到IRasterWorkspaceEx对象上
3)Define the storage and raster properties using the RasterStorageDef and RasterDef classes. 利用RasterStorageDef 和RasterDef 类定义栅格数据集的存储和栅格属性。
4)Create the dataset using the CreateRasterDataset method.利用CreateRasterDataset方法创建栅格数据集。
IWorkspaceFactory wsf = new FileGDBWorkspaceFactoryClass();
IRasterWorkspaceEx ws = (IRasterWorkspaceEx)wsf.OpenFromFile(@"c:\\temp\\fgdb.gdb", 0);
//Define the raster storage.
IRasterStorageDef storage = new RasterStorageDefClass();
storage.Tiled = true;
storage.TileHeight = 128;
storage.TileWidth = 128;
//Define the spatial reference.
IRasterDef rasterDef = new RasterDefClass();
rasterDef.SpatialReference = new UnknownCoordinateSystemClass();
//Create data.
IRasterDataset rasterDs = ws.CreateRasterDataset("newraster", 3,
rstPixelType.PT_SHORT, storage, "sde.DEFAULT", rasterDef, null);
访问HDF和NIFF数据的子集
一些栅格格式,如分层数据格式(HDF),可以在单个文件中包含多个subdatasets。访问HDF subdatasets使用IRasterDatasetJukebox接口,请参见下面的代码示例:
IWorkspaceFactory wsf = new FileGDBWorkspaceFactoryClass();
IRasterWorkspaceEx ws = (IRasterWorkspaceEx)wsf.OpenFromFile(@"c:\\temp\\fgdb.gdb", 0);
//Define the raster storage.
IRasterStorageDef storage = new RasterStorageDefClass();
storage.Tiled = true;
storage.TileHeight = 128;
storage.TileWidth = 128;
//Define the spatial reference.
IRasterDef rasterDef = new RasterDefClass();
rasterDef.SpatialReference = new UnknownCoordinateSystemClass();
//Create data.
IRasterDataset rasterDs = ws.CreateRasterDataset("newraster", 3,
rstPixelType.PT_SHORT, storage, "sde.DEFAULT", rasterDef, null);
读取JPEG EXIF扩展标记信息
public static void JPEG_EXIFtag(IRasterDataset exifDataset)
//exifDataset represents a raster dataset opened from a JPEG file that has EXIF tags.
IDataset dataset = (IDataset)exifDataset;
//Get the EXIF tags and the associated values.
IPropertySet propertySet = dataset.PropertySet;
System.Object tag_names;
System.Object tag_values;
propertySet.GetAllProperties(out tag_names, out tag_values);
string[] stringNames = (string[])tag_names;
object[] stringValues = (object[])tag_values;
for (int i = 0; i < stringNames.Length - 1; i++)
System.Console.WriteLine(stringNames[i]);
System.Console.WriteLine(stringValues[i]);
读取像素数据
- 使用光栅游标访问像素数据
public static void UsingRasterCursorWithPixelBlock(IRasterDataset2 rasterDs)
try
//Create a raster.
IRaster2 raster2 = rasterDs.CreateFullRaster()as IRaster2;
//Create a raster cursor with a system-optimized pixel block size by passing a null.
IRasterCursor rasterCursor = raster2.CreateCursorEx(null);
//Use the IRasterEdit interface.
IRasterEdit rasterEdit = raster2 as IRasterEdit;
//Loop through each band and pixel block.
IRasterBandCollection bands = rasterDs as IRasterBandCollection;
IPixelBlock3 pixelblock3 = null;
long blockwidth = 0;
long blockheight = 0;
System.Array pixels;
IPnt tlc = null;
object v;
long bandCount = bands.Count;
do
以上是关于ArcEngine 栅格数据 总结的主要内容,如果未能解决你的问题,请参考以下文章