identify a point based on mouse argument.

1226
0
05-05-2013 06:56 AM
NadeemQazi
New Contributor III
Please see the attached layer. I have used following code in the OnMouseDown event. my objective is to select the X_coor , and Y_coor field from the layer based on the arg.X and arg.y. however when i run this code than on a single click there are several values of the X_coor and Y-coor. I  observed that the values of x_coor and y_coor fields in the  associated attribute table of the layer is differ by in  fifth or sixth significant digit. Actually this is my Time enabled data and I want to access it time in second corresponding to X-coor and Y-coor when the mouse is clicked. Any help........
   
  IMxApplication pMxApp = null;
            pMxApp = (IMxApplication)ArcMap.Application;
            IMxDocument pMxDoc = null;
            //pMxDoc = ArcMap.Document;
            if (pMxDoc.SelectedLayer == null)
            {
                MessageBox.Show("There is no layer selected.  First select a time-aware layer.");
                return;
            }
            IMap pMap = pMxDoc.FocusMap;
            IIdentify idft = null;
            //mycode for enevelop
            int Tolerance = 10;
            Tolerance = pMxDoc.SearchTolerancePixels;
            IPoint mypt = pMxDoc.CurrentLocation;
            int X = arg.X;
            int  Y = arg.Y;
             IDisplayTransformation pDispTrans = null;
            pDispTrans = pMxApp.Display.DisplayTransformation;
            tagRECT pToleranceRect = new tagRECT();
            pToleranceRect.left = X - Tolerance;
            pToleranceRect.right = X + Tolerance;
            pToleranceRect.top = Y - Tolerance;
            pToleranceRect.bottom = Y + Tolerance;

            IEnvelope pSearchEnvelope = null;
            pSearchEnvelope = new EnvelopeClass();
            pDispTrans.TransformRect(pSearchEnvelope, ref pToleranceRect, (int)(esriDisplayTransformationEnum.esriTransformPosition | esriDisplayTransformationEnum.esriTransformToMap));

            // identify feature points of measurement
          
            pSearchEnvelope.SpatialReference = pMxDoc.ActiveView.FocusMap.SpatialReference;

             idft = (IIdentify)pMap.get_Layer(0);
           
            IArray pidarray = null;
            IArray pidarray2 = null;
            pidarray = idft.Identify(pSearchEnvelope);
            if (pidarray != null)
            {
             
                MessageBox.Show("totL FOUND from currentloaction method" + pidarray.Count);
                IIdentifyObj myobj = (IIdentifyObj)pidarray.get_Element(0);
                IRowIdentifyObject rowobj = (IRowIdentifyObject)myobj;
                MessageBox.Show("downrowobjfld0" + ":" + rowobj.Row.get_Value(0).ToString() + ":" + "rowobjfld2" + rowobj.Row.get_Value(2).ToString() + ":fld3: " + rowobj.Row.get_Value(3).ToString());

            }
            else
                MessageBox.Show("pidarray null")
0 Kudos
0 Replies