当前位置: 首页 > news >正文

江门网站制作软件重庆网站建设哪家公司哪家好

江门网站制作软件,重庆网站建设哪家公司哪家好,国际工程承包,商务酒店网站模板1、前言 很久没写ArcEngine的内容了,正好这次有同志提了一个问题:如何用ArcEngine实现批量提取面要素之间的公共边?捣鼓了半天总算是解决了,下面就来说一说解决思路。 2、ArcMap的实现方法 首先准备一份测试数据,如…

1、前言

很久没写ArcEngine的内容了,正好这次有同志提了一个问题:如何用ArcEngine实现批量提取面要素之间的公共边?捣鼓了半天总算是解决了,下面就来说一说解决思路。

2、ArcMap的实现方法

首先准备一份测试数据,如下图所示:

在这里插入图片描述

提取公共边用ArcMap做非常简单,只需要打开Analysis Tools下的Intersect相交工具,将Output Type设置为LINE,运行工具,马上就能得到面要素的公共边。如下图所示:

在这里插入图片描述

结果如下图所示:

在这里插入图片描述

3、方法一:调用GP提取公共边

既然已经知道了在ArcMap中如何使用Intersect工具来提取公共边,那么我们就可以在ArcEngine中调用GP工具来实现。不过需要注意:ArcEngine代码初始化时需要设置License的权限,代码如下:

using ESRI.ArcGIS.Geoprocessor;
using System;
using System.Windows.Forms;namespace App
{public partial class MainForm : Form{public MainForm(){InitializeComponent();}private void btn_Click(object sender, EventArgs e){// 设置参数ESRI.ArcGIS.AnalysisTools.Intersect tool = new ESRI.ArcGIS.AnalysisTools.Intersect();tool.in_features = @"C:\Users\Virtual\Desktop\data\面.shp";tool.output_type = "LINE";tool.out_feature_class = @"C:\Users\Virtual\Desktop\data\线.shp";// 执行GPGeoprocessor gp = new Geoprocessor();gp.OverwriteOutput = true;gp.Execute(tool, null);}}
}

运行结果如下图所示:

在这里插入图片描述

4、方法二:根据空间关系及拓扑工具提取公共边

获取两个面之间的公共边分以下两步:

  1. 利用IRelationalOperator判断两个Polygon是否为Touches关系?
  2. 如果是Touches关系,利用ITopologicalOperatorIntersect方法提取相交部分即可

代码如下:

using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using System;
using System.Collections.Generic;
using System.Windows.Forms;namespace App
{public partial class MainForm : Form{public MainForm(){InitializeComponent();}private void btn_Click(object sender, EventArgs e){IFeatureClass pFeatureClass = GetFeatureClass(@"C:\Users\Virtual\Desktop\data\面.shp");List<IPolygon> polygons = GetPolygonList(pFeatureClass);List<IPolyline> polylines = GetPolylineList(polygons);CreateFeatureClass(polylines, @"C:\Users\Virtual\Desktop\data\线.shp");}// 获取要素类private IFeatureClass GetFeatureClass(string filePath){IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();IWorkspaceFactoryLockControl pWorkspaceFactoryLockControl = pWorkspaceFactory as IWorkspaceFactoryLockControl;if (pWorkspaceFactoryLockControl.SchemaLockingEnabled){pWorkspaceFactoryLockControl.DisableSchemaLocking();}IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(filePath), 0);IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileName(filePath));return pFeatureClass;}// 获取Polygon集合private List<IPolygon> GetPolygonList(IFeatureClass pFeatureClass){IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, true);IFeature pFeature = pFeatureCursor.NextFeature();if (pFeature == null){return null;}// 遍历游标List<IPolygon> list = new List<IPolygon>();while (pFeature != null){list.Add(pFeature.ShapeCopy as IPolygon);pFeature = pFeatureCursor.NextFeature();}// 返回System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);return list;}// 获取Polyline集合private List<IPolyline> GetPolylineList(List<IPolygon> polygons){List<IPolyline> list = new List<IPolyline>();for (int i = 0; i < polygons.Count; i++){for (int j = 0; j < polygons.Count; j++){if (i == j){continue;}IRelationalOperator pRelationalOperator = polygons[i] as IRelationalOperator;if (pRelationalOperator.Touches(polygons[j])){ITopologicalOperator pTopologicalOperator = polygons[i] as ITopologicalOperator;IGeometry pIntersectGeometry = pTopologicalOperator.Intersect(polygons[j], esriGeometryDimension.esriGeometry1Dimension);list.Add(pIntersectGeometry as IPolyline);}}}return list;}// 创建要素类private IFeatureClass CreateFeatureClass(List<IPolyline> polylines, string filePath){// 设置空间参考IGeometryDef pGeometryDef = new GeometryDef();IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;pGeometryDefEdit.HasM_2 = false;pGeometryDefEdit.HasZ_2 = false;pGeometryDefEdit.SpatialReference_2 = axMapControl1.SpatialReference;// 字段集合IFields pFields = new Fields();IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;// ShapeIField pField = new Field();IFieldEdit pFieldEdit = pField as IFieldEdit;pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;pFieldEdit.GeometryDef_2 = pGeometryDef;pFieldEdit.AliasName_2 = "Shape";pFieldEdit.Name_2 = "Shape";pFieldEdit.IsNullable_2 = false;pFieldEdit.Required_2 = true;pFieldsEdit.AddField(pField);// 创建要素类IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(filePath), 0);IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;IFeatureClass pFeatureClass = pFeatureWorkspace.CreateFeatureClass(System.IO.Path.GetFileName(filePath), pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");// 要素游标IFeatureBuffer pFeatureBuffer = pFeatureClass.CreateFeatureBuffer();IFeatureCursor pFeatureCursor = pFeatureClass.Insert(true);for (int i = 0; i < polylines.Count; i++){pFeatureBuffer.Shape = polylines[i];pFeatureCursor.InsertFeature(pFeatureBuffer);}pFeatureCursor.Flush();// 返回System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureBuffer);System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);return pFeatureClass;}}
}

运行结果如下图所示:

在这里插入图片描述

5、结语

本文主要介绍了ArcEngine中提取公共边的实现方法。其实对于第二种方法,即:利用空间关系和拓扑工具提取公共边,我个人是不太满意的,因为这是纯粹的暴力解法,数据量一旦较多,效率肯定是个大问题。可惜不知道ESRI是怎么实现的,有了解的同志也可以讲讲这个问题最优的解决方法是什么。

http://www.sczhlp.com/news/122267/

相关文章:

  • 盐城营销网站建设凡客做网站
  • 一类特征方程在数列递推中的应用
  • 海南省工程建设定额网站口碑好的常州网站优化
  • 17858833595做网站iis7 部署网站
  • 网站的开发流程有哪几个阶段大连建设工程招聘信息网站
  • 商务网站建设的可行性分析包括做外贸哪个网站好
  • 公司主营业务网站建设长春百度搜索排名优化
  • 做购物网站 国外服务器wordpress最多支持多少会员
  • 织梦汽车网站模板南京市建设厅网站
  • 长春个人做网站哪家好网站互动化
  • wordpress如何在地址栏中加网站logowordpress主题跟目录
  • rust跨文件调用代码
  • 济南网站建设公司熊掌号长沙建站公司
  • 专业营销型网站定制陕西网站建设电话
  • 手机网站 微信支付网站幻灯片 按纽
  • 直播网站做收入流水耳机商城网站开发
  • 详细介绍:导师推荐毕设:基于SpringBoot+Vue的中小企业进销存管理系统设计
  • 厦门市建设工程质监站网站怎么清除网站
  • 做网站费是多少建设网站程序
  • 做电影网站被抓king cms网站建设
  • 备案 修改网站名称建设微网站需要多少钱
  • 做试管的网站企业年金离职的时候怎么办
  • 创业网站怎么做的wordpress 获取当前域名
  • 网站建设 如何友情链接wordpress游戏插件
  • 平湖网站制作wordpress做的企业官网
  • 弹窗视频网站上海机械网站建设
  • 网站开发岗位seo基础知识培训视频
  • NIO重构UDP收发模块
  • 广州专门做网站东莞做微网站建设价格
  • 毕业设计商城网站开发淮阳住房和城乡建设局网站