找个输入IPoint在某个FeatureClass上距离最近的要素
2024-10-08 07:27:41
/// <summary>
/// 得到输入点在输入图层上的最近点
/// </summary>
/// <param name="randomPoints">输入的点,注意小数位数不能太长,具体支持多长没有测试,我用小数点2位可以成功,但是七八位肯定不行</param>
/// <param name="feaPoints">输出在featureclass上距离最近的要素,这里是点类型输出的是点</param>
/// <param name="length">输入点到featureclass上最近点的距离</param>
/// <returns></returns>
public bool NearestPoint(IPoint[] randomPoints, out IPoint[] feaPoints, out double length)
{
feaPoints = new IPoint[randomPoints.Length];
length = ;
try
{
fd = (LinkReady.ReadPipeLineWorkspace() as IFeatureWorkspace).OpenFeatureDataset(LY.UG.Common.DictionaryConfig.DatasetName["道路网络数据集名称"]);//("SDE.地下管线");
nc = fd as INetworkCollection;
IFeatureClass feaRoadJunction = (fd as IFeatureClassContainer).get_ClassByName(LY.UG.Common.DictionaryConfig.DatasetName["道路网络点图层"]); int[] feaID = new int[randomPoints.Length];
double[] feaDis = new double[randomPoints.Length];
IFeatureIndex pFeatureIndex = new FeatureIndex();
IIndexQuery pIndexQuery;
IGeoDataset geodataset = (IGeoDataset)feaRoadJunction; ITrackCancel trackCancel = new TrackCancel();
pFeatureIndex.FeatureClass = feaRoadJunction;//.setFeatureClassByRef(pFeatureClass1); pFeatureIndex.Index(trackCancel, geodataset.Extent);
pIndexQuery = pFeatureIndex as IIndexQuery;
for (int i = ; i < randomPoints.Length; i++)
{
pIndexQuery.NearestFeature(randomPoints.GetValue(i) as IPoint, out feaID[i], out feaDis[i]);
feaPoints[i] = new PointClass();
feaPoints[i] = feaRoadJunction.GetFeature(feaID[i]).ShapeCopy as IPoint;
length = length + feaDis[i];
} return true;
}
catch (Exception ee)
{
return false;
}
}
最新文章
- linux安装php
- 浅谈RSA加密算法
- [笔记]--Python字符串处理
- 可接受多个值的文件上传字段HTML5新特性
- Java语言编写计算器(简单的计算器)
- Android中对闹钟Alarm的事件处理
- 将前台input中的数据异步传到后台并存入数据库
- Django:同一个app支持多个数据库
- rem 自适应适配方法
- F3D模式规则详解
- 机器学习之决策树_CART算法
- 常见Chrome 插件
- echart图表
- SpringAOP基础 - 静态代理设计模式
- 要使用C#实现一个ActiveX控件
- C#中DllImport用法汇总
- shell统计各省的百强县
- java NIO(转载)
- 美团Java实习面试经历(拿到Offer)
- Qt 使用irrlicht(鬼火)3D引擎