arcEngine 10 C++ 坐标转换【坐标系的投影】

搜索:arcengine C++ 坐标转换  ,百度 ,谷歌都没有类似的文章。arcEngine 换成 arcgis engine 效果一样。

好吧,这个重任就交给我吧。

有空了 研究好了 就写。

现在开始发功了:

直接上代码:

#include<ArcSDK.h>

//.....

    /*
     *地理坐标投影
     *http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/esriSRProjCS3Type_Constants/002m0000003n000000/
     * esriSRProjCS_WGS1984WebMercatorMajorAuxSphere , 3857 , WGS 1984 Web Mercator Major Auxilliary Sphere 
     *
    */
    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;
    };

在ArcEngine C++ 项目中,加上上面的函数,然后 调用就可以了。返回值 只是为了 链式调用,输入的点 已经被修改了。

测试代码:

    IPointPtr point1;
    HRESULT hr1 = point1.CreateInstance(CLSID_Point);
    point1->PutCoords(12698012.6530,2575437.9373);

    point1=projToGeo(point1);
    point1->get_X(&x);
    point1->get_Y(&y);
    printf("\t\t X=%lf,Y=%lf\n",x,y);

结果应该为 地理坐标系,大地坐标系:X=114.068188,Y=22.531326

这样就完成了 从 平面坐标系到大地坐标系/从投影坐标系到地理坐标系 的转换了。

如果想做 从地理到平面,也简单的,把 设置原始 空间参考 那句 改成 地理的就行了。

其中 有两个重要参数:long geoType,long projType

这俩值 是 代表对应 坐标系 的一个数字 ,可以从下面网站查询:

 # WGS_1984_Web_Mercator_Auxiliary_Sphere  #ID=3857

================================================================
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/esriSRProjCS3Type_Constants/002m0000003n000000/

esriSRProjCS_WGS1984WebMercatorMajorAuxSphere , 3857 , WGS 1984 Web Mercator Major Auxilliary Sphere

esriSRGeoCS_WGS1984 WGS 1984. #ID=4326
=====================================
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/esriSRGeoCSType_Constants/002m0000002t000000/

原文地址:https://www.cnblogs.com/ayanmw/p/2646917.html