将鼠标点击得到的屏幕坐标系上的点,先转成地理坐标系,之后通过获取指定数据集的投影坐标系,转换成该投影坐标系下的坐标。
IPoint pPnt = ReturnMousePoint(m_pGlobeControl.GlobeDisplay, x, y);
IGeoDataset pGeoDataset = m_HandlingFeatureLayer as IGeoDataset;
if (pGeoDataset.SpatialReference != null)
{
ISpatialReferenceFactory ispReferenceFactory = new SpatialReferenceEnvironmentClass();
IGeographicCoordinateSystem earthref = ispReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
pPnt.SpatialReference = earthref;
pPnt.Project(pGeoDataset.SpatialReference);
}
public static IPoint ReturnMousePoint(IGlobeDisplay globeDisplay, int dScreenX, int dScreenY)
{
double dLon, dLat, dAlt;
IPoint point = new PointClass();
ESRI.ArcGIS.Analyst3D.ISceneViewer sceneViewer = globeDisplay.ActiveViewer;
ESRI.ArcGIS.Analyst3D.ICamera camera = sceneViewer.Camera;
ESRI.ArcGIS.GlobeCore.IGlobeCamera globeCamera = (ESRI.ArcGIS.GlobeCore.IGlobeCamera)camera;
IGlobeViewUtil globeViewUtil = (ESRI.ArcGIS.GlobeCore.IGlobeViewUtil)globeCamera; // Explicit cast
IZAware pZAware = point as IZAware;
pZAware.ZAware = true;
try
{
globeViewUtil.WindowToGeographic(globeDisplay, globeDisplay.ActiveViewer, dScreenX, dScreenY, true, out dLon, out dLat, out dAlt); //转成地理坐标
point.X = dLon; point.Y = dLat; point.Z = dAlt;
}
catch (Exception)
{
point = null;
MessageBox.Show("坐标转换错误", "ReturnMousePoint");
}
return point;
}