IActiveView坐标转换

PageLayoutControl页面坐标与地理坐标的相互转换:

1, 页面坐标到地理坐标的转换分两步:

(1)将IPageLayout转为IActiveView,IActiveView.ScreenDisplay.DisplayTransformation.FromMapPoin(); 将页面坐标转为屏幕坐标;

(2)将FocusMap转为IActiveView,IActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(); 将屏幕坐标转为地理坐标。

2, 地理坐标转换为页面坐标也是分两步:

(1)将FocusMap转为IActiveView,IActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint();将地理坐标转为屏幕坐标;

(2)将IPageLayout转为IActiveView,IActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint();将屏幕坐标转为页面坐标。

此外,其IDisplayTransformation.FromPoints方法可以将point(1/72 inch) distance转为map distance;IDisplayTransformation.ToPoints方法可以将map distance转为point distance。



例1、屏幕坐标转为地理坐标:

public IPoint GetMapCoordinatesFromScreenCoordinates(IPoint screenPoint, IActiveView activeView)
        {
            if (screenPoint == null || screenPoint.IsEmpty || activeView == null)
            {
                return null;
            }
            IScreenDisplay screenDisplay = activeView.ScreenDisplay;
            IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;

            return displayTransformation.ToMapPoint((System.Int32)screenPoint.X, (System.Int32)screenPoint.Y);
        }

例2、地理坐标转为屏幕坐标:

public IPoint GetScreenCoordinatesFromMapCoorindates(IPoint mapPoint, IActiveView activeView)
        {
            if (mapPoint == null || mapPoint.IsEmpty || activeView == null)
            {
                return null;
            }
            IScreenDisplay screenDisplay = activeView.ScreenDisplay;
            IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;
            System.Int32 x;
            System.Int32 y;
            displayTransformation.FromMapPoint(mapPoint, out x, out y);
            IPoint returnPoint = new PointClass();
            returnPoint.PutCoords(x, y);
            return returnPoint;
        }



posted @ 2018-05-30 10:23  HPUGIS  阅读(209)  评论(0编辑  收藏  举报