經緯度和平面座標相互轉換
/// <summary>
/// 將經緯度點轉換為平面座標。
/// </summary>
/// <param name="map"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public static IPoint GetProject(IMap map, double x, double y)
{
try
{
IMap pMap = map;
IPoint pt = new PointClass();
ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
ISpatialReference flatref = pMap.SpatialReference;
ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
pt.PutCoords(x, y);
IGeometry geo = (IGeometry)pt;
geo.SpatialReference = earthref;
geo.Project(flatref);
return pt;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 將經緯度點轉換為平面座標點。
/// </summary>
/// <param name="map"></param>
/// <param name="point"></param>
/// <returns></returns>
public static IPoint GetProject(IMap map, IPoint point)
{
double x = point.X;
double y = point.Y;
try
{
IMap pMap = map;
IPoint pt = new PointClass();
ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
ISpatialReference flatref = pMap.SpatialReference;
ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
pt.PutCoords(x, y);
IGeometry geo = (IGeometry)pt;
geo.SpatialReference = earthref;
geo.Project(flatref);
return pt;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 將平面座標轉換為經緯度。
/// </summary>
/// <param name="map"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public static IPoint GetGeo(IMap map, double x, double y)
{
try
{
IMap pMap = map;
IPoint pt = new PointClass();
ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
ISpatialReference flatref = pMap.SpatialReference;
ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
pt.PutCoords(x, y);
IGeometry geo = (IGeometry)pt;
geo.SpatialReference = flatref;
geo.Project(earthref);
double xx = pt.X;
return pt;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 將平面座標點轉換為經緯度點。
/// </summary>
/// <param name="map"></param>
/// <param name="point"></param>
/// <returns></returns>
public static IPoint GetGeo(IMap map, IPoint point)
{
double x = point.X;
double y = point.Y;
try
{
IMap pMap = map;
IPoint pt = new PointClass();
ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
ISpatialReference flatref = pMap.SpatialReference;
ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
pt.PutCoords(x, y);
IGeometry geo = (IGeometry)pt;
geo.SpatialReference = flatref;
geo.Project(earthref);
double xx = pt.X;
return pt;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}