Инструмент Clip на ArcObjects

ArcGIS 8.x,9.x,10.x (Arcview, ArcEditor, Arcinfo).
Ответить
HomBro
Интересующийся
Сообщения: 33
Зарегистрирован: 25 ноя 2017, 20:31
Репутация: 1
Откуда: Уфа

Инструмент Clip на ArcObjects

Сообщение HomBro » 23 июн 2020, 15:21

Хочу сделать инструмент на ArcObjects, по задумке я сначала кликаю на инструмент, потом в рандомное место на карте, открывается окошко, там я выбираю слой с которого хочу вырезать область вокруг точки в которую я уже кликнул, результат должен сохранится в файл по указанному пути, нооооо. постоянно вылетает исключение в самом ArcMap, а по нему вообще не разберешь, в чем проблема.
Часть кода:

Код: Выделить всё

	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);
        }
Тут в коде есть лишнее от предыдущих неудачных вариантов, в итоге пытался просто вырезать из уже двух готовых слоев, но тоже ловил исключение. Если всё прям совсем криво, то даже не против за это получить критику, ну и конечно же надеюсь что подскажете, как это всё правильно сделать.

Ответить

Вернуться в «ArcGIS»

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и 7 гостей