0

I've used the following ESRI snippet to Convert the display extents in Pixels (at the current map scale) and then return out the map units.

public System.Double ConvertPixelsToMapUnits(ESRI.ArcGIS.Carto.IActiveView activeView, System.Int32 pixelUnits)
{
  
  if(activeView == null)
  {
    return -1;
  }
  //Get the ScreenDisplay
  ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;

  //Get the DisplayTransformation 
  ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;

  //Get the device frame which will give us the number of pixels in the X direction
  ESRI.ArcGIS.Display.tagRECT deviceRECT = displayTransformation.get_DeviceFrame();
  System.Int32 pixelExtent = (deviceRECT.right - deviceRECT.left);

  //Get the map extent of the currently visible area
  ESRI.ArcGIS.Geometry.IEnvelope envelope = displayTransformation.VisibleBounds;
  System.Double realWorldDisplayExtent = envelope.Width;

  //Calculate the size of one pixel
  if(pixelExtent == 0)
  {
    return -1;
  }
  System.Double sizeOfOnePixel = (realWorldDisplayExtent / pixelExtent);

  //Multiply this by the input argument to get the result
  return (pixelUnits * sizeOfOnePixel);
}

and then this to check if the snapping is within tolerance ITolerance which is in Pixels(Example 10 pixels) :

Double dblToleranceX;
dblToleranceX = snaptolerance(ITolerance);// call ESRI Snippet 
dblProximity = dblToleranceX;
ouble dblToleranceY = dblToleranceX;
pInputpoint = gpMxDocument.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(intX, intY);
pRectangle.PutCoords(pInputpoint.X - dblToleranceX, pInputpoint.Y - dblToleranceY, pInputpoint.X + dblToleranceX, pInputpoint.Y + dblToleranceY);
pSpatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureClass pFeatureClass = gpFeatureWorkSpace.OpenFeatureClass(strFeaturecls);
pSpatialfilter.Geometry = pRectangle;
pSpatialfilter.GeometryField = pFeatureClass.ShapeFieldName;
pFeatureCursor = pFeatureClass.Search(pSpatialfilter, false);
pFeature = pFeatureCursor.NextFeature();

if (pFeatureClass.FeatureCount(pSpatialfilter) < 1)
 {
    MessageBox.Show("Snapping is not within tolerance");
                    return;
                }

The code work perfectly on NAD83(decimal degree) but does not work when Changing the data frame's coordinate system to NAD 83 UTM Zone 11N (Meters).

Is there a way around this issue in order to make the code work for these kind of situation?

0

1 Answer 1

1

I've got an answer from ESRI Canada support and the solution is to use buffer instead of rectangle:

   IGeometry buffer;
   ITopologicalOperator topo = (ITopologicalOperator)pInputpoint;
   buffer = topo.Buffer(dblPointDistance);   //(dblProximity);

   pSpatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
   IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass  ;
   pSpatialfilter.Geometry = buffer; //pRectangle , used buffer instead of using rectangle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.