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服务,分为同步和异步两种类型,一般执行步骤较 ...
随机推荐
- webpack中的图片打包之路
最近在Github上弄项目,需要搭建一个webpack开发环境.Emmm,是的,从0开始搭建一个项目确实不容易,光Webpack的坑就够我踩一路的了.这不,刚搭建到“图片打包”这里,就遇到了麻烦.最后 ...
- AI-IBM-cognitive class --Liner Regression
Liner Regression import matplotlib.pyplot as plt import pandas as pd import pylab as pl import numpy ...
- socket - Linux 套接字
总览 #include <sys/socket.h> mysocket = socket(int socket_family, int socket_type, int protocol) ...
- spring boot 不连接数据库启动
Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on th ...
- 二、jquery Try{}catch(e){}
一.Try{}catch(e){} try{ $.each($("div"),function(i,item){ if(...){ throw("异常信息"); ...
- MySQL-触发案列
1.更新案例 DELIMITER $$ USE `haochacang`$$ DROP TRIGGER /*!50032 IF EXISTS */ `customer_info_update`$$ C ...
- tensorflow函数介绍(2)
参考:tensorflow书 1.模型的导出: import tensorflow as tf v1=tf.Variable(tf.constant(2.0),name="v1") ...
- 使用idea搭建Spring boot+jsp的简单web项目
大家好: 这是我的第一篇博客文章,简单介绍一下Spring boot + jsp 的搭建流程,希望给跟我一样新接触Spring boot的读者一点儿启发. 开发工具:jdk1.8 idea2017 ...
- hdu 5120 Intersection (圆环面积相交->圆面积相交)
Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made up by ...
- 2018-2019 2 20165203 《网络对抗技术》Exp9 Web安全基础
2018-2019 2 20165203 <网络对抗技术>Exp9 Web安全基础 实验要求 本实践的目标理解常用网络攻击技术的基本原理,做不少于7个题目,共3.5分.包括(SQL,XSS ...