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;
        }
示例#2
0
        public static IGeoTransformation GetGeographicToWebMercatorTransformation()
        {
            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

            // esriSRGeoTransformation_NAD1983_To_WGS1984_5	1515	United States.
            return(spatialReferenceFactory.CreateGeoTransformation((int)esriSRGeoTransformationType.esriSRGeoTransformation_NAD1983_To_WGS1984_5) as IGeoTransformation);
        }
示例#3
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);
        }
示例#4
0
        public IPoint ProjectWgsToUrkaine2000WithGeoTransformation(
            IPoint inputPoint,
            CoordinateSystemModel coordinateSystemModel,
            esriTransformDirection transformationDirection)
        {
            if (inputPoint == null)
            {
                return(null);
            }

            var bufferPoint = new PointClass {
                X = inputPoint.X, Y = inputPoint.Y, SpatialReference = inputPoint.SpatialReference
            };

            //Create Spatial Reference Factory
            var spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            var targetSpatialReference  = spatialReferenceFactory.CreateGeographicCoordinateSystem(coordinateSystemModel.ESRIWellKnownID);

            var compositeGeoTransformation  = new CompositeGeoTransformationClass();
            var predefinedGeoTransformation =
                spatialReferenceFactory.CreateGeoTransformation(Constants.ItrfToWgsGeoTransformationID) as IGeoTransformation;

            compositeGeoTransformation.Add(esriTransformDirection.esriTransformReverse, predefinedGeoTransformation);

            var coordinateFrameGeoTransformation = new CoordinateFrameTransformationClass();
            var itrfSpatialReference             =
                spatialReferenceFactory.CreateSpatialReference((int)esriSRGeoCS3Type.esriSRGeoCS_IERSTerrestrialReferenceFrame2000);

            coordinateFrameGeoTransformation.PutSpatialReferences(itrfSpatialReference, targetSpatialReference);
            coordinateFrameGeoTransformation.PutParameters(
                Constants.UkraineToItrf.XAxisTranslation,
                Constants.UkraineToItrf.YAxisTranslation,
                Constants.UkraineToItrf.ZAxisTranslation,
                Constants.UkraineToItrf.XAxisRotation,
                Constants.UkraineToItrf.YAxisRotation,
                Constants.UkraineToItrf.ZAxisRotation,
                Constants.UkraineToItrf.ScaleDifference);
            compositeGeoTransformation.Add(esriTransformDirection.esriTransformForward, coordinateFrameGeoTransformation);

            var geometry = bufferPoint as IGeometry5;

            geometry.ProjectEx(targetSpatialReference, transformationDirection, compositeGeoTransformation, false, 0.0, 0.0);

            return(geometry as IPoint);
        }
示例#5
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);
        }
示例#6
0
 public static IGeoTransformation GetGeographicToWebMercatorTransformation()
 {
     ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
     // esriSRGeoTransformation_NAD1983_To_WGS1984_5	1515	United States.
     return spatialReferenceFactory.CreateGeoTransformation((int)esriSRGeoTransformationType.esriSRGeoTransformation_NAD1983_To_WGS1984_5) as IGeoTransformation;
 }
 /// <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);
     }
 }