ArcEngine 创建线要素图层
在创建要素图层的时候,默认的几何类型是Polygon:
Dim objectClassDescription As IObjectClassDescription = New FeatureClassDescription
Dim fields2 As Fields = objectClassDescription.RequiredFields
代码来源:http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//0049000000pz000000
上面代码的fields2包含2个字段,一个OBJECTID字段和一个SHAPE字段,而SHAPE字段决定了要素的几何类型(GeometryType),这个是环境自己生成,他的几何类型是Polygon。
如果想生成其他的几何类型的要素图层就要自己手动创建这两个字段,并在SHAPE添加几何类型的信息,下面图层的要素类型为Polyline。如下代码(VB)所示:
Dim featureClassName As String = "图层名称" '临时图层名称
Dim workspaceFactory As IWorkspaceFactory = New InMemoryWorkspaceFactory() '内存空间
Dim WorkspaceName As IWorkspaceName = workspaceFactory.Create("", "MyWorkspace", Nothing, )
Dim name As IName = WorkspaceName
Dim workspace As IWorkspace = name.Open()
Dim featureWorkspace As IFeatureWorkspace = workspace 'Dim workspace2 As IWorkspace2 = workspace
Dim fields As IFields = Nothing
Dim CLSID As ESRI.ArcGIS.esriSystem.UID = Nothing
Dim CLSEXT As ESRI.ArcGIS.esriSystem.UID = Nothing
Dim strConfigKeyword As String = ""
Dim featureClass As IFeatureClass
' 赋值类ID如果未分配
If CLSID Is Nothing Then
CLSID = New ESRI.ArcGIS.esriSystem.UID
CLSID.Value = "esriGeoDatabase.Feature"
End If
'环境默认生成的两个字段,字段的几何类型为Polygon,决定了要素图层的集合类型
'Dim objectClassDescription As IObjectClassDescription = New FeatureClassDescription
'Dim fields2 As Fields = objectClassDescription.RequiredFields
If fields Is Nothing Then
' 创建要素几何信息
Dim pGeometryDef As IGeometryDef = New GeometryDef() ' 为esriFieldTypeGeometry类型的字段创建几何定义,包括类型和空间参照
Dim pGeometryDefEdit As IGeometryDefEdit = pGeometryDef
pGeometryDefEdit.GridCount_2 =
pGeometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline '决定要素图层的几何类型
pGeometryDefEdit.SpatialReference_2 = pMap.SpatialReference '必须设置图层的空间参考系 fields = New Fields
Dim fieldsEdit As IFieldsEdit = CType(fields, IFieldsEdit)
'自己创建OBJECTID字段
Dim fieldOID As IField = New Field()
Dim fieldEditOID As IFieldEdit = CType(fieldOID, IFieldEdit)
fieldEditOID.Name_2 = "OBJECTID"
fieldEditOID.AliasName_2 = "OBJECTID"
fieldEditOID.Type_2 = esriFieldType.esriFieldTypeOID
fieldEditOID.Editable_2 = False
fieldsEdit.AddField(fieldOID) '自己创建几何字段,
Dim fieldShape As IField = New Field()
Dim fieldEditShape As IFieldEdit = CType(fieldShape, IFieldEdit)
fieldEditShape.Name_2 = "SHAPE"
fieldEditShape.AliasName_2 = "SHAPE"
fieldEditShape.Type_2 = esriFieldType.esriFieldTypeGeometry
fieldEditShape.GeometryDef_2 = pGeometryDef
fieldEditShape.Editable_2 = True
fieldsEdit.AddField(fieldShape) Dim field As IField = New Field
Dim fieldEdit As IFieldEdit = CType(field, IFieldEdit) ' 显示转换
' 设置字段属性
fieldEdit.Name_2 = "RISK"
fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble
fieldEdit.IsNullable_2 = False
fieldEdit.AliasName_2 = "RISK"
fieldEdit.DefaultValue_2 =
fieldEdit.Editable_2 = True
fieldsEdit.AddField(field)
Dim field2 As IField = New Field
Dim fieldEdit2 As IFieldEdit = CType(field2, IFieldEdit) ' 显示转换
' 设置字段属性
fieldEdit2.Name_2 = "管线ObjId"
fieldEdit2.Type_2 = esriFieldType.esriFieldTypeInteger
fieldEdit2.IsNullable_2 = False
fieldEdit2.AliasName_2 = "管线ObjId"
fieldEdit2.DefaultValue_2 =
fieldEdit2.Editable_2 = True
'添加到字段集中
fieldsEdit.AddField(field2)
fields = CType(fieldsEdit, IFields)
End If
Dim strShapeField As String = ""
Dim j As Int32
For j = To fields.FieldCount
If fields.Field(j).Type = esriFieldType.esriFieldTypeGeometry Then
strShapeField = fields.Field(j).Name
'fields.Field(j).GeometryDef.GeometryType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline
Exit For
End If
Next j
Dim fieldChecker As IFieldChecker = New FieldChecker
Dim enumFieldError As IEnumFieldError = Nothing
Dim validatedFields As IFields = Nothing
fieldChecker.ValidateWorkspace = workspace
fieldChecker.Validate(fields, enumFieldError, validatedFields)
featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword)
C#
/// <summary>
/// 创建点要素图层,内存图层
/// </summary>
/// <param name="featureClassName">图层名称</param>
/// <returns>要素图层</returns>
private IFeatureClass CreateFeatureClass(string featureClassName)
{
IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactory();//内存空间
IWorkspaceName WorkspaceName = workspaceFactory.Create("", "MyWorkspace", null, );
IName name = WorkspaceName as IName;
IWorkspace workspace = name.Open();
IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace; IFields fields=null;
ESRI.ArcGIS.esriSystem.UID CLSID= null;
ESRI.ArcGIS.esriSystem.UID CLSEXT=null;
String strConfigKeyword = "";
IFeatureClass featureClass;
//赋值类ID如果未分配
if( CLSID==null){
CLSID = new ESRI.ArcGIS.esriSystem.UID();
CLSID.Value = "esriGeoDatabase.Feature";
}
//环境默认生成的两个字段,字段的几何类型为Polygon,决定了要素图层的集合类型
//Dim objectClassDescription As IObjectClassDescription = New FeatureClassDescription
//Dim fields2 As Fields = objectClassDescription.RequiredFields
if( fields==null)
{
//创建要素几何信息
IGeometryDef pGeometryDef = new GeometryDef();//为esriFieldTypeGeometry类型的字段创建几何定义,包括类型和空间参照
IGeometryDefEdit pGeometryDefEdit=pGeometryDef as IGeometryDefEdit;
pGeometryDefEdit.GridCount_2 = ;
pGeometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint; //决定要素图层的几何类型
pGeometryDefEdit.SpatialReference_2 = axSceneControl1.Scene.SpatialReference;//必须设置图层的空间参考系
fields = new Fields();
IFieldsEdit fieldsEdit =fields as IFieldsEdit;
//自己创建OBJECTID字段
IField fieldOID = new Field();
IFieldEdit fieldEditOID =fieldOID as IFieldEdit;
fieldEditOID.Name_2 = "OBJECTID";
fieldEditOID.AliasName_2 = "OBJECTID";
fieldEditOID.Type_2 = esriFieldType.esriFieldTypeOID;
fieldEditOID.Editable_2 = false;
fieldsEdit.AddField(fieldOID); //自己创建几何字段,
IField fieldShape = new Field();
IFieldEdit fieldEditShape = fieldShape as IFieldEdit;
fieldEditShape.Name_2 = "SHAPE";
fieldEditShape.AliasName_2 = "SHAPE";
fieldEditShape.Type_2 = esriFieldType.esriFieldTypeGeometry;
fieldEditShape.GeometryDef_2 = pGeometryDef;
fieldEditShape.Editable_2 = true;
fieldsEdit.AddField(fieldShape); IField field = new Field();
IFieldEdit fieldEdit =field as IFieldEdit;// 显示转换
//设置字段属性
fieldEdit.Name_2 = "RISK";
fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
fieldEdit.IsNullable_2 = false;
fieldEdit.AliasName_2 = "RISK";
fieldEdit.DefaultValue_2 = ;
fieldEdit.Editable_2 = true;
fieldsEdit.AddField(field);
IField field2 = new Field();
IFieldEdit fieldEdit2=field2 as IFieldEdit; // 显示转换
//设置字段属性
fieldEdit2.Name_2 = "管线ObjId";
fieldEdit2.Type_2 = esriFieldType.esriFieldTypeInteger;
fieldEdit2.IsNullable_2 = false;
fieldEdit2.AliasName_2 = "管线ObjId";
fieldEdit2.DefaultValue_2 = ;
fieldEdit2.Editable_2 = true;
//添加到字段集中
fieldsEdit.AddField(field2);
fields =fieldsEdit as IFields;
}
String strShapeField = "";
for (int j = ; j < fields.FieldCount; j++)
{
if(fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
{
strShapeField =fields.get_Field(j).Name;
}
}
IFieldChecker fieldChecker =new FieldChecker();
IEnumFieldError enumFieldError =null;
IFields validatedFields =null;
fieldChecker.ValidateWorkspace = workspace;
fieldChecker.Validate(fields,out enumFieldError, out validatedFields);
featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword)
return featureClass;
}
打开内存空间(C#)
IRasterLayer pRasterLayer = new RasterLayerClass();
IWorkspaceFactory workspaceFactory2 = new InMemoryWorkspaceFactory();
IRasterWorkspace2 workspace = (IRasterWorkspace2)workspaceFactory2.OpenFromFile("MyWorkspace", );
PS:不同线程不能打开同一个工作空间。
ArcEngine 创建线要素图层的更多相关文章
- ArcEngine环境下合并断开的线要素(根据属性)
1.遇到的问题: 最近遇到在线要素(矢量数据)中,一条完整的道路.河流等往往是断开的,如下图1所示: 2.思路: 在ArcGIS Desktop中没有相关的工具可以将这些断开的线要素进行自动合并,今天 ...
- ArcEngine中合并断开的线要素(根据几何判断)
在上一篇ArcEngine环境下合并断开的线要素(根据属性)随笔中介绍了如何通过shp文件属性表中相同的属性字段进行线要素的合并.今天刚把通过几何条件判断的方式连接断开的线要素的ArcGIS 插件完成 ...
- C# ArcEngine创建内存图层(转载)
C#+Arcengine---创建内存图层 分类:技术文档 2009-12-11 14:43阅读(1498)评论(0) #region 在内存中创建图层 /// <summary& ...
- ArcGIS Server 10.2 实战(一)Asp.net MVC与JSON数据妙用实现动态生成要素图层
今年7月刚刚发布的ArcGIS 10.2为GIS的web开发带来了一个很实在的功能,JSON转要素.以往GIS图层外部数据(如文本数据,数据库数据)动态地写入地图服务中的图层是一件不可想象的事情,如今 ...
- 用IFeatureWorkspaceAnno.CreateAnnotationClass 创建注记图层时报“The application is not licensed to modify or create schema”的错误的解决方案。
用IFeatureWorkspaceAnno.CreateAnnotationClass 的方法创建注记图层的时候报"The application is not licensed to m ...
- ArcGIS 网络分析[1.4] 制作点线要素时需要注意的地方
有很多同学虽然成功做好了网络数据集,但是分析时会出现这样的问题: 这是为什么呢? 这有三个可能的原因: 1. 两个点之间所有的道路没有连通(问题出在点.线数据上). 2. 网络数据集出现了孤立的点位置 ...
- 在ArcMap中发布FeatureLayer(要素图层)
FeatureLayer(要素图层)是ArcGIS Server发布的一种很重要的地图服务,发布后使用提供的url地址就可以在代码中调用并在地图上显示.编辑这个FeatureLayer.在HTML页面 ...
- 转:ArcGIS API For JavaScript官方文档(二十)之图形和要素图层——①Graphics概述
原文地址:ArcGIS API For JavaScript官方文档(二十)之图形和要素图层——①Graphics概述 ArcGIS JavaScript API允许在地图上绘制graphic(图形) ...
- ArcGIS Desktop和Engine中对点要素图层Graduated Symbols渲染的实现 Rotation Symbol (转)
摘要 ArcGIS中,对于要素图层的渲染,支持按照要素字段的值渲染要素的大小,其中Graduated Symbols可以对大小进行分级渲染.在个人开发系统的过程中,也可以用来美化数据显 ...
随机推荐
- 2018-9-28-WPF-自定义-TextBoxView-的-Margin-大小
title author date CreateTime categories WPF 自定义 TextBoxView 的 Margin 大小 lindexi 2018-09-28 17:16:17 ...
- Python--day72--ajax简介
ajax的基本结构: <script> $("#b1").on("click", function () { $.ajax({ url: " ...
- JavaMail转发邮件
最近要做一个邮件转发功能,看了好多blog,都是接受邮件,再解析邮件内容,再组装成新的邮件发出! 我按照这个不够,不错!邮件发出去了.但是好麻烦啊,接受邮件是个Message,发送邮件也是个Messa ...
- SpringSecurity登录原理(源码级讲解)
一.简单叙述 首先会进入UsernamePasswordAuthenticationFilter并且设置权限为null和是否授权为false,然后进入ProviderManager查找支持Userna ...
- @ENABLEWEBSECURITY和@ENABLEWEBMVCSECURITY有什么区别?
@EnableWebSecurity和@EnableWebMvcSecurity有什么区别? @EnableWebSecurity JavaDoc文档: 将此注释添加到@Configuration类中 ...
- Educational Codeforces Round 54 (Rated for Div. 2) D Edge Deletion (SPFA + bfs)
题目大意:给定你一个包含n个点m条边的无向图,现在最多在图中保留k条边,问怎么删除多的边,使得图中良好的节点数最多,求出保留在图中的边的数量和编号. 良好的节点定义为:删除某条边后该点到点1的最短距离 ...
- P1025 最大完美度
题目描述 定义一个字符串的完美度为字符串中所有字符的完美度的和. 现在给你一个只含字母的字符串s, 每一个字母的完美度由你进行分配, 可以分配给一个字母[1,26]中的一个数字作为完美度, 但每个字母 ...
- P1009 字符三角形
题目描述 输入一个字符c,按照阳历输出的格式输出由该字符组成的一个字符三角形. 输入格式 输入包含一个字符c. 输出格式 输出由该字符c组成的字符三角形. 样例输入 A 样例输出 A AAA AAAA ...
- H3C 示例:计算子网地址
- flex布局属性说明
flex布局又称为盒子布局或弹性布局,用来为盒状模型提供最大的灵活性,任何一个容器都可以指定为 Flex 布局. 给父容器添加display: flex/inline-flex;属性,即可使容器内容采 ...