How to Select Feature by XY Location and Highlight it in ArcMap 9.3 programmatically?

4264
12
05-18-2011 12:46 AM
dgesridgesri
Occasional Contributor II
Greetings,

I hope to find a solution to the following questions that I really need in my project:

  1. How to find the feature under the mouse click (XY Coodinates) from a feature layer in ArcMap 9.3?

  2. How to highlight (flash) a selected feature in ArcMap 9.3 using VB.Net?

Please advise....
0 Kudos
12 Replies
imranmd
New Contributor
hi frnd iam new to programming ..


i want to show a pop up window to display the element attributes (same as map identify tool) .

can anyone suggest some ideas

here is my code for displaying the map in wpf.


using System;
using System.Windows;
using System.Windows.Forms;
using System.Drawing;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.CadastralUI;
using ESRI.ArcGIS.ParcelFabricTools;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.EditorExt;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using System.Runtime.InteropServices;

namespace MapHostedInWPF
{
   
    public partial class Window1 : Window
    {
        AxMapControl mapControl;
        AxToolbarControl toolbarControl;
        AxTOCControl tocControl;
        public Window1()
        {
            InitializeComponent();
            CreateMapControl();
        }
        private void CreateMapControl()
        {
            mapControl = new AxMapControl();
            mapHost.Child = mapControl;

            toolbarControl = new AxToolbarControl();
            toolbarHost.Child = toolbarControl;

            tocControl = new AxTOCControl();
            tocHost.Child = tocControl;
        }
                       
        private void SetMapProperties()
        {
         
            mapControl.Dock = DockStyle.None;
            mapControl.BackColor = Color.FromArgb(233, 233, 233);
        }
        private void WireMapEvents()
        {
            mapControl.OnMouseMove += new IMapControlEvents2_Ax_OnMouseMoveEventHandler
                (mapControl_OnMouseMove);
        }

        private void mapControl_OnMouseMove(object sender,
            IMapControlEvents2_OnMouseMoveEvent e)
        {
            System.Console.WriteLine(e.mapX.ToString());
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            try
            {
             

                SetMapProperties();
                WireMapEvents();

              
                mapControl.LoadMxFile("D:\\California\\California.mxd");
                tocControl.SetBuddyControl(mapControl);
                toolbarControl.SetBuddyControl(mapControl);

                toolbarControl.AddItem("esriControls.ControlsOpenDocCommand");
                toolbarControl.AddItem("esriControls.ControlsAddDataCommand");
                toolbarControl.AddItem("esriControls.ControlsSaveAsDocCommand");
                toolbarControl.AddItem("esriControls.ControlsMapNavigationToolbar");         
                toolbarControl.AddItem("esriControls.ControlsEditingToolbar");

                toolbarControl.BackColor = Color.FromArgb(245, 245, 220);

            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }
 
        }


    }
}
0 Kudos
imranmd
New Contributor
can you please tell me the code to implement yours code in my project...

public void WorkIdentify()
        {
           IMxDocument doc =  ArcMap.Application.Document as IMxDocument;
            IActiveView activeView = doc.ActiveView;
            IPoint mouseLocation = GetScreenCoordinatesFromMapCoorindates(doc.CurrentLocation, activeView);
            System.Int32 x = (System.Int32) mouseLocation.X;
            System.Int32 y = (System.Int32) mouseLocation.Y;
           
            if (activeView == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;
            ESRI.ArcGIS.CartoUI.IIdentifyDialog identifyDialog = new ESRI.ArcGIS.CartoUI.IdentifyDialogClass();
            identifyDialog.Map = map;

            //Clear the dialog on each mouse click
            identifyDialog.ClearLayers();
            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;

            ESRI.ArcGIS.Display.IDisplay display = screenDisplay; // Implicit Cast
            identifyDialog.Display = display;

            ESRI.ArcGIS.CartoUI.IIdentifyDialogProps identifyDialogProps = (ESRI.ArcGIS.CartoUI.IIdentifyDialogProps)identifyDialog; // Explicit Cast
            ESRI.ArcGIS.Carto.IEnumLayer enumLayer = identifyDialogProps.Layers;
            enumLayer.Reset();

            ESRI.ArcGIS.Carto.ILayer layer = enumLayer.Next();

            //
            while (!(layer == null))
            {
                identifyDialog.AddLayerIdentifyPoint(layer, x, y);

                layer = enumLayer.Next();
            }
            identifyDialog.Show();
        }
0 Kudos
imranmd
New Contributor
Dear Sandhya Yamarthi,

Can you please tell me how to call the following code...

using System.Runtime.InteropServices;

namespace Project1
{
class Class1
{
[DllImport("kernel32.dll")]
static extern void Sleep(uint dwMilliseconds);

public void FlashFeature(IFeature Feature, IMxDocument MxDoc)
{

try
{

MxDoc.ActiveView.ScreenDisplay.StartDrawing(0, (short)(esriScreenCache.esriNoScreenCache));

switch (Feature.Shape.GeometryType)
{
case (esriGeometryType.esriGeometryPolyline):
{
FlashLine(MxDoc.ActiveView.ScreenDisplay, Feature.Shape);
break;
}
case (esriGeometryType.esriGeometryPolygon):
{
FlashPolygon(MxDoc.ActiveView.ScreenDisplay, Feature.Shape);
break;
}
case (esriGeometryType.esriGeometryPoint):
{
FlashPoint(MxDoc.ActiveView.ScreenDisplay, Feature.Shape);
break;
}



}
MxDoc.ActiveView.ScreenDisplay.FinishDrawing();
}
catch (Exception Err)
{
MessageBox.Show("Error : " + Err.Message);

}

}

public void FlashLine(IScreenDisplay Display, IGeometry Geometry)
{


ISimpleLineSymbol LineSymbol;
ISymbol Symbol;
IRgbColor RgbColor;

try
{
LineSymbol = new SimpleLineSymbolClass();
LineSymbol.Width = 4;

RgbColor = new RgbColorClass();
RgbColor.Green = 128;

Symbol = (ISymbol)LineSymbol;
Symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;

Display.SetSymbol((ISymbol)(LineSymbol));
Display.DrawPolyline(Geometry);

Sleep(300);

Display.DrawPolyline(Geometry);
}
catch (Exception Err)
{
LogFile.WriteLog("Error at : " + Err.Message);

}

}

public void FlashPolygon(IScreenDisplay Display, IGeometry Geometry)
{
ISimpleFillSymbol FillSymbol;
ISymbol Symbol;
IRgbColor RgbColor;

try
{
FillSymbol = new SimpleFillSymbolClass();
FillSymbol.Outline = null;

RgbColor = new RgbColorClass();
RgbColor.Green = 128;

Symbol = (ISymbol)FillSymbol;
Symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;

Display.SetSymbol((ISymbol)(FillSymbol));
Display.DrawPolygon(Geometry);
Sleep(300);

Display.DrawPolygon(Geometry);
}
catch (Exception Err)
{
LogFile.WriteLog("Error at : " + Err.Message);

}

}
public void FlashPoint(IScreenDisplay Display, IGeometry Geometry)
{
ISimpleMarkerSymbol MarkerSymbol;
ISymbol Symbol;
IRgbColor RgbColor;

try
{
MarkerSymbol = new SimpleMarkerSymbolClass();
MarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;

RgbColor = new RgbColorClass();
RgbColor.Green = 128;

Symbol = (ISymbol)MarkerSymbol;
Symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;

Display.SetSymbol((ISymbol)MarkerSymbol);
Display.DrawPoint(Geometry);
Sleep(300);
Display.DrawPoint(Geometry);

}
catch (Exception Err)
{
LogFile.WriteLog("Error : " + Err.Message);

}

}
}
}


I have already post my code..

Thanks for your valuable time and consideration...

Waiting for your reply..
0 Kudos