internal Class1(IGeoTransformation igeoTransformation_1, string string_1)
 {
     this.igeoTransformation_0 = null;
     this.string_0             = "";
     this.igeoTransformation_0 = igeoTransformation_1;
     this.string_0             = string_1;
 }
 /// <summary>
 /// 转换要素类的坐标系
 /// </summary>
 /// <param name="fileName">目标要素类的名字</param>
 /// <param name="savePath">存储目标要素类的路径</param>
 public void SpatialRefTrans(string fileName, string savePath)
 {
     //三个步骤完成坐标系的转换
     outFeatureClass   = CreateNewShpFile(inFeatureClass, fileName, savePath, spatialRefTo); //step.1 建立空的shpfile,以提供复制要素的空间
     geoTransformation = CreateSpatialRefTrans();                                            //step.2 创建坐标转换接口,为IGeometry2接口的ProjectEx()方法提供转换参数
     featureClassTransSpatialRef(inFeatureClass, outFeatureClass);                           //step.3 遍历待复制的要素类,复制图形和属性并改变图形的坐标系
 }
        protected override void OnClick()
        {
            IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
            IWorkspace        workspace        = workspaceFactory.OpenFromFile(@"C:\temp\data.gdb", 0);
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
            IFeatureClass     featureClass     = featureWorkspace.OpenFeatureClass("PolygonFC");

            ISpatialReferenceFactory3 spatialFact = new SpatialReferenceEnvironmentClass();
            IQueryFilter filter = new QueryFilterClass();

            filter.WhereClause = "";
            // The Geotransformation to use while performing the projection
            IGeoTransformation pGeoTransB = spatialFact.CreateGeoTransformation(
                (int)esriSRGeoTransformationType.esriSRGeoTransformation_NAD1983_To_WGS1984_1) as IGeoTransformation;
            // The target spatial reference. WGS_1984: WKID = 4326 (EPSG)
            ISpatialReference toSpatialReference = spatialFact.CreateSpatialReference(4326);
            //create the search cursor to go through each and every feature in the featureclass
            IFeatureCursor featureCursor = featureClass.Search(filter, true);
            IFeature       feature       = featureCursor.NextFeature();
            string         areaText      = null;

            while (feature != null)
            {
                // Project the feature (geometry) from its current coordinate system into the one specified (UTMz11N_WGS84)
                ((IGeometry5)feature.Shape).ProjectEx(toSpatialReference, esriTransformDirection.esriTransformReverse, pGeoTransB, false, 0.0, 0.0);
                IPolygon polygon = (IPolygon)feature.Shape;
                // Compute the area
                IArea area = polygon as IArea;
                // Build a string to output to a message box
                areaText += "OID = " + feature.OID + " , " + "Area =" + area.Area.ToString() + " \n";
                feature   = featureCursor.NextFeature();
            }
            MessageBox.Show(areaText);
            ArcMap.Application.CurrentTool = null;
        }
        public void GetAreaByProjectionAndGeoTransformationPerformanceTest()
        {
            IPolygon polygon = CreateTestPolygon();

            const int count = 100;
            IEnumerable <IPolygon> clones = GetClones(polygon, count);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            double area = 0;
            esriTransformDirection direction;
            IGeoTransformation     transformation = GetGeoTransformationToLv95(out direction);

            foreach (IPolygon clone in clones)
            {
                ((IGeometry5)clone).ProjectEx(_lv95, direction, transformation, false, 0, 0);
                area = ((IArea)clone).Area;
            }

            stopwatch.Stop();

            Console.WriteLine(@"Area: {0}", area);
            Console.WriteLine(@"{0:N2} ms per polygon", stopwatch.ElapsedMilliseconds / count);
        }
        //step.2 创建坐标转换接口,为IGeometry2接口的ProjectEx()方法提供转换参数
        /// <summary>
        /// 创建坐标转换接口,为IGeometry2接口的ProjectEx()方法提供转换参数
        /// </summary>
        /// <returns>返回根据坐标转换参数创建的坐标转换接口</returns>
        private IGeoTransformation CreateSpatialRefTrans()
        {
            //转换和待转换的坐标系
            IGeographicCoordinateSystem pGeoCoordSysFrom = (spatialRefFrom as IProjectedCoordinateSystem).GeographicCoordinateSystem;
            IGeographicCoordinateSystem pGeoCoordSysTo   = (spatialRefTo as IProjectedCoordinateSystem).GeographicCoordinateSystem;
            //定义转换参数
            ICoordinateFrameTransformation pCoordinateFrameTrans = new CoordinateFrameTransformationClass();

            pCoordinateFrameTrans.PutParameters(Tx, Ty, Tz, Rx, Ry, Rz, SD);
            pCoordinateFrameTrans.PutSpatialReferences(pGeoCoordSysFrom, pGeoCoordSysTo);
            pCoordinateFrameTrans.Name = TransName;
            //geoTransformationOperationSet.Set(esriTransformDirection.esriTransformForward, pCoordinateFrameTrans);
            geoTransformation = pCoordinateFrameTrans as IGeoTransformation;
            return(geoTransformation);
        }
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (this.cboTargetGCS.SelectedIndex == -1)
     {
         MessageBox.Show("请选择目标地理框架");
     }
     else if (this.txtSourGCS.Tag != null)
     {
         if (this.cboHCSTransformMethod.SelectedIndex == -1)
         {
             MessageBox.Show("请选择转转方法");
         }
         else if (this.txtName.Text.Trim().Length == 0)
         {
             MessageBox.Show("请输入新建地理坐标转转名称");
         }
         else
         {
             ISpatialReferenceFactory factory = new SpatialReferenceEnvironmentClass();
             ISpatialReference        to      = null;
             if (this.cboTargetGCS.SelectedIndex == 0)
             {
                 to = factory.CreateGeographicCoordinateSystem(4214);
             }
             else if (this.cboTargetGCS.SelectedIndex == 1)
             {
                 to = factory.CreateGeographicCoordinateSystem(4610);
             }
             else
             {
                 to = factory.CreateGeographicCoordinateSystem(4326);
             }
             if (this.igeoTransformation_1 != null)
             {
                 this.igeoTransformation_1.Name = this.txtName.Text.Trim();
             }
             else
             {
                 IGeoTransformation geoTransformation =
                     (this.cboHCSTransformMethod.SelectedItem as Class1).GeoTransformation;
                 geoTransformation.PutSpatialReferences(this.txtSourGCS.Tag as ISpatialReference, to);
                 geoTransformation.Name    = this.txtName.Text;
                 this.igeoTransformation_1 = geoTransformation;
             }
             base.DialogResult = DialogResult.OK;
         }
     }
 }
        private IGeoTransformation GetGeoTransformationToLv95(
            out esriTransformDirection direction)
        {
            IList <KeyValuePair <IGeoTransformation, esriTransformDirection> > transformations =
                SpatialReferenceUtils.GetPredefinedGeoTransformations(
                    _wgs84, _lv95);

            Assert.AreEqual(1, transformations.Count);

            IGeoTransformation transformation = transformations[0].Key;

            direction = transformations[0].Value;

            Console.WriteLine(@"{0} ({1})", transformation.Name, direction);

            return(transformation);
        }
Example #8
0
        public void ChangeCoordinateSystem1()
        {
            ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

            IGeoTransformationOperationSet geoTransformationOperationSet = spatialReferenceFactory.GeoTransformationDefaults;

            //NAD 1927 to WGS 1984 30.

            IGeoTransformation geoTransformation = spatialReferenceFactory.CreateGeoTransformation((int)

                                                                                                   esriSRGeoTransformationType.esriSRGeoTransformation_NAD1927_To_WGS1984_12) as IGeoTransformation;

            geoTransformationOperationSet.Set(esriTransformDirection.esriTransformForward, geoTransformation);

            geoTransformationOperationSet.Set(esriTransformDirection.esriTransformReverse, geoTransformation);

            //Amersfoort to WGS 1984.

            geoTransformation = spatialReferenceFactory.CreateGeoTransformation(8012) as IGeoTransformation;

            geoTransformationOperationSet.Set(esriTransformDirection.esriTransformForward, geoTransformation);

            geoTransformationOperationSet.Set(esriTransformDirection.esriTransformReverse, geoTransformation);



            ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

            //ESRI.ArcGIS.DataManagementTools.Project pro = new ESRI.ArcGIS.DataManagementTools.Project();
            //GP.OverwriteOutput = true;
            //pro.in_dataset = layer.FeatureClass;
            //pro.in_coor_system = pSpatialReference;
            //pro.out_coor_system = prjPath;
            //pro.out_dataset = outputPath;

            //GP.Execute(pro, null);
        }
Example #9
0
        /// <summary>
        /// Fills the datum transformations comobo box with the transforms applicable to the
        /// selected projection and WGS84.
        /// </summary>
        private void FillDatumTransform()
        {
            ISpatialReference sr = _transform.GetSpatialReference();

            if (sr != null)
            {
                IGeoTransformation trans = _transform.GetGeoTransform();
                if (trans != null)
                {
                    List <IGeoTransformation> transList = EsriUtilities.GetTransformations(sr);
                    comboBoxGeoTrans.DataSource    = transList;
                    comboBoxGeoTrans.DisplayMember = "Name";
                    comboBoxGeoTrans.SelectedIndex = comboBoxGeoTrans.FindString(trans.Name);
                    comboBoxGeoTrans.Enabled       = true;
                }
                else
                {
                    if (EsriUtilities.IsWGS84(sr))
                    {
                        comboBoxGeoTrans.DataSource = null;
                        comboBoxGeoTrans.Enabled    = false;
                    }
                    else
                    {
                        List <IGeoTransformation> transList = EsriUtilities.GetTransformations(sr);
                        comboBoxGeoTrans.DataSource    = transList;
                        comboBoxGeoTrans.DisplayMember = "Name";
                        comboBoxGeoTrans.Enabled       = true;
                    }
                }
            }
            else
            {
                comboBoxGeoTrans.DataSource = null;
                comboBoxGeoTrans.Enabled    = false;
            }
        }
Example #10
0
        /// <summary>
        /// Transforms an Point to a different coordinate system.
        /// </summary>
        /// <param name="inPoint">The Point to be Converted</param>
        /// <param name="inDataCoordinateSystem">The Coordinate System the point is currently in</param>
        /// <param name="inReturnCoordinateSystem">The coordinate System the point is to be returned into</param>
        /// <returns>A transformed point or null.</returns>
        public T ConvertToCoordinateSystem <T>(T inputGeometry, int inDataCoordinateSystem, ISpatialReference destSpatialReference) where T : IGeometry2
        {
            // Create source spatial reference

            ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference         sourceSpatialReference  = spatialReferenceFactory.CreateSpatialReference(inDataCoordinateSystem);

            if (destSpatialReference == null)
            {
                return(inputGeometry);
            }

            //cast T as IGeometry2 and project this.
            IGeometry2 geometry = inputGeometry as IGeometry2;

            if ((inDataCoordinateSystem == 27700) && (destSpatialReference.FactoryCode == 4326))
            {
                IGeoTransformation geoTransformation = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                geometry.ProjectEx(destSpatialReference as ISpatialReference, esriTransformDirection.esriTransformForward, geoTransformation, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 4326) && (destSpatialReference.FactoryCode == 27700))
            {
                IGeoTransformation geoTransformation = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                geometry.ProjectEx(destSpatialReference as ISpatialReference, esriTransformDirection.esriTransformReverse, geoTransformation, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 27700) && (destSpatialReference.FactoryCode == 102113))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass() as ICompositeGeoTransformation;
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, geoTransformation);                                         // National Grid to Wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, pGeoTrans_B);                                               // reversed sphere to wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 102113) && (destSpatialReference.FactoryCode == 27700))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass() as ICompositeGeoTransformation;
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, pGeoTrans_B);                                               // sphere to wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, geoTransformation);                                         // National Grid to Wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 27700) && (destSpatialReference.FactoryCode == 102100))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass();
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, geoTransformation);                                         // National Grid to Wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, pGeoTrans_B);                                               // reversed sphere to wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 102100) && (destSpatialReference.FactoryCode == 27700))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass();
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, pGeoTrans_B);                                               // sphere to wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, geoTransformation);                                         // National Grid to Wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }

            else if ((inDataCoordinateSystem == 27700) && (destSpatialReference.FactoryCode == 3857))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass();
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, geoTransformation);                                         // National Grid to Wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, pGeoTrans_B);                                               // reversed sphere to wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 3857) && (destSpatialReference.FactoryCode == 27700))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass();
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, pGeoTrans_B);                                               // sphere to wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, geoTransformation);                                         // National Grid to Wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }
            else
            {
                geometry.Project(destSpatialReference as ISpatialReference);
            }

            return(inputGeometry);
        }
 /// <summary>
 /// Sets the output projection for the transform to the one chosen here.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void comboBoxCoordSys_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         ISpatialReference         sr        = null;
         ISpatialReferenceFactory3 srFactory = new SpatialReferenceEnvironmentClass();
         if (comboBoxCoordSys.SelectedIndex == 4)
         {
             if (_map != null && _map.SpatialReference != null)
             {
                 sr           = _map.SpatialReference;
                 labelSR.Text = sr.Name;
             }
             else
             {
                 labelSR.Text = "";
             }
             buttonSR.Enabled = true;
             _transform.SetGeoTransform(null);
         }
         else
         {
             if (comboBoxCoordSys.SelectedIndex == 0)
             {
                 sr = srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                 _transform.SetGeoTransform(null);
             }
             else
             {
                 if (comboBoxCoordSys.SelectedIndex == 1)
                 {
                     sr = srFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_10N);
                 }
                 else if (comboBoxCoordSys.SelectedIndex == 2)
                 {
                     sr = srFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N);
                 }
                 else if (comboBoxCoordSys.SelectedIndex == 3)
                 {
                     sr = srFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_12N);
                 }
                 IGeoTransformation trans = null;
                 trans = (IGeoTransformation)srFactory.CreateGeoTransformation(
                     (int)esriSRGeoTransformationType.esriSRGeoTransformation_NAD1983_To_WGS1984_1);
                 _transform.SetGeoTransform(trans);
             }
             labelSR.Text     = "";
             buttonSR.Enabled = false;
         }
         _transform.SetSpatialReference(sr);
         if ((_map.SpatialReference == null) || !((IClone)_map.SpatialReference).IsEqual((IClone)sr))
         {
             _map.SpatialReference = sr;
             ArcMap.Document.ActiveView.Refresh();
         }
         FillDatumTransform();
         EnableSelectInputs();
     }
     catch (Exception ex)
     {
         ShowError(ex.Message);
     }
 }
Example #12
0
        /// <summary>
        /// Returns a projected copy of the geometry without altering the state of the original object.
        /// </summary>
        /// <typeparam name="T">The type of geometry.</typeparam>
        /// <param name="shape">The current geometry.</param>
        /// <param name="spatialReference">The target spatial reference.</param>
        /// <param name="transformation">The datum transformation.</param>
        /// <param name="direction">The direction of transformation.</param>
        /// <returns>A projected copy of the geometry.</returns>
        public static T Project2 <T>(this T shape, ISpatialReference spatialReference, IGeoTransformation transformation, esriTransformDirection direction) where T : class, IGeometry
        {
            var copy = shape.Copy();

            if (transformation == null)
            {
                copy.Project(spatialReference);
            }
            else
            {
                ((IGeometry2)copy).ProjectEx(spatialReference, direction, transformation, false, 0, 0);
            }

            return(copy);
        }