private void Projectionbutton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.textBox1.Text)) { MessageBox.Show("请选择需要定义文件所在的目录"); return; } if (string.IsNullOrEmpty(this.textBox2.Text)) { MessageBox.Show("请选择坐标系文件"); return; } this.Projectionbutton.Enabled = false; var tool = new ProjectionClass() { Folder = this.textBox1.Text, CoordinateFile = this.textBox2.Text, OutFolder = this.textBox3.Text }; if (!tool.Work()) { MessageBox.Show(string.Format("失败!{0}", tool.Error)); } else { MessageBox.Show("Finish"); } this.Projectionbutton.Enabled = true; }
public SplinePlus() { SPData = CreateInstance(SPData); SPData.SplinePlus = this; SplineCreationClass = CreateInstance(SplineCreationClass); FollowerClass = CreateInstance(FollowerClass); TrainClass = CreateInstance(TrainClass); EventClass = CreateInstance(EventClass); GizmosClass = CreateInstance(GizmosClass); ProjectionClass = CreateInstance(ProjectionClass); SPData.Selections = CreateInstance(SPData.Selections); SPData.SmoothData = CreateInstance(SPData.SmoothData); SPData.SharedSettings = CreateInstance(SPData.SharedSettings); }
//将任意坐标系统转换为自定义Albers大地坐标(米) public static IPoint GeoToGra(IPoint point) { IPoint pt = new PointClass(); pt.PutCoords(point.X, point.Y); ISpatialReferenceFactory2 pFact = new SpatialReferenceEnvironmentClass(); //定义地理坐标,由输入的对象决定,也可以自己定义,参考: esriSRGeoCSType IGeographicCoordinateSystem pGCS = new GeographicCoordinateSystemClass(); pGCS = pFact.CreateGeographicCoordinateSystem(point.SpatialReference.FactoryCode); //自定义投影方式 IProjectedCoordinateSystem pProjectedCS = new ProjectedCoordinateSystemClass(); IProjectedCoordinateSystemEdit pProjectedCSEdit = pProjectedCS as IProjectedCoordinateSystemEdit; //定义投影方式,参考: esriSRProjectionType IProjection pProjection = new ProjectionClass(); pProjection = pFact.CreateProjection((int)esriSRProjectionType.esriSRProjection_Albers); //定义投影单位,参考:esriSRUnitType ILinearUnit pUnit = new LinearUnitClass(); pUnit = pFact.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit; //定义其他参数,参考:esriSRParameterType IParameter[] pParm = new IParameter[6]; pParm[0] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseEasting); pParm[0].Value = 0; pParm[1] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseNorthing); pParm[1].Value = 0; pParm[2] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_CentralMeridian); pParm[2].Value = 110; pParm[3] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel1); pParm[3].Value = 25; pParm[4] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel2); pParm[4].Value = 47; pParm[5] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_LatitudeOfOrigin); pParm[5].Value = 0; //设置投影相关信息 object name = "User_Defined_Albers"; object alias = "Albers"; object abbreviation = "Albers"; object remarks = "User_Defined_Albers is the projection"; object usage = ""; object gcs = pGCS; object projectedUnit = pUnit; object projection = pProjection; object parameters = pParm; pProjectedCSEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref gcs, ref projectedUnit, ref projection, ref parameters); //获取自定义空间参考 ISpatialReference pSpatialRef = pProjectedCS as ISpatialReference; IGeometry pGeometry = (IGeometry)pt; pGeometry.SpatialReference = pGCS as ISpatialReference; //重投影处理 pGeometry.Project(pSpatialRef); return pt; }
//将任意坐标系统转换为自定义Albers大地坐标(米) public static IPoint GeoToGra(IPoint point) { IPoint pt = new PointClass(); pt.PutCoords(point.X, point.Y); ISpatialReferenceFactory2 pFact = new SpatialReferenceEnvironmentClass(); //定义地理坐标,由输入的对象决定,也可以自己定义,参考: esriSRGeoCSType IGeographicCoordinateSystem pGCS = new GeographicCoordinateSystemClass(); pGCS = pFact.CreateGeographicCoordinateSystem(point.SpatialReference.FactoryCode); //自定义投影方式 IProjectedCoordinateSystem pProjectedCS = new ProjectedCoordinateSystemClass(); IProjectedCoordinateSystemEdit pProjectedCSEdit = pProjectedCS as IProjectedCoordinateSystemEdit; //定义投影方式,参考: esriSRProjectionType IProjection pProjection = new ProjectionClass(); pProjection = pFact.CreateProjection((int)esriSRProjectionType.esriSRProjection_Albers); //定义投影单位,参考:esriSRUnitType ILinearUnit pUnit = new LinearUnitClass(); pUnit = pFact.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit; //定义其他参数,参考:esriSRParameterType IParameter[] pParm = new IParameter[6]; pParm[0] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseEasting); pParm[0].Value = 0; pParm[1] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseNorthing); pParm[1].Value = 0; pParm[2] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_CentralMeridian); pParm[2].Value = 110; pParm[3] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel1); pParm[3].Value = 25; pParm[4] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel2); pParm[4].Value = 47; pParm[5] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_LatitudeOfOrigin); pParm[5].Value = 0; //设置投影相关信息 object name = "User_Defined_Albers"; object alias = "Albers"; object abbreviation = "Albers"; object remarks = "User_Defined_Albers is the projection"; object usage = ""; object gcs = pGCS; object projectedUnit = pUnit; object projection = pProjection; object parameters = pParm; pProjectedCSEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref gcs, ref projectedUnit, ref projection, ref parameters); //获取自定义空间参考 ISpatialReference pSpatialRef = pProjectedCS as ISpatialReference; IGeometry pGeometry = (IGeometry)pt; pGeometry.SpatialReference = pGCS as ISpatialReference; //重投影处理 pGeometry.Project(pSpatialRef); return(pt); }