获取离点最近的线要素
输入点要素feature和 和 线要素的集合IFeatureClass ,返回一个feature_line。
public IFeature get_nearst_feature(IFeature feature_point,IFeatureClass featureclass_line)
{
_point = feature_point.Shape as IPoint;
IFeatureIndex2 pFeatureIndex = new FeatureIndexClass();
pFeatureIndex.FeatureClass = featureclass_line;//这里应该是要查询的线要素类
ITrackCancel trackCancel = new TrackCancelClass();
pFeatureIndex.Index(trackCancel, (featureclass_line as IGeoDataset).Extent);
IIndexQuery2 pIndexQuery2 = (IIndexQuery2)pFeatureIndex;
int pClosestFeatureFID;
double pDistance;
pIndexQuery2.NearestFeature(feature_point.Shape, out pClosestFeatureFID, out pDistance);//输入点 进行遍历
if (pClosestFeatureFID < 0)
{
return null;
}
IFeature feature_line = featureclass_line.GetFeature(pClosestFeatureFID);
return feature_line;
}
转载自:https://blog.csdn.net/qq_33222460/article/details/79639015