private void btnOK_Click(object sender, EventArgs e) { try { if (this.txtConvertMethod.Tag != null) { esriTransformDirection direction; IGeoTransformation transformation; IGeoTransformationOperationSet geographicTransformations = (this.ibasicMap_0 as IMapGeographicTransformations).GeographicTransformations; IGeographicCoordinateSystem pFromGCS = (this.listBox1.SelectedItem as ObjectWrap).Object as IGeographicCoordinateSystem; IGeographicCoordinateSystem pToGCS = (this.cboTarget.SelectedItem as ObjectWrap).Object as IGeographicCoordinateSystem; geographicTransformations.Get(pFromGCS, pToGCS, out direction, out transformation); if (transformation != null) { geographicTransformations.Remove(direction, transformation); } geographicTransformations.Set(esriTransformDirection.esriTransformForward, this.txtConvertMethod.Tag as IGeoTransformation); geographicTransformations.Set(esriTransformDirection.esriTransformReverse, this.txtConvertMethod.Tag as IGeoTransformation); } } catch (Exception exception) { exception.ToString(); } base.DialogResult = DialogResult.OK; }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { this.btnNew.Enabled = this.listBox1.SelectedIndex != -1; if ((this.bool_0 && (this.listBox1.SelectedIndex != -1)) && (this.cboTarget.SelectedIndex != -1)) { IGeographicCoordinateSystem pFromGCS = (this.listBox1.SelectedItem as ObjectWrap).Object as IGeographicCoordinateSystem; IGeographicCoordinateSystem pToGCS = (this.cboTarget.SelectedItem as ObjectWrap).Object as IGeographicCoordinateSystem; IGeoTransformationOperationSet geographicTransformations = (this.ibasicMap_0 as IMapGeographicTransformations).GeographicTransformations; if (geographicTransformations != null) { esriTransformDirection direction; IGeoTransformation transformation; geographicTransformations.Get(pFromGCS, pToGCS, out direction, out transformation); if (transformation != null) { this.txtConvertMethod.Text = transformation.Name; this.txtConvertMethod.Tag = transformation; } else { this.txtConvertMethod.Text = ""; this.txtConvertMethod.Tag = transformation; } } } }
private void CustomGT() { // Initialize a new spatial reference environment. // SpatialReferenceEnvironment is a singleton object and needs to use the Activator class. Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); System.Object obj = Activator.CreateInstance(factoryType); ISpatialReferenceFactory2 pSRF = obj as ISpatialReferenceFactory2; // Initialize and create the input and output coordinate systems. IProjectedCoordinateSystem2 pPCSin = new ESRI.ArcGIS.Geometry.ProjectedCoordinateSystemClass(); IProjectedCoordinateSystem2 pPCSout = new ESRI.ArcGIS.Geometry.ProjectedCoordinateSystemClass(); pPCSin = (IProjectedCoordinateSystem2)pSRF.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_Abidjan1987UTM_30N); pPCSout = (IProjectedCoordinateSystem2)pSRF.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_WGS1984UTM_30N); // Retrieve the geographic coordinate systems from the two projected // coordinate systems. IGeographicCoordinateSystem2 pGCSto = (IGeographicCoordinateSystem2)pPCSout.GeographicCoordinateSystem; IGeographicCoordinateSystem2 pGCSfrom = (IGeographicCoordinateSystem2)pPCSin.GeographicCoordinateSystem; // Initialize and create an appropriate geographic transformation. ICoordinateFrameTransformation pCFT = new CoordinateFrameTransformationClass(); pCFT.PutParameters(1.234, -2.345, 658.3, 4.3829, -2.48591, 2.18943, 2.48585); pCFT.PutSpatialReferences(pGCSfrom, pGCSto); pCFT.Name = "Custom GeoTran"; // The SpatialReferenceEnvironment has a GeoTransformationOperationSet that you // can use to maintain a list of active geographic transformations. // Once you add a geographic transformation to the operation set, many operations // can access the transformations. // Add the transformation to the operation set. IGeoTransformationOperationSet pGTSet = pSRF.GeoTransformationDefaults; // Always add a geographic transformation in both directions. pGTSet.Set(esriTransformDirection.esriTransformForward, pCFT); pGTSet.Set(esriTransformDirection.esriTransformReverse, pCFT); }
public static IPoint GetFitCurrentPosition(IMap pMap, ISpatialReference pSR) { IGeographicCoordinateSystem geographicCoordinateSystem; IGeographicCoordinateSystem system2; if (m_CurrentPosition.SpatialReference is IUnknownCoordinateSystem) { return(m_CurrentPosition); } if (pSR is IUnknownCoordinateSystem) { return(m_CurrentPosition); } if (m_CurrentPosition.SpatialReference is IProjectedCoordinateSystem) { geographicCoordinateSystem = (m_CurrentPosition.SpatialReference as IProjectedCoordinateSystem).GeographicCoordinateSystem; } else { geographicCoordinateSystem = m_CurrentPosition.SpatialReference as IGeographicCoordinateSystem; } if (pSR is IProjectedCoordinateSystem) { system2 = (pSR as IProjectedCoordinateSystem).GeographicCoordinateSystem; } else { system2 = pSR as IGeographicCoordinateSystem; } IPoint point = (m_CurrentPosition as IClone).Clone() as IPoint; IGeoTransformationOperationSet geographicTransformations = (pMap as IMapGeographicTransformations).GeographicTransformations; if (geographicTransformations != null) { esriTransformDirection direction; IGeoTransformation transformation; geographicTransformations.Get(geographicCoordinateSystem, system2, out direction, out transformation); if (transformation != null) { (point as IGeometry2).ProjectEx(pSR, direction, transformation, true, 10.0, 10.0); } else { (point as IGeometry2).Project(pSR); } } return(point); }
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); }