ArcMap C#在选定图层中绘制折线

时间:2013-12-07 17:28:09

标签: c# arcgis polyline arcmap

public void OnMouseDown(int Button, int Shift, int X, int Y)
{
  IMxDocument mxDoc = m_App.Document as IMxDocument;
  IActiveView activeView = mxDoc.FocusMap as IActiveView;
  IScreenDisplay screenDisplay = activeView.ScreenDisplay;

  ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
  IRgbColor rgbColor = new RgbColorClass();
  rgbColor.Red = 255;
  lineSymbol.Color = rgbColor;

  IRubberBand rubberLine = new RubberLineClass();
  IPolyline newPolyline = (IPolyline)rubberLine.TrackNew(screenDisplay, (ISymbol)lineSymbol);

  screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
  screenDisplay.SetSymbol((ISymbol)lineSymbol);
  screenDisplay.DrawPolyline(newPolyline);
  screenDisplay.FinishDrawing();    
}

这是绘制折线的功能。但我希望折线将自动存储在“线”图层中,这是可能的吗?

1 个答案:

答案 0 :(得分:1)

你的问题有点不清楚。你的'line'层是否已经存在?

如果你想让你的图层成为一个特征层而不是图形图层,那么在工作区中创建一个特征类,然后像这样添加你的线对象(对不起它在vb.net中):

Dim pFeature as IFeature
pFeature = pFeatureClass.CreateFeature()
pFeature.Shape = newPolyline
pFeature.Store()

然后从您的要素类创建一个要素图层并将其添加到地图中:

Dim pFeatureLayer as IFeatureLayer
pFeatureLayer.FeatureClass = pFeatureClass
pFeatureLayer.Name = "Lines"
Dim pMap as IMap = pMxDoc.FocusMap
pMap.AddLayer(pFeatureLayer)