如何实现经度纬度到平面坐标的相互转换(VB.net)
投影过程(C#):
/// flatref 投影的坐标系统,这里的54013是世界投影,世界投影所有经纬度都可以转换为平面坐标,但是由于投影面积大失真也会比较大(相当于把整个地球劈成一片片的,然后拉伸最后贴到平面上,失真当然大了)。当然也可以选择精度更高的平面如:esriSRProjCS_Beijing1954GK_23N
对应数值21483 仅仅把北京附近的地球平面拉伸铺在平面上,由于投影面积变小,所以投影经度提高。但是由于面积变小,所以有些经度纬度不能转换,比如所美国的精度纬度用北京投影就投不了。
flatref = pfactory.CreateProjectedCoordinateSystem(54013); //没什么说的,标准大地经纬度,可以将X-Y逆投影为经度和纬度
earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983); /// 将经纬度点转换为平面坐标。
private IPoint GetProject(double x, double y)
{
IPoint pt = new PointClass();
pt.PutCoords(x, y);
IGeometry geo = (IGeometry)pt;
geo.SpatialReference = earthref;
geo.Project(flatref); return pt;
} /// 将平面坐标转换为经纬度。
private IPoint GetGeo(double x, double y)
{
IPoint pt = new PointClass();
pt.PutCoords(x, y);
IGeometry geo = (IGeometry)pt;
geo.SpatialReference = flatref;
geo.Project(earthref);
double xx = pt.X;
return pt;
}
实际上IPoint的投影和任何地图都没什么大关系,完全可以不用地图,直接调用IPoint进行投影的转换
Private Function transformToProject(x As Double, y As Double) As IPoint
Dim pt As IPoint, geo As IGeometry
Dim pProjCoordSys As IProjectedCoordinateSystem
Dim pGCS As IGeographicCoordinateSystem
Dim pSpatRefFact As ISpatialReferenceFactory
'Set the spatial reference factory to a new spatial reference environment
Set pSpatRefFact = New SpatialReferenceEnvironment
Set pProjCoordSys = pSpatRefFact.CreateProjectedCoordinateSystem(esriSRProjCS_WGS1984UTM_47N)
Set pGCS = pSpatRefFact.CreateGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_NAD1983)
Set pt = New Point
pt.PutCoords x, y
Set geo = pt
Set geo.SpatialReference = pGCS
geo.Project pProjCoordSys
Set transformToProject = pt
End Function