ArcGIS 面要素缝隙孔洞检查代码 C# GP
public class PolygonGapChecker : CheckProgressMessageSender, IChecker, ICheckProgressChangeEvent
{
private IFeatureLayer featureLayer;
/// <summary>
/// 待检查的面要素类图层
/// </summary>
public IFeatureLayer FeatureLayer
{
set
{
if (value != null)
{
if (value.FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
featureLayer = value;
else
throw new ArgumentException("要素类不是期望的类型,应是面要素类。");
}
else
throw new ArgumentException("要素类对象传入的是null");
}
} private int featureCount = -;
/// <summary>
/// 受检要素类的要素个数
/// </summary>
public int FeatureCount { get { return featureCount; } } //private double distance = 0.2;
/// <summary>
/// 距离值,一个大于零的值
/// </summary>
public double Distance { set { } } private double tolerance = 0.001;
/// <summary>
/// 容差值,一个大于零的值
/// </summary>
public double Tolerance { set {
if (value <= )
throw new ArgumentException("容差应是一个大于0的小数。");
else
tolerance = value;
}
} //private double angle = 10.0;
/// <summary>
/// 角度值,一个大于零的值
/// </summary>
public double Angle { set { } } private string workspacePath = string.Empty;
/// <summary>
/// FGDB或文件夹的路径
/// </summary>
public string WorkspacePath
{
set
{
if (System.IO.Directory.Exists(value))
workspacePath = value;
else
throw new ArgumentException("给定FGDB或文件夹的路径不存在!");
}
} private readonly CheckerType checkerType = CheckerType.面缝隙或孔洞;
/// <summary>
/// 检查类型
/// </summary>
public CheckerType CheckerType { get { return checkerType; } } /// <summary>
/// 检查方法
/// </summary>
/// <returns>检查结果要素类</returns>
public IFeatureClass Check()
{ IFeatureClass featureClass_cover;
//IFeatureClass featureClass_erase;
//IFeatureClass featureClass_erase_explode;
IFeatureClass featureClass_result;
IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
string featureClass_cover_Name=featureLayer.Name+"_cover.shp";
string featureClass_erase_Name = $"{workspacePath}\\{featureLayer.Name}_erase.shp";
string featureClass_result_Name = $"{workspacePath}\\{featureLayer.Name}_gap.shp";
if (workspacePath.Split('.').Last().ToLower() == "gdb")
{
//确定要素类的名称,如workspace是文件地理数据库那么要素类名字最后没有有.shp。
featureClass_cover_Name= featureClass_cover_Name.Replace(".shp", "");
featureClass_erase_Name=featureClass_erase_Name.Replace(".shp", "");
featureClass_result_Name=featureClass_result_Name.Replace(".shp", "");
//若是文件地理数据库,应实例化FileGDBWorkspaceFactoryClass对象。
workspaceFactory = new FileGDBWorkspaceFactoryClass();
}
IFeatureWorkspace featureWorkspace = workspaceFactory.OpenFromFile(workspacePath, ) as IFeatureWorkspace; #region 创建Cover要素类,用于被擦除
FeatureClassCreator featureClassCreator = new FeatureClassCreator(featureLayer, featureClass_cover_Name, esriGeometryType.esriGeometryPolygon, workspacePath);
featureClass_cover = featureClassCreator.Create();
OnCheckProgresChange(checkProgressChangeEventHandler, ">>>成功创建Cover。");
IPolygon polygon_cover = new PolygonClass();
IPoint pointUpperLeft = new PointClass { X = (featureLayer.FeatureClass as IGeoDataset).Extent.UpperLeft.X - , Y = (featureLayer.FeatureClass as IGeoDataset).Extent.UpperLeft.Y- };
IPoint pointUpperRight = new PointClass { X = (featureLayer.FeatureClass as IGeoDataset).Extent.UpperRight.X + , Y = (featureLayer.FeatureClass as IGeoDataset).Extent.UpperRight.Y- };
IPoint pointLowerRight = new PointClass { X = (featureLayer.FeatureClass as IGeoDataset).Extent.LowerRight.X + , Y = (featureLayer.FeatureClass as IGeoDataset).Extent.LowerRight.Y+ };
IPoint pointLowerLeft = new PointClass { X = (featureLayer.FeatureClass as IGeoDataset).Extent.LowerLeft.X - , Y = (featureLayer.FeatureClass as IGeoDataset).Extent.LowerLeft.Y+ };
IPointCollection pointCollection_cover = polygon_cover as IPointCollection;
pointCollection_cover.AddPoint(pointUpperLeft);
pointCollection_cover.AddPoint(pointUpperRight);
pointCollection_cover.AddPoint(pointLowerRight);
pointCollection_cover.AddPoint(pointLowerLeft);
pointCollection_cover.AddPoint(pointUpperLeft);
IFeature feature_cover= featureClass_cover.CreateFeature();
feature_cover.Shape = polygon_cover;
feature_cover.Store();
OnCheckProgresChange(checkProgressChangeEventHandler, ">>>成功创建Cover要素,准备执行Erase。");
#endregion Geoprocessor.Geoprocessor gp = new Geoprocessor.Geoprocessor
{
AddOutputsToMap = false,
OverwriteOutput = true
};
Erase erase = new Erase
{
in_features = $"{workspacePath}\\{featureClass_cover_Name}",
erase_features = featureLayer,
out_feature_class = featureClass_erase_Name,
cluster_tolerance = this.tolerance,
};
gp.Execute(erase, null);
OnCheckProgresChange(checkProgressChangeEventHandler, ">>>成功创建Erase,准备执行Explode。");
MultipartToSinglepart multipartToSinglepart = new MultipartToSinglepart
{
in_features = featureClass_erase_Name,
out_feature_class = featureClass_result_Name
};
gp.Execute(multipartToSinglepart, null); featureClass_result = featureWorkspace.OpenFeatureClass(featureClass_result_Name.Replace($"{workspacePath}\\", ""));
CheckAuxiliaryHelper.SpatialSearchAndDeleteFeatures(featureClass_result, pointUpperLeft, esriSpatialRelEnum.esriSpatialRelIntersects);
featureClass_result.DeleteField(featureClass_result.Fields.Field[featureClass_result.FindField("ORIG_FID")]);
CheckAuxiliaryHelper.DeleteFeatureClass(featureClass_cover_Name, featureWorkspace);
CheckAuxiliaryHelper.DeleteFeatureClass(featureClass_erase_Name, featureWorkspace);
return featureClass_result;
}
private CheckProgressChangeEventHandler checkProgressChangeEventHandler;
/// <summary>
/// 进度改变事件
/// </summary>
public event CheckProgressChangeEventHandler CheckProgressChangeEvent
{
add
{
this.checkProgressChangeEventHandler += value;
} remove
{
this.checkProgressChangeEventHandler-=value;
}
} }


ArcGIS 面要素缝隙孔洞检查代码 C# GP的更多相关文章
- ESLint 检查代码质量
利用 ESLint 检查代码质量 其实很早的时候就想尝试 ESLint 了,但是很多次都是玩了一下就觉得这东西巨复杂,一执行检查就是满屏的error,简直是不堪入目,遂放弃.直到某天终于下定决心深入看 ...
- C#编译器怎么检查代码是否会执行
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:C#编译器怎么检查代码是否会执行.
- 利用ESLint检查代码质量
1. ESLint ESLint 是一个插件化的 javascript 代码检测工具,它可以用于检查常见的 JavaScript 代码错误,也可以进行代码风格检查,这样我们就可以根据自己的喜好指定一套 ...
- 将位图导入为ArcGIS面要素
本文根据笔者经验,介绍一种从位图图像导入ArcGIS称为要素的方法.这种方法适用于从现有出版物图片中获取地理信息的情况. 首先要说明的是,从位图导入要素是非常非常不精确的方式,如果有其它数据来源,那么 ...
- 在IDEA中停止和关闭SonarLint自动检查,手动运行SonarLint检查代码
关闭SonarLint自动检查代码 有时敲一行代码SonarLint插件就会自动检查,让人感觉很不舒服,还会使电脑卡顿: 依次点击:File -> Settings 或直接Ctrl+Alt+S ...
- android 中的一些资源注解,让编译器帮你检查代码
android 中的一些资源注解,让编译器帮你检查代码 写方便的时候可以用注解来声明一些参数,以明确的指示参数的类型,让代码更安全.我们看到,在android源代码里大量使用了注解.我整理了一些注解如 ...
- 使用eslint检查代码质量
1.安装 全局安装 npm install eslint -g 局部安装 npm install eslint --save 2.初始化一个配置文件 eslint --init 执行后根据项目需要回答 ...
- 项目git commit时卡主不良代码:husky让Git检查代码规范化工作
看完 <前端规范之Git工作流规范(Husky + Commitlint + Lint-staged) https://www.cnblogs.com/Yellow-ice/p/15349873 ...
- ArcGIS Runtime SDK for Android开发之调用GP服务(异步调用)
一.背景说明 通过调用GP服务,Android客户端也能实现专业的.复杂的GIS分析处理功能,从而增加应用的实用价值. ArcGIS Server发布的GP服务,分为同步和异步两种类型,一般执行步骤较 ...
随机推荐
- npm run dev 报错:Error: Cannot find module 'webpack-cli/bin/config-yargs'
使用 npm run dev 时报错: Error: Cannot find module 'webpack-cli/bin/config-yargs' 原因是找不到webpack-cli这个包,使用 ...
- 使用EntityFramework调用存储过程并获取存储过程返回的结果集
[实习]刚入职,公司要求完成两个任务,任务要求使用存储过程和事务,其中一个问题要获取存储过程的查询结果集.经过多方查找和自己的实践,终于找到了方法.这里记录一下. 看到的这篇文章中给出的例子是查询单个 ...
- Codeforces Round #393 (Div. 2) - B
题目链接:http://codeforces.com/contest/760/problem/B 题意:给定n张床,m个枕头,然后给定某个特定的人(n个人中的其中一个)他睡第k张床,问这个人最多可以拿 ...
- ltp-ddt realtime_cpu_load涉及的cyclictest 交叉编译
Cyclictest 是 rt-tests 下的一个测试工具,也是rt-tests 下使用最广泛的测试工具,一般主要用来测试使用内核的延迟,从而判断内核的实时性. 1.下载源码 git clone ...
- solrJ 基本使用
添加: PropertiesUtils pro = new PropertiesUtils();String path = pro.load("solr.properties", ...
- 【串线篇】Mybatis缓存简介
缓存:暂时的存储一些数据:加快系统的查询速度... CPU: 主频:4-2.7GHZ 内存:4G-8G 1333MHZ 2166MHZ CPU:一级缓存(4MB):二级缓存 (16MB); ...
- class反编译
JD-GUI:http://java-decompiler.github.io/ 离线包在我的文件 下载安装,file选择class文件即可浏览 反编译代码与源码去掉注释后的代码比较接近,虽然比源码损 ...
- angular 组件通信
单页面应用组件通信有以下几种,这篇文章主要讲 Angular 通信 父组件 => 子组件 子组件 => 父组件 组件A = > 组件B 父组件 => 子组件 子组件 => ...
- 您的加密USB驱动器是否安全?黑客又是如何攻破的?
您如何确定您使用的“安全”USB驱动器是否真的安全,并且您存储的数据无法提取?这正是Google公司和中国网络安全研究人员在最近的2018年黑帽美国大会上以艰难的方式攻击加密的USB密钥”的问题. 研 ...
- hive之视图和索引
一.视图 1.视图定义 视图其实是一个虚表,视图可以允许保存一个查询,并像对待表一样对这个查询进行操作,视图是一个逻辑结构,并不会存储数据. 2.视图的创建 通过创建视图来限制数据访问可以用来保护信息 ...