1. 程式人生 > >螢幕畫素值與經緯度值的換算

螢幕畫素值與經緯度值的換算


 /// <summary>
        /// 畫素值與經緯度值的換算
        /// </summary>
        /// <param name="activeView"></param>
        /// <param name="iDevUnit"></param>
        /// <returns></returns>
        public double calcMapScale(IActiveView activeView, double iDevUnit) //後面引數為畫素值
        {
            double mapUnits = 0.01;
            IScreenDisplay pSd = activeView.ScreenDisplay;
            if (pSd != null)
            {
                //獲取地圖空間的畫素寬度
                IDisplayTransformation pDtf = pSd.DisplayTransformation;
                tagRECT tagRect = pDtf.get_DeviceFrame();
                int iPixelWid = tagRect.right - tagRect.left;
                //獲取當前地圖檢視的地理寬度
                IEnvelope pExtentEnve = activeView.Extent;
                mapUnits = pExtentEnve.Width / iPixelWid * iDevUnit;
            }
            return mapUnits;
        }