Example #1
0
        /// <summary>
        /// 将像素转换成地图单元
        /// </summary>
        /// <param name="pActiveView">提供各种转换信息</param>
        /// <param name="pixelUnits">像素单元</param>
        /// <returns>像素单元大小</returns>
        public static double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
        {
            if (pActiveView == null)
            {
                return(-1);
            }
            //获取 the ScreenDisplay
            IScreenDisplay screenDisplay = pActiveView.ScreenDisplay;

            //获取 DisplayTransformation
            IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;

            //获取一个设备帧并用它来获得x轴方向上的像素数
            tagRECT deviceRECT  = displayTransformation.get_DeviceFrame();
            int     pixelExtent = (deviceRECT.right - deviceRECT.left);

            //获取当前可是区域的地图范围
            IEnvelope envelope = displayTransformation.VisibleBounds;
            double    realWorldDisplayExtent = envelope.Width;

            //计算一个像素大小
            if (pixelExtent == 0)
            {
                return(-1);
            }
            double sizeOfOnePixel = (realWorldDisplayExtent / pixelExtent);

            //得出像素单元大小
            return(pixelUnits * sizeOfOnePixel);
        }
Example #2
0
        private static double GetLengthInMapUnits(IActiveView activeView, double mm)
        {
            if (activeView == null)
            {
                return(-1);
            }

            IScreenDisplay         screenDisplay         = activeView.ScreenDisplay;
            IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;
            var dpi    = displayTransformation.Resolution;
            var inches = mm / 25.4;

            tagRECT deviceRect  = displayTransformation.get_DeviceFrame();
            int     pixelExtent = (deviceRect.right - deviceRect.left);

            var pixels = dpi * inches;
            IDistanceConverter distanceConverter = new DistanceConverter();

            IEnvelope envelope = displayTransformation.VisibleBounds;
            double    realWorldDisplayExtent = envelope.Width;

            if (pixelExtent == 0)
            {
                return(-1);
            }

            var sizeOfOnePixel = (realWorldDisplayExtent / pixelExtent);

            return(pixels * sizeOfOnePixel);
        }
Example #3
0
 public static IEnvelope GetSearchEnvelope(IActiveView pActiveView, IPoint pPoint)
 {
     try
     {
         double    num           = 6.0;
         IEnvelope visibleBounds = null;
         if (pActiveView != null)
         {
             IDisplayTransformation displayTransformation = pActiveView.ScreenDisplay.DisplayTransformation;
             visibleBounds = displayTransformation.VisibleBounds;
             tagRECT deviceFrame = displayTransformation.get_DeviceFrame();
             double  height      = 0.0;
             long    num3        = 0L;
             height = visibleBounds.Height;
             num3   = deviceFrame.bottom - deviceFrame.top;
             double num4 = 0.0;
             num4 = height / ((double)num3);
             num *= num4;
         }
         if (pPoint == null)
         {
             return(null);
         }
         visibleBounds        = pPoint.Envelope;
         visibleBounds.Width  = num;
         visibleBounds.Height = num;
         visibleBounds.CenterAt(pPoint);
         return(visibleBounds);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Example #4
0
        /// <summary>
        /// Converts the pixels to map units.
        /// </summary>
        /// <param name="activeView">The active view.</param>
        /// <param name="targetSpatialRef">The target spatial reference.</param>
        /// <param name="pixelValue">The pixel value.</param>
        /// <param name="useWidth">if set to <c>true</c> [use width].</param>
        /// <returns>System.Double.</returns>
        public static double ConvertPixelsToMapUnits(IActiveView activeView, ISpatialReference targetSpatialRef, double pixelValue, bool useWidth = true)
        {
            double result;

            if (activeView == null)
            {
                result = 0.0;
            }
            else if (pixelValue == 0.0)
            {
                result = 0.0;
            }
            else if (targetSpatialRef is IUnknownCoordinateSystem)
            {
                result = 0.0;
            }
            else
            {
                IDisplayTransformation displayTransformation = activeView.ScreenDisplay.DisplayTransformation;
                IEnvelope visibleBounds = displayTransformation.VisibleBounds;
                visibleBounds.Project(targetSpatialRef);
                tagRECT deviceFrame = displayTransformation.get_DeviceFrame();
                double  num;
                long    num2;
                if (useWidth)
                {
                    num  = visibleBounds.Width;
                    num2 = (long)(deviceFrame.right - deviceFrame.left);
                }
                else
                {
                    num  = visibleBounds.Height;
                    num2 = (long)(deviceFrame.bottom - deviceFrame.top);
                }
                if (num == 0.0)
                {
                    result = 0.0;
                }
                else if (num2 == 0L)
                {
                    result = 0.0;
                }
                else
                {
                    double num3 = num / (double)num2;
                    result = pixelValue * num3;
                }
            }
            return(result);
        }
Example #5
0
        /// <summary>
        /// 如果地图的参考比例尺被设定,该函数起作用,将指定的像素转换为地图的范围
        /// </summary>
        /// <param name="pMap">地图接口</param>
        /// <param name="pixels">像素</param>
        /// <returns>地图对应的范围</returns>
        public static double ConvertPixels2ReferenceScaleMapUnits(IMap pMap, int pixels)
        {
            IActiveView pView = (IActiveView)pMap;

            if (pMap.ReferenceScale > 0)
            {
                IDisplayTransformation pDT       = pView.ScreenDisplay.DisplayTransformation;
                tagRECT   deviceRECT             = pDT.get_DeviceFrame();
                int       pixelExtent            = deviceRECT.right - deviceRECT.left;
                IEnvelope pEnv                   = pDT.VisibleBounds;
                double    realWorldDisplayExtent = pEnv.Width;
                double    sizeOfOnePixel         = realWorldDisplayExtent / pixelExtent;
                return(pixels * sizeOfOnePixel);
            }
            return(pixels);
        }
Example #6
0
        /// <summary>
        /// Converts a screen pixel distance to the real distance.
        /// </summary>
        /// <param name="pixels">Number of pixels on the screen.</param>
        /// <param name="display">Esri display.</param>
        /// <returns>Real world distance.</returns>
        public static double PixelsToDistance(int pixels, IScreenDisplay display)
        {
            IDisplayTransformation transformation = display.DisplayTransformation;

            // get number of pixels in x axis
            tagRECT deviceRect       = transformation.get_DeviceFrame();
            int     pixelsOfMapWidth = deviceRect.right - deviceRect.left;

            // get extent of visible area in map
            IEnvelope mapExtent      = transformation.VisibleBounds;
            double    distOfMapWidth = mapExtent.Width;

            // calculate size of one pixel
            double sizeOfPixel = distOfMapWidth / pixelsOfMapWidth;

            return(sizeOfPixel * pixels);
        }
Example #7
0
        /// <summary>
        /// 屏幕距离转换为地图距离,用地图可视范围的宽度/设备宽,得到每个像素代表的地图长度
        /// </summary>
        /// <param name="pScreenDisplay"></param>
        /// <param name="pixel"></param>
        /// <returns></returns>
        public static double ConvertPixelToMapUnit(IScreenDisplay pScreenDisplay, int pixel)
        {
            if (pScreenDisplay == null)
            {
                return(0);
            }

            IDisplayTransformation pDisplayTransformation = pScreenDisplay.DisplayTransformation;

            tagRECT   rectDevice   = pDisplayTransformation.get_DeviceFrame();
            IEnvelope pMapBoundary = pDisplayTransformation.VisibleBounds;

            int    nDeviceWidth = rectDevice.right - rectDevice.left;
            double dMapWidth    = pMapBoundary.Width;

            return(pixel * (dMapWidth / nDeviceWidth));
        }
Example #8
0
 public double ConvertPixelsToMapUnits(IActiveView pActiveView, double dPixelUnits, bool bWidthFlag)
 {
     try
     {
         if (pActiveView == null)
         {
             return(0.0);
         }
         if (dPixelUnits == 0.0)
         {
             return(0.0);
         }
         IDisplayTransformation displayTransformation = pActiveView.ScreenDisplay.DisplayTransformation;
         IEnvelope visibleBounds = displayTransformation.VisibleBounds;
         tagRECT   deviceFrame   = displayTransformation.get_DeviceFrame();
         double    width         = 0.0;
         long      num2          = 0L;
         if (bWidthFlag)
         {
             width = visibleBounds.Width;
             num2  = deviceFrame.right - deviceFrame.left;
         }
         else
         {
             width = visibleBounds.Height;
             num2  = deviceFrame.bottom - deviceFrame.top;
         }
         if (width == 0.0)
         {
             return(0.0);
         }
         if (num2 == 0L)
         {
             return(0.0);
         }
         double num3 = 0.0;
         num3 = width / ((double)num2);
         return(dPixelUnits * num3);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.UnitFun", "ConvertMapToPixelsUnits", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(-1.0);
     }
 }
Example #9
0
        public static double ConvertScreenPixelsToMapUnits(IScreenDisplay scrnDsp, double pixels)
        {
            IDisplayTransformation dspTransform = scrnDsp.DisplayTransformation;
            double refScale = dspTransform.ReferenceScale;

            if (refScale != 0)
            {
                double scaleRatio = dspTransform.ScaleRatio;
                double pixelCount = dspTransform.ToPoints(scaleRatio);
                double pixelSize  = (double)scaleRatio / (double)pixelCount;
                return(pixelSize * pixels);
            }
            else
            {
                tagRECT deviceFrame = dspTransform.get_DeviceFrame();
                int     pixelExtent = deviceFrame.right - deviceFrame.left;

                IEnvelope visBounds = dspTransform.VisibleBounds;
                double    pixelSize = (double)visBounds.Width / (double)pixelExtent;
                return(pixelSize * pixels);
            }
        }
 /// <summary>
 /// nDeviceFrameUpdated event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="sizeChanged"></param>
 private void OnDeviceFrameUpdated(IDisplayTransformation sender, bool sizeChanged)
 {
   //update the device frame rectangle
   m_deviceFrame = sender.get_DeviceFrame();
 }
Example #11
0
 /// <summary>
 /// nDeviceFrameUpdated event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="sizeChanged"></param>
 private void OnDeviceFrameUpdated(IDisplayTransformation sender, bool sizeChanged)
 {
     //update the device frame rectangle
     m_deviceFrame = sender.get_DeviceFrame();
 }