Часть кода:
Код: Выделить всё
private IApplication m_application;
private IMxDocument doc;
ToolForm tool = new ToolForm();
public override void OnCreate(object hook)
{
m_application = hook as IApplication;
doc = (IMxDocument)m_application.Document;
//Disable if it is not ArcMap
if (hook is IMxApplication)
base.m_enabled = true;
else
base.m_enabled = false;
// TODO: Add other initialization code
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
// TODO: Add Tool1.OnMouseDown implementation
tool.x = doc.CurrentLocation.X;
tool.y = doc.CurrentLocation.Y;
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
// TODO: Add Tool1.OnMouseUp implementation
tool.Show();
}
Код: Выделить всё
public IMxDocument doc;
public double x, y;
public ToolForm()
{
InitializeComponent();
}
private void ToolForm_Load(object sender, EventArgs e)
{
numericUpDown1.Value = trackBar1.Value;
IMap map = doc.FocusMap;
int lc = map.LayerCount;
for(int i=0; i<lc; i++)
{
if(map.Layer[i] is IFeatureLayer)
{
comboBox1.Items.Add(map.Layer[i].Name);
comboBox2.Items.Add(map.Layer[i].Name);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Geoprocessor gp = new Geoprocessor();
IFeatureClass in_feature = doc.FocusMap.Layer[0] as IFeatureClass;
IFeatureClass clip_feature = doc.FocusMap.Layer[0] as IFeatureClass;
IMap map = doc.FocusMap;
int lc = map.LayerCount;
int in_id = 0, clip_id = 0;
if (comboBox1.SelectedItem != null)
{
for(int i = 0; i < lc; i++)
{
if(map.Layer[i].Name == comboBox1.SelectedItem.ToString())
{
in_feature = map.Layer[i] as IFeatureClass;
in_id = i;
}
}
}
if (comboBox2.SelectedItem != null)
{
for (int i = 0; i < lc; i++)
{
if (map.Layer[i].Name == comboBox2.SelectedItem.ToString())
{
clip_feature = map.Layer[i] as IFeatureClass;
clip_id = i;
}
}
}
IPoint ptBuff = new PointClass();
ptBuff.PutCoords(x, y);
ITopologicalOperator topoOp;
topoOp = ptBuff as ITopologicalOperator;
ISpatialFilter spFilter = new SpatialFilterClass();
spFilter.Geometry = topoOp.Buffer((double)numericUpDown1.Value);
Clip clipTool = new Clip();
clipTool.in_features = map.Layer[in_id];
clipTool.clip_features = map.Layer[clip_id];
clipTool.out_feature_class = @"C:\city_buffer_clip.shp";
gp.Execute(clipTool, null);
}