ArcGIS Engine Style文件操作
对于一个GISer来说,地图,符号这些都应该有着比别人更深刻的理解和认识,作为平台软件都会提供一套自己的符号库,符号库里面根据类别和种类进行区分,因为点,线,面的自然存在和固有属性是不肯能让你用面状符号去渲染点和线的,学GIS的人,一般都会有分类的意识。
说我是一个ArcGIS 的用户,其实算不上,只能说是ArcGIS 软件的一个粉丝和使用者而已,我工作的大部分时间都是和ArcGIS 打交道,虽然跟一个东西时间长了,了解的也就越多,这句话是不错,但是对我来说还远远不够,我在告诉别人ArcGIS 的某一个功能是怎么用的时候,还总想告诉别人这是为什么,这点其实并不容易,但是我从来没放弃过,只要有时间,我自己也会去思考一些问题,思考如何能给 别人说的清楚,说的通俗易懂,不断的去学习,不断的看ArcGIS的英文资料,也不断的用鼠标在ArcGIS上点来点去,总希望发现奇迹,前几天用ArcGIS Engine 做一些符号化的功能,学写了一些,也有了自己的一些心得,希望能和大家分享。遇到了很多问题,比如经常在打开style文件的时候报错,有的时候不报错,有的时候报错,折腾了好长时间,最后发现,每次用完之后,需要将和符号相关的几个对象释放掉。现在开始看几个和符号化相关的接口:
IStyleGalleryStorage
该接口被ServerStyleGalleryClass和StyleGalleryClass实现,其中前者是用来针对ArcGIS Engine的serverstyle文件,后者是针对ArcGIS Desktop的style文件的。IStyleGalleryStorage 用来管理可以使用IStyleGallery编辑的Styles文件,我们可以将IStyleGalleryStorage看做一个存放Style文件的一个大的容器,每一个style文件由IStyleGalleryItems组成,通过IStyleGalleryStorage 我们可以添加、删除、更新对应的style文件。ESRI为我们提供了很多的默认的style文件,这些style文件的默认的存放路径C:\Program Files\ArcGIS\Styles下。该路径下有两种类型的文件,一种是文件扩展名称为.ServerStyle的文件,一种是文件扩展名称为style的文件。ServerStyle文件用于AE的开发,Style文件是ArcMap可以使用的样式文件。ESRI自带的工具里面有一种工具可以将style类型的文件转换为ServerStyle类型的文件,然后提供给ArcGIS Engine使用。
下面主要说明一下IStyleGalleryStorage对象的几个主要成员
AddFile;
语法:Public Void AddFile(string path);
Path:表示文件在本地的存放位置,C:\Program Files\ArcGIS\Styles\ Business.ServerStyle文件
该函数的意思是将一个指定位置的style文件添加到这个指定的容器里面,然后就可以通过IStyleGallery来对这些容器中的IStyleGalleryItem对象进行调用、处理等基本操作。
)DefaultStylePath: 是一个只读类型的属性,她返回的是ESRI中style文件默认的存放路径,这个跟ArcGIS软件的安装路径有关。返回值是一个String类型的变量,她的默认值可以是C:\Program Files\ArcGIS\Styles 这个是我本地计算机的DefualtStylePath的返回,因为我的ArcGIS软件安装在C盘。
)File属性 The file at the given index. 返回指定索引值的style文件的全路径名称、或者文件名称。
)FileCount :The number of files in the Style Gallery 返回 IStyleGalleryStorage中所包含的style文件的数量。
)RemoveFile(string path) 返回指定路径的style文件。
)TargetFile The target output file for adding, updating and removing items. 这个是个可读、可写的属性。这个属性用来设置要编辑的目标文件,这个需要给定一个style文件的路径,如果本地计算机在指定的位置存在这个一个文件,那么系统就修改这个一个文件,如果本地计算机不存在这个一个文件,那么系统就将会在给定的位置创建一个新的style文件。当我们需要为IStyleGallery添加IStyleGalleryItem示例的时候,就需要指定这个属性,用来设置要编辑的IstyleGalleryStoragy中的某一个相对应的style文件。比如,在创建一个新的IstyleGalleryStoragy实例的时候,指定TargetFile属性,这个Style文件中就将默认的包含两个style文件,
一个是C:\Users\Administrator\AppData\Roaming\ESRI\ArcMap\Administrator.style文件,
一个是C:\Program Files\ArcGIS\Styles\ESRI.style文件
每一个文件都是由IStyleGalleryItem项组成的。并且每一个.style文件或.ServerStyle文件中的IStyleGalleryItem中的Item属性都有一个Class类型,然后根据不同的Class类型,添加后划分到对应的Class类型中,如下图所示:(关于Class类后面还有介绍)
如上图所示的ESRI.style文件中,有很多类型的IstyleGalleryItem项,比如:Reference Systems/Maplex Labels/Shadows/Area Patches/Line Patches等等。每一个类都有若干数量的IStyleGalleryItem组成,比如上图中的Color Ramps项就是由右边的IStyleGalleryItem项组成的。
:IStyleGallery
IStyleGallery可以看成是ISyleGalleryItem的容器,我们在上一节中已经提到我们可以把IStyelGalleryStorage看做一个.style和.ServerStyle文件的容器,并管理这些style文件,而这些style文件内是由ISyleGalleryItem项组成的。但是IStyleGaleryStorage却没有提供管理这些Style文件内的IStyleGalleryItem的借口,所以不能管理这些IstyleGalleryItem,这个时候就出现了IStyleGallery借口,由他来管理IStyleGalleryStorage容器内所有的IstyleGalleryItem项,比如,添加、删除、更新等操作。
下面接下来讲解一下他的几个属性以及他的方法:
ClassCount 只读属性,Number of classes in the Style Gallery。StyleGallery是有IStyleGalleryItem项组成的,这些IStyleGlleryItem分别属于不同的类,并且IStyleGalery默认的将IStyleGalleryItem分为12个类,如下图所示:
每一个类都包含有若干个IStyleGaleryItem,如下图所示
上图中,ESRI.Style文件包含22个类,当前我们选中North Arrows指北针类,然后右边就显示出来North Arrow类中所包含的IStyleGalleryItem项,可以看出有很多个这样的Item。
ClassCount属性也就是返回当前的StyleGallery中所包含的类的数目。在IStyleGallery中,不管我们包含多少个IStyle文件,IStyleGallery中包含的类的种类的数量都是一定的,即22个。也就是说,每一个Style文件中包含的类的数量以及类的名称都是一样的,我们也可以这样理解,当我们创建一个.style文件的时候,系统就自动在style文件中创建22个类,尽管这个时候,每个类中的IStyleGalleryItem都为空。
Class属性,通过调用.get_Class(int index) 来返回指定索引值的IStyleGaleryClass对象,请看下面一段代码
int StyleGalleryClassCouont = styleGellery.ClassCount;
IStyleGalleryClass styleGaleryClass = null;
for (int i = ; i < StyleGalleryClassCouont; i++)
{
styleGaleryClass = styleGellery.get_Class(i);
string name = styleGaleryClass.Name;
}
关于IStyleGalleryClass 我们可以在以后讲解,这里只需要知道通过这个属性可以返回一个IStyleGaleryItem类的一个示例。
AddItem 语法如下所示:
Public void AddItem(IstyleGalleryItem item);
描述:Adds an item to the target style file.
CateGories属性
描述:The categories within the given class. 返回指定名称的Class中所包含的IStyleGallery所属的类别。
每一个IStyleGalleryClass类都包含有多个IstyleGalleryItem项,为了大体上区别这些IstyleGalleryItem项,我们又给这些IstyleGalleryItem项归类,也就是说,每一个IstyleGalleryItem都有这个Cagegories(种类、类别)这个属性。如下图所示:
)Clear 方法
语法: Public void Clear();
Discription:Removes all styles from the Style Gallery.
Items 返回满足指定参数的IstyleGalleryItems
Discription: The style items from the specified style file, in the specified class and category. The style set and category may be blank to return all items.
语法:IEnumStyleGalleryItem get_Items(string className,string styleSet,string category)
className:表示,IStyleGalleryItem所属的类
StyleSet:表示IstyleGalleryItem所存在的style文件
Category:IstyleGalleryItem 所属的类别。
参考代码:
IStyleGallery styleGellery = new StyleGalleryClass();
IStyleGalleryStorage styleGalleryStorage = styleGellery as IStyleGalleryStorage;
string tt = styleGalleryStorage.DefaultStylePath;
string iStyleFilePath = tt + "Civic.style";
styleGalleryStorage.AddFile(iStyleFilePath);
string ClassName = "Color Ramps";
string StyleCategory = "Default Ramps";
IEnumStyleGalleryItem enumStyleGalleryItem = styleGellery.get_Items(ClassName, iStyleFilePath, StyleCategory);
IStyleGalleryItem StyleGalleryItemEnum = null;
ArrayList al = new ArrayList();
while ((StyleGalleryItemEnum = enumStyleGalleryItem.Next()) != null)
{
al.Add(StyleGalleryItemEnum.Name);
}
int itemCount = al.Count;
RemoveItem
Discription: Removes an item from the target style file.
这个方法挺简单,直接调用就可以了。
SaveStyle
Discription: Saves the specified style to a file. If class is specified, only items in that class will be saved.
这里面的有一个参数:FileName不是很理解
UpdateItem
Discription: Updates an existing item in target style file.(可以看出,这里需要指定IStyleGalery的TargetFile属性,用来更新的操作也是更新这个属性指定的文件中的Item成员)
IstyleGalleryItem
Defination: Provides access to members that define items in the Style Gallery.
Product Availability:Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.
Description:Symbols and map elements are stored in the Style Gallery. Each symbol or map element has a unique ID that can be read from the item within the style gallery. A Name and Category are also properties of the items within the style gallery. These two fields, along with the Item itself, can be updated and changed as necessary.
主要方法:
Category :The category of the item.
ID: Id for the item in the Style Gallery.
Item: The symbol or map element to be stored in the Style Gallery item.
Name :The name of the item in the Style Gallery.
理解:IStyleGalleryItem项是IStyleGallery中最小的组成单元,即使是最小的单元,但是他也有她自己的属性,比如:Category、ID、Name等属性。我们也需要将IStyleGalleyItem理解成一个小的容器,因为每一个IStyleGalleryItem中都包含着一个属性Item属性,symbol或者地图都包含在这样一个IStyleGalleryItem项中。
参考代码:
IStyleGallery styleGallery = new StyleGallery();
IEnumStyleGalleryItem styleGalleryItem = (IEnumStyleGalleryItem)styleGallery;//从这一行可以看出一个IStyleGallery实例可以直接的转换为一个IEnumStyleGaleryItem对象
styleGalleryItem.Reset();
string itemName = styleGalleryItem.Next().Name;
MessageBox.Show(itemName);
注意:用AddItem、UpdateItem、RemoveItem之前,必须用到IStyleGalleryStorage接口的TargetFile属性。如果没有设置这个属性,就会报错,错误信息如下:
"对 COM 组件的调用返回了错误 HRESULT E_FAIL。" 错误代码:"-2147467259"
读取ServerStyle文件代码如下:
private string styleName = "3D Basic.ServerStyle";
public void ReadStyleServer()
{
IStyleGallery tStyleGallery = new ServerStyleGalleryClass();
IStyleGalleryStorage tStyleGalleryStorage = tStyleGallery as IStyleGalleryStorage;
tStyleGalleryStorage.AddFile(styleName);
// tStyleGalleryStorage.TargetFile = styleName_TargetFile;
IEnumStyleGalleryItem tStyleGalleryItems = tStyleGallery.get_Items("Marker Symbols", styleName, "");
tStyleGalleryItems.Reset();
IStyleGalleryItem tStyleGalleryItem = tStyleGalleryItems.Next();
int tIndex = ;
try
{
while (tStyleGalleryItem != null)
{
string tName = tStyleGalleryItem.Name;
tStyleGalleryItem.Name = tName + tIndex;
tIndex++;
tStyleGallery.UpdateItem(tStyleGalleryItem);//这个地方报错
tStyleGalleryItem = tStyleGalleryItems.Next();
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
string tErrorMessage = ex.Message +
ex.ErrorCode;
}
finally
{
//释放这个接口,不然再次读取时会报错
ReleaseCom(tStyleGalleryItems);
ReleaseCom(tStyleGallery);
}
}
private void ReleaseCom(object o)
{
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(o) > )
{
}
}
要想更新,必须用到TargetFile属性。具体为什么必须用这个,原因不明,可能是文件独占。所以只能走一个弯。思路如下:
()先把"3D Basic.ServerStyle"备份一个临时文件,备份的文件名称"Temp.ServerStyle"
()设置TargetFile,使其指向"Temp.ServerStyle"
()开始更新,更新完毕后,拷贝"Temp.ServerStyle"覆盖原来的"3D Basic.ServerStyle"
代码如下(只写数据跟新,不写文件拷贝和覆盖)
private string styleName_TargetFile = "Temp.ServerStyle";
private string styleName = "3D Basic.ServerStyle";
public void ReadStyleServer()
{
IStyleGallery tStyleGallery = new ServerStyleGalleryClass();
IStyleGalleryStorage tStyleGalleryStorage = tStyleGallery as IStyleGalleryStorage;
tStyleGalleryStorage.AddFile(styleName);
tStyleGalleryStorage.TargetFile = styleName_TargetFile;
IEnumStyleGalleryItem tStyleGalleryItems = tStyleGallery.get_Items("Marker Symbols", styleName, "");
tStyleGalleryItems.Reset();
IStyleGalleryItem tStyleGalleryItem = tStyleGalleryItems.Next();
int tIndex = ;
try
{
while (tStyleGalleryItem != null)
{
string tName = tStyleGalleryItem.Name;
tStyleGalleryItem.Name = tName + tIndex;
tIndex++;
tStyleGallery.UpdateItem(tStyleGalleryItem);
tStyleGalleryItem = tStyleGalleryItems.Next();
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
string tErrorMessage = ex.Message +
ex.ErrorCode;
}
finally
{
//释放这个接口,不然再次读取时会报错
ReleaseCom(tStyleGalleryItems);
ReleaseCom(tStyleGallery);
}
}
private void ReleaseCom(object o)
{
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(o) > )
{
}
}
不再报错,顺利运行。AddItem、RemoveItem方法类似。AddItem的时候,如果目标文件不存在,接口会自动创建目标文件。
ArcGIS Engine Style文件操作的更多相关文章
- 我的视频网站开通,第一个 ArcGIS文本文件,excel文件生成点操作发布,希望大家支持
网站地址:http://i.youku.com/gisoracle第一个学习视屏:ArcGIS文本文件,excel文件生成点操作http://v.youku.com/v_show/id_XNzM3Nz ...
- Arcgis engine 指定图层对要素进行创建、删除等操作
Arcgis engine 指定图层创建点要素 在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 .其中 和IFeatureClassWrite接口有关的代码不要好像 ...
- 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用
Dixon 原文 用ArcGIS Engine.VS .NET和Windows控件开发GIS应用 此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...
- C#,ArcGIS Engine开发入门教程
C#,ArcGIS Engine开发入门教程 转自:http://blog.csdn.net/yanleigis/article/details/2233674 目录(?)[+] 五实现 一 加载A ...
- ArcGIS Engine开发之地图基本操作(4)
ArcGIS Engine开发中数据库的加载 1.加载个人地理数据库数据 个人地理数据库(Personal Geodatabase)使用Miscrosoft Access文件(*.mdb)进行空间数据 ...
- ArcGIS Engine开发之地图基本操作(3)
地图数据的加载 一.加载Shapefile数据 Shapefile文件是目前主流的一种空间数据的文件存储方式,也是不同GIS软件进行数据格式转换常用的中间格式.加载Shapefile数据的方式有两种: ...
- ArcGIS Engine开发之地图基本操作(2)
地图数据的加载 1.加载地图文档 ArcGIS Engine支持加载多种类型的数据,有矢量数据的Coverage.Shapefile.dwg/dxf文件,栅格数据的BMP.GRID.控件数据库等.很多 ...
- ArcGIS Engine开发前基础知识(4)
ArcGIS不同开发方式的比较 关于GIS应用软件的开发,通常有三种方式:C/S架构.网络GIS和移动GIS.ArcGIS平台提供了对三种开发方式的支持,对于采用从C/S架构的大多数开发者来讲,首先想 ...
- ArcGIS Engine开发前基础知识(1)
ArcGIS二次开发是当前gis领域的一项重要必不可少的技能.下面介绍它的基本功能 一.ArcGIS Engine功能 在使用之前首先安装和部署arcgis sdk,(在这里不在赘述相关知识)可以实现 ...
随机推荐
- Javascript的作用域、作用域链以及闭包
一.javascript中的作用域 ①全局变量-函数体外部进行声明 ②局部变量-函数体内部进行声明 1)函数级作用域 javascript语言中局部变量不同于C#.Java等高级语言,在这些高级语言内 ...
- Objective-C 【多态】
------------------------------------------- 多态的概念.实现以及注意事项 程序中的多态:不同的对象 以自己的方式去 响应 相同方法名(父类同 ...
- 用 CSS 隐藏页面元素的 5 种方法
原文链接:用 CSS 隐藏页面元素的 5 种方法,转载请注明来源! 用 CSS 隐藏页面元素有许多种方法.你可以将 opacity 设为 0.将 visibility 设为 hidden.将 disp ...
- Oracle PL/SQL 找出100以内是3和5的倍数的数 循环语句
循环: loop --执行代码 exit when 表达式;--当表达式为真退出循环.(注意,其编写位置决定循环为先判断还是先执行,相当于java的while或do-while) end loop; ...
- [算法] get_lucky_price price
int get_lucky_price(int price, const vector & number) 题意大概是给你一个数price,比如1000,然后有unlucky_num,有{1, ...
- MFC GDI相关对象
首先说明几个名词: CDC 是MFC对Wind32 API的设备上下文(DC)进行封装的C++类,由他继承的类包括 CPaintDC(常用)CWindowDC(现在软件基本不用) CClientDC( ...
- Ambry: LinkedIn’s Scalable Geo-Distributed Object Store
https://github.com/linkedin/ambry http://www.open-open.com/lib/view/open1464828607502.html
- 关于不使用web服务实现文本框自动完成扩展
来博客园很久了,一直是伸手党,呵呵,现在终于申请了一个账号并开通了博客 下面分享下之前在一个项目里遇到的问题 前段时间在一个项目里要求在文本框内输入要搜索的内容,自动提示与此内容相关的词条 当时在博客 ...
- DataGridView添加另外一个控件。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; u ...
- JQ方法大全
Dom:Attribute:$("p").addClass(css中定义的样式类型); 给某个元素添加样式$("img").attr({src:"te ...