zoukankan      html  css  js  c++  java
  • 基于Arcgis Engine的坐标转换

    摘自:http://blog.csdn.net/kikitamoon/article/details/18408695

    根据arcgis中坐标系统的设置,实现坐标转换可能存在下面几种情况:

    1、

    不涉及到地理坐标系变换的坐标变换,这个参数完全不需要,而不是 optional 哦。

    例如:从 GCS_Xian_1980 进行投影变换,转换为 Xian_1980_3_Degree_GK_CM_120E 投影坐标系。

    整过转换中,仅使用了高斯克吕格投影变换,没有涉及到地理坐标变换。

    情景2:

    涉及到地理坐标系变换的坐标变换,并且ArcGIS 已知二者之间的变换方法,这个参数是必须的,在已知列表中做选择或者自定义。(自定义见:情景3)

    例如:从 GCS_Beijing_1954,转换为 GCS_WGS_1984坐标系。

    转换过程中涉及到地理坐标系变换,也就是进行了椭球体变换

    情景3:

    涉及到地理坐标系变换的坐标变换,并且ArcGIS 未知二者之间的变换方法,也就是ArcGIS没有提供转换方法,但是这个参数是必须的,需要自定义,这个参数前会亮绿灯,告诉用户,必须要填写。另外,上 面情景2中,ArcGIS给出的方法,如果都不是自己需要的,也需要自定义。

    例如:从 GCS_Beijing_1954,转换为 GCS_Xian_1980坐标系。

    而针对第三种应用在实际项目中用到的比较多。一般情况下catalog中自带的gp工具是可以在ae中调用的,但我研究过这个 Geogriphic Transformation实在找不到相应的参数怎么写,在catalog中操作时是先使用Create Custom Geographic Transformation工具创建自定义的坐标转换参数,然后再使用Project gp选择已建的转换方法及相关参数进行坐标转换。现使用arcgis engine实现。

    创建转换方式,使用七参的

     private IGeoTransformation CreateGeoTransformation(ISpatialReference pInputSR, ISpatialReference pOutputSR,SevenParameters parameters)
            {
                IGeoTransformation pGeoTrans;
                pGeoTrans = new CoordinateFrameTransformationClass();
    
                ((ICoordinateFrameTransformation)pGeoTrans).PutSpatialReferences(pInputSR, pOutputSR);
                ((ICoordinateFrameTransformation)pGeoTrans).PutParameters(parameters.dx,parameters.dy,parameters.dz,parameters.wx,parameters.wy,parameters.wz,parameters.ppm);
    
                return pGeoTrans;
            }

    实现转换:

    public void Project(IFeatureClass fromFeatureClass, string outPath, string outFileName, ISpatialReference inRe, ISpatialReference outRe, SevenParameters parameters, out string message)
            {
                message = "";
                try
                {
                    IWorkspaceFactory fac = new ShapefileWorkspaceFactoryClass();
                    IFeatureWorkspace toSpace = (IFeatureWorkspace)fac.OpenFromFile(outPath, 0);
    
                    IFields pFields = CreatFields(fromFeatureClass, outRe);
                    IFeatureClass toFeatureClass = toSpace.CreateFeatureClass(outFileName, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
    
                     IFeatureCursor pFC = fromFeatureClass.Search(null, false);
                    if (pFC == null) return;
                    IFeature fromFeature = pFC.NextFeature();
                    IFeatureCursor pFeatureCursor = null;
    
                    IGeoTransformation pCoordinateFrameTransformation = CreateGeoTransformation(inRe,outRe,parameters);
                    while (fromFeature != null)
                    {
                        IPointCollection toPC = new PolygonClass();
                        IGeometry2 pGeometry = (IGeometry2)fromFeature.ShapeCopy;
    
                        pGeometry.ProjectEx(outRe,esriTransformDirection.esriTransformForward,pCoordinateFrameTransformation,false,0,0);
    
                        pGeometry.SpatialReference = outRe;
                        pFeatureCursor = toFeatureClass.Insert(true);
                        IFeatureBuffer pf = toFeatureClass.CreateFeatureBuffer();
    
                        IFields fromFields = fromFeature.Fields;
                        IFields toFields = pf.Fields;
                        for (int i = 0; i < toFields.FieldCount; i++)
                        {
                            IField field = toFields.get_Field(i);
                            if (field.Name.ToUpper() == "SHAPE" || field.Name.ToUpper() == "OBJECTID" || field.Name.ToUpper() == "SHAPE_LENGTH" || field.Name.ToUpper() == "SHAPE_AREA" || field.Name.ToUpper() == "FID")
                            {
                                continue;
                            }
                            int index = fromFields.FindField(field.Name);
                            if (index == -1)
                            {
                                continue;
                            }
                            object o = fromFeature.get_Value(index);
                            if (o != null)
                                pf.set_Value(i, o);
                        }
                        pf.Shape = pGeometry;
                        pFeatureCursor.InsertFeature(pf);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pf);
                        fromFeature = pFC.NextFeature();
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFC);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
                }
                catch (Exception ex)
                { }
                finally
                {
                }
            }
  • 相关阅读:
    mysql索引
    mysql锁机制
    mysql授权
    mysql执行计划
    mysql知识补遗
    求助:springboot调用存储过程并使用了pagehelper分页时报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
    java面试题1
    Yarn
    MapRudecer
    Hive数据倾斜和解决办法
  • 原文地址:https://www.cnblogs.com/nygfcn1234/p/4260170.html
Copyright © 2011-2022 走看看