📄 prjfileprop.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Display;
using System.Xml;
using System.IO;
using System.Xml.Serialization;
namespace ChangeXMLPrj
{
public class PrjFileProp
{
private string strWKT;
private ISpatialReference pSpatialRef = null;
public PrjFileProp(string prjfilename)
{
#region 需要featureclass的GDB
//#region 序列化图层对象
IWorkspaceFactory pwksf = new AccessWorkspaceFactoryClass();
IFeatureWorkspace pfwks = pwksf.OpenFromFile("Reuse.mdb", 0) as IFeatureWorkspace;
IFeatureClass pfdt = pfwks.OpenFeatureClass("refmz");
IFeatureLayer pfly = new FeatureLayerClass();
pfly.Name = "wda";
pfly.FeatureClass = pfdt as IFeatureClass;
//////序列化保存对象
this.SeriesObj(pfly);
//#endregion
//反序列话读取对象
IFeatureClass pfc= this.DisSeri();
if (pfc == null) return;
#endregion
ISpatialReferenceFactory2 psrfac = new SpatialReferenceEnvironmentClass();
pSpatialRef = psrfac.CreateESRISpatialReferenceFromPRJFile(prjfilename);
pSpatialRef = new UnknownCoordinateSystemClass();
IFeatureLayer pflyr = new FeatureLayerClass();
pflyr.FeatureClass = pfc;
pflyr.SpatialReference = pSpatialRef;
pSpatialRef =( pflyr as IGeoDataset ).SpatialReference;
IProjectedCoordinateSystem ipcs = pSpatialRef as IProjectedCoordinateSystem;
double zmax=0;
double zmin=1;
ISpatialReferenceResolution pspresolution = pSpatialRef as ISpatialReferenceResolution;
double dblxyresolu= pspresolution.get_XYResolution(true);
double dblzresolu = pspresolution.get_ZResolution(true);
double dblmresolu = pspresolution.MResolution;
///需要Alter中间FeatureClass层
pfwks.CreateFeatureDataset("hat5", pSpatialRef);
ISpatialReferenceTolerance psptollerance = pSpatialRef as ISpatialReferenceTolerance;
double dblxytolrance = psptollerance.XYTolerance;
double dblztolrance = psptollerance.ZTolerance;
double dblmtolrance = psptollerance.MTolerance;
if (pSpatialRef.HasMPrecision())
{
pSpatialRef.GetMDomain(out zmin, out zmax);
}
if (pSpatialRef.HasZPrecision())
{
pSpatialRef.GetZDomain(out zmin, out zmax);
}
if (pSpatialRef.HasXYPrecision())
{
double dx, dy, ax, ay;
ipcs.GetDomain(out dx,out dy ,out ax,out ay );
pSpatialRef.GetDomain(out dx,out dy ,out ax,out ay );
}
double a,b,c;
pSpatialRef.GetFalseOriginAndUnits(out a, out b, out c);
}
private void SeriesObj(IFeatureLayer plyr)
{
IXMLStream xstr=new XMLStreamClass();
IPersistStream ps = plyr as IPersistStream;
ps.Save(xstr as IStream , 0);
xstr.SaveToFile("featurelyr.xml");
}
private IFeatureClass DisSeri()
{
try
{
IXMLStream read = new XMLStreamClass();
read.LoadFromFile("featurelyr.xml");
IFeatureLayer plf = new FeatureLayerClass();
IPersistStream ppsrad = plf as IPersistStream;
ppsrad.Load(read as IStream);
string ss = plf.Name;
return plf.FeatureClass;
}
catch
{
return null;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -