转载自http://www.blogbus.com/endlessmissing-logs/65641317.html
在搞AE开发的时候,经常碰到的一个问题就是不同坐标系统之间的转换,AE中IGlobeControl控件中提供了IGlobeViewUtil类实现了大地坐标、屏幕坐标和地理坐标三者之间的转换,IMapControl中则提供了ToMapPoint和FromMapPoint两种方法实现屏幕坐标和地理坐标之间的转换,但在实际开发中,这些转换还不够,比如当我们需要实现地理坐标转换到自定义格式的大地坐标时,上述方法则不能解决这些问题,最好的解决方法是使用IGeometry对象的Project方法,实现不同空间参照系之间的相互转换。以下以地理坐标转为自定义的Albers坐标系统为例予以说明,其主要用到的接口有ISpatialReferenceFactory、IProjectedCoordinateSystem、IProjectedCoordinateSystemEdit、ISpatialReferenceFactory、IGeographicCoordinateSystem 、ISpatialReference 等:
其C#代码如下:
//将任意坐标系统转换为自定义Albers大地坐标(米)
public static IPoint GeoToGra(IPoint point)
{
IPoint pt = new PointClass();
pt.PutCoords(point.X,point.Y);
ISpatialReferenceFactory2 pFact = new SpatialReferenceEnvironmentClass();
//定义地理坐标,由输入的对象决定,也可以自己定义,参考: esriSRGeoCSType
IGeographicCoordinateSystem pGCS = new GeographicCoordinateSystemClass();
pGCS = pFact.CreateGeographicCoordinateSystem(point.SpatialReference.FactoryCode);
//自定义投影方式
IProjectedCoordinateSystem pProjectedCS = new ProjectedCoordinateSystemClass();
IProjectedCoordinateSystemEdit pProjectedCSEdit = pProjectedCS as IProjectedCoordinateSystemEdit;
//定义投影方式,参考: esriSRProjectionType
IProjection pProjection = new ProjectionClass();
pProjection = pFact.CreateProjection((int)esriSRProjectionType.esriSRProjection_Albers);
//定义投影单位,参考:esriSRUnitType
ILinearUnit pUnit = new LinearUnitClass();
pUnit = pFact.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit;
//定义其他参数,参考:esriSRParameterType
IParameter[] pParm = new IParameter[6];
pParm[0] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseEasting);
pParm[0].Value = 0;
pParm[1] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseNorthing);
pParm[1].Value = 0;
pParm[2] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_CentralMeridian);
pParm[2].Value = 110;
pParm[3] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel1);
pParm[3].Value = 25;
pParm[4] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel2);
pParm[4].Value = 47;
pParm[5] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_LatitudeOfOrigin);
pParm[5].Value = 0;
//设置投影相关信息
object name = "User_Defined_Albers";
object alias = "Albers";
object abbreviation = "Albers";
object remarks = "User_Defined_Albers is the projection";
object usage = "";
object gcs = pGCS;
object projectedUnit = pUnit;
object projection = pProjection;
object parameters = pParm;
pProjectedCSEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref gcs, ref projectedUnit, ref projection, ref parameters);
//获取自定义空间参考
ISpatialReference pSpatialRef = pProjectedCS as ISpatialReference;
IGeometry pGeometry = (IGeometry)pt;
pGeometry.SpatialReference = pGCS as ISpatialReference;
//重投影处理
pGeometry.Project(pSpatialRef);
return pt;
}
//将平面坐标转换为地理坐标WGS1984(经纬度)
public static IPoint GetGeo(IGeometry pg)
{
IPoint pt = new PointClass();
pt.PutCoords(pg.Envelope.XMax, pg.Envelope.YMax); //这里IGeometry对象可换成IPoint等对象
ISpatialReferenceFactory2 spatialReferenceFact = new SpatialReferenceEnvironmentClass();
IGeometry geo = (IGeometry)pt;
geo.SpatialReference = spatialReferenceFact.CreateProjectedCoordinateSystem(pg.SpatialReference.FactoryCode);
ISpatialReference pSR = spatialReferenceFact.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
geo.Project(pSR);
return pt;
}
以上实现可以参考ESRI提供的相关帮助示例文档:
IProjectedCoordinateSystemEdit_Define_Example、CreateParameter_Example 、
ISpatialReferenceFactory_Example、CreateProjection_Example、CreateUnit_Example
CreateGeographicCoordinateSystem_Example、CreateProjectedCoordinateSystem_Example
自定义不同的坐标系统,需要设置不同的参数,所有的地图投影都必须有FalseEasting 和 FalseNorthing两个参数,每种不同投影的其他参数的参数如下所示,具体参照:IProjectedCoordinateSystemEdit Interface
Aitoff
CentralMeridian
Albers
CentralMeridian
StandardParallel1
StandardParallel2
LatitudeOfOrigin
Azimuthal_Equidistant
CentralMeridian
LatitudeOfOrigin
Behrmann
CentralMeridian
Bonne
CentralMeridian
StandardParallel1
Cassini
CentralMeridian
ScaleFactor
LatitudeOfOrigin
Craster_Parabolic
CentralMeridian
Cylindrical_Equal_Area
CentralMeridian
StandardParallel1
Double_Stereographic
CentralMeridian
ScaleFactor
LatitudeOfOrigin
Eckert_I
CentralMeridian
Eckert_II
CentralMeridian
Eckert_III
CentralMeridian
Eckert_IV
CentralMeridian
Eckert_V
CentralMeridian
Eckert_VI
CentralMeridian
Equidistant_Conic
CentralMeridian
StandardParallel1
StandardParallel2
LatitudeOfOrigin
Equidistant_Cylindrical
CentralMeridian
StandardParallel1
Flat_Polar_Quartic
CentralMeridian
Gall_Stereographic
CentralMeridian
Gauss_Kruger
CentralMeridian
ScaleFactor
LatitudeOfOrigin
Gnomonic
LongitudeOfCenter
LatitudeOfCenter
Hammer_Aitoff
CentralMeridian
Hotine_Oblique_Mercator_Azimuth_Center
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter
Hotine_Oblique_Mercator_Azimuth_Natural_Origin
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter
Hotine_Oblique_Mercator_Two_Point_Center
LatitudeOf1st
LatitudeOf2nd
ScaleFactor
LongitudeOf1st
LongitudeOf2nd
LatitudeOfCenter
Hotine_Oblique_Mercator_Two_Point_Natural_Origin
LatitudeOf1st
LatitudeOf2nd
ScaleFactor
LongitudeOf1st
LongitudeOf2nd
LatitudeOfCenter
Krovak
PseudoStandardParallel1
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter
XScaleFactor
YScaleFactor
Rotation
Lambert_Azimuthal_Equal_Area
CentralMeridian
LatitudeOfOrigin
Lambert_Conformal_Conic
CentralMeridian
StandardParallel1
StandardParallel2
ScaleFactor
LatitudeOfOrigin
Local
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter
Loximuthal
CentralMeridian
CentralParallel
Mercator
CentralMeridian
StandardParallel1
Miller_Cylindrical
CentralMeridian
Mollweide
CentralMeridian
New_Zealand_Map_Grid
LongitudeOfOrigin
LatitudeOfOrigin
Orthographic
LongitudeOfCenter
LatitudeOfCenter
Plate_Carree
CentralMeridian
Polyconic
CentralMeridian
LatitudeOfOrigin
Quartic_Authalic
CentralMeridian
Rectified_Skew_Orthomorphic_Center
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter
Rotation
Rectified_Skew_Orthomorphic_Natural_Origin
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter
Rotation
Robinson
CentralMeridian
Robinson_ARC_INFO
CentralMeridian
Sinusoidal
CentralMeridian
Stereographic
CentralMeridian
ScaleFactor
LatitudeOfOrigin
Stereographic_North_Pole
CentralMeridian
StandardParallel1
Stereographic_South_Pole
CentralMeridian
StandardParallel1
Times
CentralMeridian
Transverse_Mercator
CentralMeridian
ScaleFactor
LatitudeOfOrigin
Transverse_Mercator_Complex
CentralMeridian
ScaleFactor
LatitudeOfOrigin
Two_Point_Equidistant
LatitudeOf1st
LatitudeOf2nd
LongitudeOf1st
LongitudeOf2nd
Van_der_Grinten_I
CentralMeridian
Vertical_Near_Side_Perspective
LongitudeOfCenter
LatitudeOfCenter
Height
Winkel_I
CentralMeridian
StandardParallel1
Winkel_II
CentralMeridian
StandardParallel1
Winkel_Tripel
CentralMeridian
StandardParallel1