arcgis engine道路接边代码
时间: 2023-09-18 14:16:22 浏览: 85
以下是 ArcGIS Engine 中道路接边的示例代码:
```c#
private void OnCreateNewLine(IEngineEditor editor, IGeometry geometry)
{
//获取当前编辑图层的FeatureClass
IFeatureClass featureClass = editor.TargetLayer.FeatureClass;
//创建新的Feature
IFeature newFeature = featureClass.CreateFeature();
//设置新Feature的形状
newFeature.Shape = geometry;
//设置新Feature的属性
newFeature.set_Value(newFeature.Fields.FindField("Name"), "New Road");
//插入新Feature
newFeature.Store();
//获取编辑器的EditSketch对象
IEngineEditSketch editSketch = editor as IEngineEditSketch;
//获取当前编辑的线
IPolyline polyline = editSketch.Geometry as IPolyline;
//获取当前编辑线的起点和终点
IPoint startPt = polyline.FromPoint;
IPoint endPt = polyline.ToPoint;
//创建缓冲区
ITopologicalOperator topoOp = geometry as ITopologicalOperator;
IGeometry buffer = topoOp.Buffer(10);
//创建查询过滤器
ISpatialFilter spatialFilter = new SpatialFilterClass();
spatialFilter.Geometry = buffer;
spatialFilter.GeometryField = featureClass.ShapeFieldName;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
//查询相交的Feature
IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);
IFeature intersectFeature = featureCursor.NextFeature();
while (intersectFeature != null)
{
//获取相交Feature的形状
IGeometry intersectGeometry = intersectFeature.ShapeCopy;
//获取相交Feature的顶点
IPointCollection pointCollection = intersectGeometry as IPointCollection;
for (int i = 0; i < pointCollection.PointCount; i++)
{
IPoint point = pointCollection.get_Point(i);
//判断相交点是否在编辑线的起点和终点之间
if (point.X >= Math.Min(startPt.X, endPt.X) && point.X <= Math.Max(startPt.X, endPt.X) &&
point.Y >= Math.Min(startPt.Y, endPt.Y) && point.Y <= Math.Max(startPt.Y, endPt.Y))
{
//创建新的Feature
IFeature newIntersectFeature = featureClass.CreateFeature();
//设置新Feature的形状
newIntersectFeature.Shape = point;
//设置新Feature的属性
newIntersectFeature.set_Value(newIntersectFeature.Fields.FindField("Name"), "Intersection");
//插入新Feature
newIntersectFeature.Store();
}
}
intersectFeature = featureCursor.NextFeature();
}
}
```
该代码演示了如何在道路编辑时,自动创建相交点 Feature,并将其插入到编辑图层中。其中,缓冲区大小通过 `topoOp.Buffer(10)` 设置为 10 个单位。您可以根据实际需求进行调整。
阅读全文