【C#】记ArcObject下的几何投影变换的一个需要注意的坑
翻出陈年代码重写,老是报”The coordinates or measures are out of bounds.“
找来找去发现错误出在下面snippet里,geometry.Project(spatialReferenceTo)会对传入的point处理,所以应该带ref关键字以示提醒。
/// <summary> /// 平面坐标系点转地理坐标系点,在ArcGIS平台下 /// </summary> /// <param name="point">平面坐标系下的点</param> /// <param name="factoryCodeFrom"></param> /// <param name="factoryCodeTo">默认2000地理坐标系</param> public static void PointProjectedToGeographicOnArcGISPlatform(ref IPoint point,int factoryCodeFrom,int factoryCodeTo=4490 ) { ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference spatialReferenceFrom = spatialReferenceFactory.CreateProjectedCoordinateSystem(factoryCodeFrom); ISpatialReference spatialReferenceTo = spatialReferenceFactory.CreateGeographicCoordinateSystem(factoryCodeTo); IGeometry geometry = point as IGeometry; geometry.SpatialReference = spatialReferenceFrom; geometry.Project(spatialReferenceTo); }