/// <summary> /// 转换geometry为坐标串 /// </summary> /// <param name="geometry"></param> /// <param name="message">输出消息(目前是错误消息)</param> /// <returns>返回坐标串</returns> public static string ConvertGeometryToJson(IGeometry geometry, out string message) { string geomJsonStr = null; message = string.Empty; try { ITopologicalOperator topoGeom = geometry as ITopologicalOperator; topoGeom.Simplify(); if (topoGeom is IPolygon polygon) { polygon.Generalize(1); } if (geometry.SpatialReference == null || geometry.SpatialReference.Name == "Unknown") { geometry.SpatialReference = SpatialRefUtil.GetProjectedCoordinate(esriSRProjCS4Type.esriSRProjCS_Xian1980_3_Degree_GK_CM_120E); } ESRI.ArcGIS.esriSystem.IJSONWriter jsonWriter = new ESRI.ArcGIS.esriSystem.JSONWriterClass(); jsonWriter.WriteToString(); ESRI.ArcGIS.Geometry.JSONConverterGeometryClass jsonCon = new ESRI.ArcGIS.Geometry.JSONConverterGeometryClass(); jsonCon.WriteGeometry(jsonWriter, null, geometry, false); geomJsonStr = Encoding.UTF8.GetString(jsonWriter.GetStringBuffer()); } catch (Exception ex) { LOG.Error(ex); message = ex.ToString(); } return(geomJsonStr); }
/// <summary> /// 默认西安80坐标转换 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="sourceSpatialReference">原来点坐标的空间参考</param> /// <returns></returns> public static IPoint ProjectPoint(double x, double y, ISpatialReference sourceSpatialReference) { IPoint pPoint = new PointClass(); pPoint.PutCoords(x, y); pPoint.SpatialReference = sourceSpatialReference; ISpatialReference spatialReference_New = SpatialRefUtil.GetProjectedCoordinate(esriSRProjCS4Type.esriSRProjCS_Xian1980_3_Degree_GK_CM_120E); pPoint.Project(spatialReference_New); return(pPoint); }