Мой проект, который рисует линию:
Код: Выделить всё
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Display;
namespace Task1
{
/// <summary>
/// Summary description for Tool1.
/// </summary>
[Guid("c26c308c-7e0a-43cb-a021-a689161e5de6")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Task1.Tool1")]
public sealed class Tool : BaseTool
{
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
ArcGISCategoryRegistration(registerType);
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
ArcGISCategoryUnregistration(registerType);
}
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Register(regKey);
}
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Unregister(regKey);
}
private IApplication m_application;
public Tool()
{
base.m_category = "OwnTools";
base.m_caption = "Toolforplochat";
base.m_message = "Инструмент увеличения площади полигона";
base.m_toolTip = "Создание объекта площадью в 2 раза больше исходного";
base.m_name = "Polyline_NOtWORK";
try
{
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
IMxDocument pDoc;
IMap pMap;
IFeatureClass pFtClass;
public override void OnCreate(object hook)
{
m_application = hook as IApplication;
if (hook is IMxApplication)
base.m_enabled = true;
else
base.m_enabled = false;
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
pDoc = m_application.Document as IMxDocument;
pMap = pDoc.Maps.get_Item(0);
IFeatureLayer pFtLayer = pMap.get_Layer(0) as FeatureLayer;
pFtClass = pFtLayer.FeatureClass;
IPoint pBufPt;
pBufPt = new PointClass();
pBufPt.PutCoords(pDoc.CurrentLocation.X, pDoc.CurrentLocation.Y);
ITopologicalOperator pTopoOperator;
pTopoOperator = pBufPt as ITopologicalOperator;
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pTopoOperator.Buffer(5);
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureCursor pFtCur;
pFtCur = pFtClass.Search(pSpatialFilter, true);
IFeature pFt = pFtCur.NextFeature();
if (pFt != null)
{
IMxDocument pMxdoc = m_application.Document as IMxDocument;
IRubberBand pRubber = new RubberLine();
IPolyline pPolyline;
IPoint pPoint1;
pPoint1 = new PointClass();
pPoint1.X = pDoc.CurrentLocation.X;
pPoint1.Y = pDoc.CurrentLocation.Y;
IPoint pPoint2;
pPoint2 = new PointClass();
pPoint2.X = pDoc.CurrentLocation.X+60;
pPoint2.Y = pDoc.CurrentLocation.Y+60;
IPointCollection pPointCollection = new Polyline();
pPointCollection.AddPoint(pPoint1);
pPointCollection.AddPoint(pPoint2);
IFeatureLayer pFLayer = pMxdoc.FocusMap.Layer[0] as IFeatureLayer;
IDataset pDS = pFLayer.FeatureClass as IDataset;
IWorkspaceEdit pWSE = pDS.Workspace as IWorkspaceEdit;
pWSE.StartEditing(false);
pWSE.StartEditOperation();
IFeature pFeature = pFLayer.FeatureClass.CreateFeature();
pFeature.Shape = pPointCollection as IGeometry;
pFeature.Store();
pWSE.StopEditOperation();
pWSE.StopEditing(true);
pMxdoc.ActiveView.Refresh();
}
}
}
}