📄 opera.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.DataSourcesGDB;
namespace ChangeXMLPrj
{
public class opera
{
/// <summary>
/// 依据prj文件,获取有效投影参数
/// </summary>
/// <returns></returns>
public ISpatialReference getSpatialRefByPrjFile()
{
//OpenFileDialog ofg = new OpenFileDialog();
//ofg.Title = "投影坐标系文件";
//ofg.Filter = "投影文件(*.prj)|*.prj";
//ofg.Multiselect = false;
//ofg.RestoreDirectory = false;
//string path = Environment.GetEnvironmentVariable("ARCGISHOME");
////path = "";
//if (path != "")
//{
// path += @"Coordinate Systems\Projected Coordinate Systems";
//}
//else
//{
// path = Application.StartupPath + "\\..\\Data";
//}
//ofg.InitialDirectory = path;
//DialogResult dr = ofg.ShowDialog();
//string name = ofg.FileName;
//if (dr == DialogResult.OK && name != "")
//{
return alterspatialrefByPrj("WGS 1984 UTM Zone 24N.prj");
//}
//else
//{
// return null;
//}
//ofg = null;
}
public static string getPrjText()
{
StreamReader sr = new StreamReader("WGS 1984 UTM Zone 24N.prj");
string str= sr.ReadToEnd();
sr.Close();
str = str.Replace("\"", """);
return str ;
}
/// <summary>
/// 修改临时模板PGDB中的投影
/// </summary>
/// <param name="prjfilename">prj文件名</param>
/// <returns></returns>
private ISpatialReference alterspatialrefByPrj(string prjfilename)
{
try
{
ISpatialReferenceFactory2 psrfac = new SpatialReferenceEnvironmentClass();
ISpatialReference psrtmp = psrfac.CreateESRISpatialReferenceFromPRJFile(prjfilename);
IWorkspaceFactory pwkf = new AccessWorkspaceFactoryClass();
IWorkspace pwks = pwkf.OpenFromFile("Templete.mdb", 0);
IFeatureClass pfc = (pwks as IFeatureWorkspace).OpenFeatureClass("SRTemp");
IGeoDatasetSchemaEdit pgse = pfc as IGeoDatasetSchemaEdit;
pgse.AlterSpatialReference(psrtmp);
ISpatialReference psp = (pfc as IGeoDataset).SpatialReference;
pwks = null;
pwks = null;
return psp;
}
catch (Exception ex)
{
return null;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -