1、高亮显示节点



//高亮显示节点和端点  
public void HighLightNode()
{
//清空
_mapCtrl.Map.ClearSelection();
_mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, _mapCtrl.ActiveView.Extent);
var pGraphicsContainer = _mapCtrl.Map as IGraphicsContainer;
pGraphicsContainer.DeleteAllElements();
_mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);

//增加
ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass
{
Color = new RgbColorClass { Red = 255, Green = 0, Blue = 0 },
Width = 2,
Style = esriSimpleLineStyle.esriSLSSolid
};

ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass
{
Color =
new RgbColorClass { Red = 255, Green = 0, Blue = 0 },
Style = esriSimpleMarkerStyle.esriSMSCircle,
Size = 5
};
switch (currentFeature.Shape.GeometryType)
{
case esriGeometryType.esriGeometryPoint:
//IMarkerElement pMarkerElement = new MarkerElementClass();
//pMarkerElement.Symbol = simpleMarkerSymbol;
//var pEla = pMarkerElement as IElement;
//pEla.Geometry = currentFeature.Shape;
//var pActiveView = _mapCtrl.ActiveView;
//var pGraphicsContainer = _mapCtrl.Map as IGraphicsContainer;
//pGraphicsContainer.AddElement(pEla, 0);
//pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);
break;
case esriGeometryType.esriGeometryPolyline:
ILineElement pLineElement = new LineElementClass();
pLineElement.Symbol = simpleLineSymbol;
var pEla1 = pLineElement as IElement;
pEla1.Geometry = currentFeature.Shape;
var pActiveView1 = _mapCtrl.ActiveView;
var pGraphicsContainer1 = _mapCtrl.Map as IGraphicsContainer;
pGraphicsContainer1.AddElement(pEla1, 0);
pActiveView1.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);
break;
case esriGeometryType.esriGeometryPolygon:
IPolygonElement pPolygonElement = new PolygonElementClass { Symbol = simpleFillSymbol };
var pEla2 = pPolygonElement as IElement;
pEla2.Geometry = currentFeature.Shape;
var pActiveView2 = _mapCtrl.ActiveView;
var pGraphicsContainer2 = _mapCtrl.Map as IGraphicsContainer;
pGraphicsContainer2.AddElement(pEla2, 0);
pActiveView2.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);
break;
}
//显示节点
//step1:创建节点符号
ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();
pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;
pVertexMarkerSymbol.Size = 3;
pVertexMarkerSymbol.Angle = 0;
IRgbColor rgbVertex = new RgbColorClass();
rgbVertex.Green = 255;
pVertexMarkerSymbol.Color = rgbVertex;
ISimpleMarkerSymbol pEndPointMarkerSymbol = new SimpleMarkerSymbol();
pEndPointMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;
pEndPointMarkerSymbol.Size = 4;
pEndPointMarkerSymbol.Angle = 0;
IRgbColor rgbEndPoint = new RgbColorClass();
rgbEndPoint.Red = 255;
pEndPointMarkerSymbol.Color = rgbEndPoint;

//判D断要素的类型
if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
{
IGeometryCollection pGeoColl;
ISegmentCollection pSegColl;
ISegment pSegment;
IPath path;
IPointCollection pEndPointCol;
IMultipoint pEndPoints;
IPoint pEndPoint;
pEndPoints = new MultipointClass();
pEndPointCol = pEndPoints as IPointCollection;
pGeoColl = currentFeature.Shape as IGeometryCollection;
for (int i = 0; i < pGeoColl.GeometryCount; i++)
{
pSegColl = pGeoColl.get_Geometry(i) as ISegmentCollection;
path = pGeoColl.get_Geometry(i) as IPath;
pEndPointCol.AddPoint(path.FromPoint);
pEndPointCol.AddPoint(path.ToPoint);

for (int j = 0; j < pSegColl.SegmentCount; j++)
{
pSegment = pSegColl.get_Segment(j);
//show vertex
AddPointSymbolToMap(pSegment.FromPoint, pVertexMarkerSymbol);
AddPointSymbolToMap(pSegment.ToPoint, pVertexMarkerSymbol);
}
}
//show endpoint
for (int k = 0; k < pEndPointCol.PointCount; k++)
{
pEndPoint = pEndPointCol.get_Point(k);
AddPointSymbolToMap(pEndPoint, pEndPointMarkerSymbol);
}

}
else if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
{
IPoint pEndPoint;
pEndPoint = currentFeature.Shape as IPoint;
AddPointSymbolToMap(pEndPoint, pEndPointMarkerSymbol);
}
}


2、添加节点



OnMouseDown事件:  
IProximityOperator proximityOperator = ucDrawPanel.currentFeature.Shape as IProximityOperator;
ptInsert = proximityOperator.ReturnNearestPoint(pPt, esriSegmentExtension.esriNoExtension);

//step1: 创建节点符号
ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();
pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;
pVertexMarkerSymbol.Size = 3;
pVertexMarkerSymbol.Angle = 0;
IRgbColor rgbVertex = new RgbColorClass();
rgbVertex.Green = 255;
pVertexMarkerSymbol.Color = rgbVertex;
//step2: 显示在地图上
IMarkerElement pMarkerElement = new MarkerElementClass();
pMarkerElement.Symbol = pVertexMarkerSymbol;
var pEla = pMarkerElement as IElement;
pEla.Geometry = ptInsert as IGeometry;
pGraphicContainer.AddElement(pEla, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);

OnMouseUp事件,添加一个节点,但不打断线:
// 注意:如果第三个参数createPart设为true,线会被打断,不可取
//线?splitAtPoint
bool isSplitted;
int newPartIndex;
int newSegmentIndex;
IPolyline polyline = ucDrawPanel.currentFeature.Shape as IPolyline;
//插入一点,newSegmentIndex记录插入点的相对线的节点位置
polyline.SplitAtPoint(ptInsert, true, false, out isSplitted, out newPartIndex, out newSegmentIndex);
ucDrawPanel.currentFeature.Store();


3、删除节点



OnMouseDown事件:  
//step1:获取预删除的节点
IPolyline pPolyline;
IHitTest pHitTest;
bool BoolHitTest;
double dist = 0;
double DbHitDis = 0;
int LngPrtIdx = 0;
bool BoolHitRt = false;
hitElement = getElement(pPt, esriGeometryType.esriGeometryPolyline);
if (hitElement != null)
{
pPolyline = hitElement.Geometry as IPolyline;
pHitTest = pPolyline as IHitTest;
ptDelete = new PointClass();
BoolHitTest = pHitTest.HitTest(pPt, pActiveView.Extent.Width / 100,
esriGeometryHitPartType.esriGeometryPartVertex, ptDelete, ref DbHitDis, ref LngPrtIdx, ref indexDelete, ref BoolHitRt);
// pHitTest.HitTest(pPt, pActiveView.Extent.Width / 100,esriGeometryHitPartType.esriGeometryPartVertex, ptDelete,ref DbHitDis, ref LngPrtIdx, ref LngSegIdx, ref BoolHitRt);

if (BoolHitTest)
{
//step2:高?亮显示,符号黑色边框镂空填充
ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();
pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
pVertexMarkerSymbol.Size = 5;
pVertexMarkerSymbol.Angle = 0;
IRgbColor rgbVertex = new RgbColorClass();
rgbVertex.Red = 0;
rgbVertex.Blue = 0;
rgbVertex.Green = 0;
pVertexMarkerSymbol.Color = rgbVertex;

IMarkerElement pMarkerElement = new MarkerElementClass();
pMarkerElement.Symbol = pVertexMarkerSymbol;
var pEla = pMarkerElement as IElement;
pEla.Geometry = ptDelete as IGeometry;
pGraphicContainer.AddElement(pEla, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);
}
}

OnMouseUp事件,删除节点:
IPointCollection pointCollection = ucDrawPanel.currentFeature.Shape as IPointCollection;
pointCollection.RemovePoints(indexDelete, 1);
IPolyline polylineNew = pointCollection as IPolyline;
StoreFeatureGeometry(ucDrawPanel.currentFeature, polylineNew);
保存图形要素:
private bool StoreFeatureGeometry(IFeature pFeature, IGeometry pIGeometry)
{
try
{
var pFeatureClass = pFeature.Class as IFeatureClass;
var pDataset = pFeatureClass as IDataset;
IWorkspace pWorkspace = pDataset.Workspace;
var pWorkspaceEdit = pWorkspace as IWorkspaceEdit;

pWorkspaceEdit.StartEditing(false);
pWorkspaceEdit.StartEditOperation();
pFeature.Shape = pIGeometry;
pFeature.Store();
pWorkspaceEdit.StopEditOperation();
pWorkspaceEdit.StopEditing(true);
return true;
}
catch (Exception ex)
{
return false;
}
}


4、打断线



关键字:Split。  
OnMouseDown事件:
IProximityOperator proximityOperator = ucDrawPanel.currentFeature.Shape as IProximityOperator;
ptSplit = proximityOperator.ReturnNearestPoint(pPt, esriSegmentExtension.esriNoExtension);

//step1:创建节点符号
ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();
pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;
pVertexMarkerSymbol.Size = 4;
pVertexMarkerSymbol.Angle = 0;
IRgbColor rgbVertex = new RgbColorClass();
rgbVertex.Red = 255;
pVertexMarkerSymbol.Color = rgbVertex;
//step2:显示在地图上
IMarkerElement pMarkerElement = new MarkerElementClass();
pMarkerElement.Symbol = pVertexMarkerSymbol;
var pEla = pMarkerElement as IElement;
pEla.Geometry = ptSplit as IGeometry;
pGraphicContainer.AddElement(pEla, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);

OnMouseUp事件打断线:
IFeatureEdit featureEdit = ucDrawPanel.currentFeature as IFeatureEdit;
ISet newFeaturesSet = featureEdit.Split(ptSplit);
newFeaturesSet.Reset();
IFeature feature = newFeaturesSet.Next() as IFeature;


5、合并线


首先判断预合并的两条线拓扑关系,是否邻接关系;满足条件可以用关键字Merge实现,或者自定义方法,重新获取点的集合IPointCollection创建多线。


 


 


你们的评论、反馈,及对你们有所用,是我整理材料和博文写作的最大的鼓励和唯一动力。欢迎讨论和关注!

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。