关于ToMapPoint过时造成的坐标转换的偏差

    制作点选(Identify )、框选(Select )等操作时,必要的一步是将客户端的屏幕坐标转换到地图坐标。在ArcGIS Server .NET ADF SP3 以前,使用如下语句进行转换:

Rectangle rect  =  (args  as  RectangleEventArgs).ScreenExtent;
ESRI.ArcGIS.ADF.Web.Geometry.Point minAdfPoint 
=  ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Left, rect.Bottom, mapCtrl.Extent, mapFunc.DisplaySettings.ImageDescriptor.Width, mapFunc.DisplaySettings.ImageDescriptor.Height);
ESRI.ArcGIS.ADF.Web.Geometry.Point maxAdfPoint 
=  ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Right, rect.Top, mapCtrl.Extent, mapFunc.DisplaySettings.ImageDescriptor.Width, mapFunc.DisplaySettings.ImageDescriptor.Height);
ESRI.ArcGIS.ADF.Web.Geometry.Envelope adfEnvelope 
=   new  ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minAdfPoint, maxAdfPoint);

    而在
SP3 以后,上述语句在编译时会收到一条警告:“ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(int, int, ESRI.ArcGIS.ADF.Web.Geometry.Envelope, int, int) ”已过时。 运行程序,似乎没觉得有什么偏差嘛。给Map Service 做个缓存,再运行,出现了明显的偏差。看下面两张图:
                                      关于ToMapPoint过时造成的坐标转换的偏差
                                                      图-1
                                      关于ToMapPoint过时造成的坐标转换的偏差
                                                      图-2
    进一步测试,只要MapResourceManager 中引用的任何一个Map Service 做了缓存,就会出现偏差,而没有缓存的情况下居然正常。这也恰恰是忽悠人的地方。 最可气的是ESRI 的帮助文档之简陋令人发指,ArcGIS Server .NET ADF API 文档看上去一片光秃秃的,告诉你方法已过时,却不提示你用什么方法替代。看来真的像我经理说的,GIS 软件巨头在美国不过是个三流小软件公司。
    好在经过孜孜不倦的google 终于找到了正确的方法,请使用如下语句:

Rectangle rect  =  (args  as  RectangleEventArgs).ScreenExtent;
ESRI.ArcGIS.ADF.Web.Geometry.Point minAdfPoint 
=  ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Left, rect.Bottom, mapCtrl.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
ESRI.ArcGIS.ADF.Web.Geometry.Point maxAdfPoint 
=  ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Right, rect.Top, mapCtrl.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
ESRI.ArcGIS.ADF.Web.Geometry.Envelope adfEnvelope 
=   new  ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minAdfPoint, maxAdfPoint);

    注意其中的GetTransformationParams和TransformationDirection。我的开发环境是Visual Studio 2005 + ArcGIS Server .NET ADF SP4 + ArcGIS Desktop 9.2 SP4 + ArcSDE 9.1。
    

你可能感兴趣的:(map)