c++进行经纬度坐标与平面坐标转换(转)

时间:2024-03-05 22:51:22
原文地址:http://www.cnblogs.com/ayanmw/archive/2012/08/19.html
IPoint
* projToGeo(IPoint* point/*需要更改坐标系的点*/,long fromProjType=3857 ,long toGeoType=4326) { long geoType = toGeoType;//4326; IPoint* points = point; ISpatialReference* spatialRf; ISpatialReference* spatialRf1; IGeographicCoordinateSystem* geograpicsys; IProjectedCoordinateSystem*projCoordSystem; ISpatialReferenceFactoryPtr originalSpecialReference; ISpatialReferenceFactoryPtr newReferenceSystem; HRESULT hr = originalSpecialReference.CreateInstance(CLSID_SpatialReferenceEnvironment); HRESULT hr1 = originalSpecialReference->CreateProjectedCoordinateSystem(fromProjType,&projCoordSystem); spatialRf = (ISpatialReference*)projCoordSystem; HRESULT hr2 = points->putref_SpatialReference(spatialRf); newReferenceSystem.CreateInstance(CLSID_SpatialReferenceEnvironment); newReferenceSystem->CreateGeographicCoordinateSystem(geoType,&geograpicsys); spatialRf1 = (ISpatialReference*)geograpicsys; //points->putref_SpatialReference(spatialRf1);//这句不能要是设置原始 空间参考的。 points->Project(spatialRf1); ////测试输出而已//////////////////////// //double x,y; //points->get_X(&x); //points->get_Y(&y); //printf("x=%lf,y=%lf\n",x,y); /////////////////////////////////////// return points; };