private ISpatialReference CreateSpatialReference(string strPrjString) { ISpatialReference temp_CreateSpatialReference = null; // create router spatial reference ISpatialReferenceFactory objSpatRefFact = null; objSpatRefFact = new SpatialReferenceEnvironmentClass(); // create temporary file string strTempPath = System.IO.Path.GetTempFileName(); try { System.IO.StreamWriter wrtr = System.IO.File.CreateText(strTempPath); wrtr.Write(strPrjString); wrtr.Close(); ISpatialReference objSR = null; objSR = objSpatRefFact.CreateESRISpatialReferenceFromPRJFile(strTempPath); temp_CreateSpatialReference = objSR; } finally { System.IO.File.Delete(strTempPath); } return temp_CreateSpatialReference; }
public static ISpatialReference CreateSpatialReference(this string strProFile) { ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(strProFile); return(pSpatialReference); }
private void advTreeCoord_NodeClick(object sender, TreeNodeMouseEventArgs e) { if (e.Node.Text.Contains(".prj") == true) { string fileFullPath = ""; string fileFullName = e.Node.Text; int depthIndex = e.Node.Level; Node curnode = new Node(); curnode = e.Node; for (int i = depthIndex; i > 1; i--) { fileFullName = curnode.Parent.Text + "\\" + fileFullName; curnode = curnode.Parent; } fileFullPath = ClsGDBDataCommon.GetParentPathofExe() + @"Resource\Coordinate Systems\" + fileFullName; ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass(); try { ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(fileFullPath); if (pSpatialReference == null) { return; } pSpaReference = pSpatialReference; richTextReference.Text = ClsGDBDataCommon.GetReferenceString(pSpatialReference); } catch (Exception ee) { MessageBox.Show(ee.Message); } } }
private void btnSelPrjFile_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "PRJ文件(*.prj)|*.prj"; if (dlg.ShowDialog() == DialogResult.OK) { ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass(); try { ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(dlg.FileName); if (pSpatialReference == null) { return; } pSpaReference = pSpatialReference; richTextReference.Text = ClsGDBDataCommon.GetReferenceString(pSpaReference); } catch (Exception ee) { MessageBox.Show(ee.Message); } } }
private ISpatialReference Get3857Sr() { ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); FileInfo projectionFile = new FileInfo("proj3857.prj"); FileInfo scalesFile = new FileInfo(ScalesFile); ISpatialReference spatialReference = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(projectionFile.FullName); return(spatialReference); }
public static ISpatialReference CreateSpatialReference(string strProj) { string prjfile = System.IO.Path.Combine(Application.StartupPath, "lsdata", DateTime.Now.ToString("HHmmss") + ".prj"); File.WriteAllText(prjfile, strProj); ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(prjfile); return(pSpatialReference); }
//功能描述: 从PRJ文件获取投影坐标系统 //参数列表: prj (string) public static ISpatialReference LoadPRJ(string sPrj) { ISpatialReferenceFactory2 pSpatRefFact = default(ISpatialReferenceFactory2); //pSpatRefFact = new SpatialReferenceEnvironment(); pSpatRefFact = new SpatialReferenceEnvironmentClass(); ISpatialReference pSpatRef = default(ISpatialReference); pSpatRef = pSpatRefFact.CreateESRISpatialReferenceFromPRJFile(sPrj); return(pSpatRef); }
/// <summary> /// 创建要素集 20110919 xisheng /// </summary> /// <param name="feaworkspace">指定工作空间</param> /// <param name="datasetname">指定要素集名称</param> /// <param name="PrjPath">空间参考</param> /// <returns></returns> private static IFeatureDataset CreateFeatureDataset(IFeatureWorkspace feaworkspace, string datasetname, string PrjPath) { try { string spatialPath = PrjPath; ISpatialReferenceFactory pSpaReferenceFac = new SpatialReferenceEnvironmentClass(); //空间参考工厂 ISpatialReference pSpatialReference = null; //用来获得空间参考 if (File.Exists(spatialPath)) { pSpatialReference = pSpaReferenceFac.CreateESRISpatialReferenceFromPRJFile(spatialPath); } if (pSpatialReference == null) { pSpatialReference = new UnknownCoordinateSystemClass(); } //设置默认的Resolution ISpatialReferenceResolution pSpatiaprefRes = pSpatialReference as ISpatialReferenceResolution; pSpatiaprefRes.ConstructFromHorizon();//Defines the XY resolution and domain extent of this spatial reference based on the extent of its horizon pSpatiaprefRes.SetDefaultXYResolution(); pSpatiaprefRes.SetDefaultZResolution(); pSpatiaprefRes.SetDefaultMResolution(); //设置默认的Tolerence ISpatialReferenceTolerance pSpatialrefTole = pSpatiaprefRes as ISpatialReferenceTolerance; pSpatialrefTole.SetDefaultXYTolerance(); pSpatialrefTole.SetDefaultZTolerance(); pSpatialrefTole.SetDefaultMTolerance(); //创建数据集 IFeatureDataset pFeatureDataset = null;//定义数据集用来装载要素类 pFeatureDataset = feaworkspace.CreateFeatureDataset(datasetname, pSpatialReference); return(pFeatureDataset); } catch (Exception e) { //******************************************************************* //guozheng added if (ModData.SysLog != null) { ModData.SysLog.Write(e, null, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write(e, null, DateTime.Now); } //******************************************************************** return(null); } }
/// <summary> /// 通过prj文件创建SpatialRef /// </summary> /// <param name="prjFile"></param> /// <returns></returns> public static ISpatialReference CreateSpatialRefByPrjFile(string prjFile) { try { ISpatialReferenceFactory srf = new SpatialReferenceEnvironmentClass(); ISpatialReference spaRef = srf.CreateESRISpatialReferenceFromPRJFile(prjFile); return(spaRef); } catch (Exception ex) { LOG.Error($"创建空间参考文件失败[{prjFile}]", ex); } return(null); }
/// <summary> /// 创建栅格空间参考 /// </summary> /// <param name="LoadPath">空间参考文件</param> /// <param name="eError"></param> /// <returns></returns> public ISpatialReference GetSpatialRef2(string LoadPath, out Exception eError) { eError = null; try { ISpatialReference pSR = null; ISpatialReferenceFactory pSpatialRefFac = new SpatialReferenceEnvironmentClass(); if (!File.Exists(LoadPath)) { //eError = new Exception("空间参考文件不存在!"); return(null); } pSR = pSpatialRefFac.CreateESRISpatialReferenceFromPRJFile(LoadPath); //ISpatialReferenceResolution pSRR = pSR as ISpatialReferenceResolution; //ISpatialReferenceTolerance pSRT = (ISpatialReferenceTolerance)pSR; //IControlPrecision2 pSpatialPrecision = (IControlPrecision2)pSR; //pSRR.ConstructFromHorizon();//Defines the XY resolution and domain extent of this spatial reference based on the extent of its horizon //pSRR.SetDefaultXYResolution(); //pSRT.SetDefaultXYTolerance(); return(pSR); } catch (Exception ex) { //******************************************************************* //guozheng added if (ModData.SysLog != null) { ModData.SysLog.Write(ex, null, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write(ex, null, DateTime.Now); } //******************************************************************** eError = ex; return(null); } }
public ISpatialReference CreateSpatialReferenceFromPRJFile(string sPRJFileName) { try { if (string.IsNullOrEmpty(sPRJFileName) | !File.Exists(sPRJFileName)) { Interaction.MsgBox("空间参考文件 " + sPRJFileName + " 丢失。", MsgBoxStyle.Exclamation, "创建空间参考错误"); return(null); } ISpatialReferenceFactory factory = null; factory = new SpatialReferenceEnvironmentClass(); ISpatialReference reference = null; reference = factory.CreateESRISpatialReferenceFromPRJFile(sPRJFileName); factory = null; return(reference); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.GeometryFun", "CreateSpatialReferenceFromPRJFile", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(null); } }
private void NewDatasetSpatialRefPage_Load(object sender, EventArgs e) { string[] directories; int num; TreeNode node2; string[] files; int num2; TreeNode node3; ISpatialReferenceFactory3 factory = new SpatialReferenceEnvironmentClass(); TreeNode node = new TreeNode("地理坐标系文件夹", 0, 1); this.treeView1.Nodes.Add(node); string startupPath = Application.StartupPath; string path = System.IO.Path.Combine(startupPath, @"Coordinate Systems\Geographic Coordinate Systems"); if (Directory.Exists(path)) { directories = Directory.GetDirectories(path); for (num = 0; num < directories.Length; num++) { node2 = new TreeNode(System.IO.Path.GetFileName(directories[num]), 0, 1); node.Nodes.Add(node2); files = Directory.GetFiles(directories[num]); num2 = 0; while (num2 < files.Length) { if (System.IO.Path.GetExtension(files[num2]).ToLower() == ".prj") { node3 = new TreeNode(System.IO.Path.GetFileName(files[num2]), 2, 2) { Tag = factory.CreateESRISpatialReferenceFromPRJFile(files[num2]) }; node2.Nodes.Add(node3); } num2++; } } } node = new TreeNode("投影坐标系文件夹", 0, 1); this.treeView1.Nodes.Add(node); path = System.IO.Path.Combine(startupPath, @"Coordinate Systems\Projected Coordinate Systems"); if (Directory.Exists(path)) { directories = Directory.GetDirectories(path); for (num = 0; num < directories.Length; num++) { node2 = new TreeNode(System.IO.Path.GetFileName(directories[num]), 0, 1); node.Nodes.Add(node2); string[] strArray3 = Directory.GetDirectories(directories[num]); for (int i = 0; i < strArray3.Length; i++) { TreeNode node4 = new TreeNode(System.IO.Path.GetFileName(strArray3[i]), 0, 1); node2.Nodes.Add(node4); files = Directory.GetFiles(strArray3[i]); for (num2 = 0; num2 < files.Length; num2++) { if (System.IO.Path.GetExtension(files[num2]).ToLower() == ".prj") { node3 = new TreeNode(System.IO.Path.GetFileName(files[num2]), 2, 2) { Tag = factory.CreateESRISpatialReferenceFromPRJFile(files[num2]) }; node4.Nodes.Add(node3); } } } } } node = new TreeNode("未知坐标系统", 2, 2) { Tag = SpatialReferenctOperator.ConstructCoordinateSystem( NewObjectClassHelper.m_pObjectClassHelper.Workspace as IGeodatabaseRelease) }; this.treeView1.Nodes.Add(node); }
public override void OnClick() { Exception eError = null; //FrmMathematicsCheck mFrmMathematicsCheck = new FrmMathematicsCheck(_AppHk, enumErrorType.数学基础正确性); //mFrmMathematicsCheck.ShowDialog(); FrmMathCheck pFrmMathCheck = new FrmMathCheck(); if (pFrmMathCheck.ShowDialog() == DialogResult.OK) { #region 错误日志保存 //错误日志连接信息 string logPath = TopologyCheckClass.GeoLogPath + "Log" + System.DateTime.Today.Year.ToString() + System.DateTime.Today.Month.ToString() + System.DateTime.Today.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString() + ".xls"; if (File.Exists(logPath)) { if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "日志文件\n'" + logPath + "'\n已经存在,是否替换?")) { File.Delete(logPath); } else { return; } } //生成日志信息EXCEL格式 SysCommon.DataBase.SysDataBase pSysLog = new SysCommon.DataBase.SysDataBase(); pSysLog.SetDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + logPath + "; Extended Properties=Excel 8.0;", SysCommon.enumDBConType.OLEDB, SysCommon.enumDBType.ACCESS, out eError); if (eError != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "日志信息表连接失败!"); return; } string strCreateTableSQL = @" CREATE TABLE "; strCreateTableSQL += @" 错误日志 "; strCreateTableSQL += @" ( "; strCreateTableSQL += @" 检查功能名 VARCHAR, "; strCreateTableSQL += @" 错误类型 VARCHAR, "; strCreateTableSQL += @" 错误描述 VARCHAR, "; strCreateTableSQL += @" 数据图层1 VARCHAR, "; strCreateTableSQL += @" 数据OID1 VARCHAR, "; strCreateTableSQL += @" 数据图层2 VARCHAR, "; strCreateTableSQL += @" 数据OID2 VARCHAR, "; strCreateTableSQL += @" 定位点X VARCHAR , "; strCreateTableSQL += @" 定位点Y VARCHAR , "; strCreateTableSQL += @" 检查时间 VARCHAR ,"; strCreateTableSQL += @" 数据文件路径 VARCHAR "; strCreateTableSQL += @" ) "; pSysLog.UpdateTable(strCreateTableSQL, out eError); if (eError != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "插入表头出错!"); pSysLog.CloseDbConnection(); return; } DataCheckClass dataCheckCls = new DataCheckClass(_AppHk); //将日志表连接信息和表名保存起来 dataCheckCls.ErrDbCon = pSysLog.DbConn; dataCheckCls.ErrTableName = "错误日志"; #endregion #region 获得要检查的IFeatureClass的集合 //将Mapcontrol上所有的图层名保存起来 List <IFeatureClass> LstFeaClass = new List <IFeatureClass>(); for (int i = 0; i < _AppHk.MapControl.LayerCount; i++) { ILayer player = _AppHk.MapControl.get_Layer(i); if (player is IGroupLayer) { ICompositeLayer pComLayer = player as ICompositeLayer; for (int j = 0; j < pComLayer.Count; j++) { ILayer mLayer = pComLayer.get_Layer(j); IFeatureLayer mfeatureLayer = mLayer as IFeatureLayer; if (mfeatureLayer == null) { continue; } IFeatureClass pfeaCls = mfeatureLayer.FeatureClass; if (!LstFeaClass.Contains(pfeaCls)) { LstFeaClass.Add(pfeaCls); } } } else { IFeatureLayer pfeatureLayer = player as IFeatureLayer; if (pfeatureLayer == null) { continue; } IFeatureClass mFeaCls = pfeatureLayer.FeatureClass; if (!LstFeaClass.Contains(mFeaCls)) { LstFeaClass.Add(mFeaCls); } } } #endregion if (_AppHk.DataTree == null) { return; } _AppHk.DataTree.Nodes.Clear(); //创建处理树图 IntialTree(_AppHk.DataTree); //设置树节点颜色 setNodeColor(_AppHk.DataTree); _AppHk.DataTree.Tag = false; string prjStr = pFrmMathCheck.PRJFNAME; if (prjStr == "") { return; } try { ISpatialReferenceFactory spatialRefFac = new SpatialReferenceEnvironmentClass(); ISpatialReference standardSpatialRef = spatialRefFac.CreateESRISpatialReferenceFromPRJFile(prjStr); for (int i = 0; i < LstFeaClass.Count; i++) { IFeatureClass pFeatureClass = LstFeaClass[i]; string pFeaClsNameStr = "";//图层名 pFeaClsNameStr = (pFeatureClass as IDataset).Name.Trim(); //创建树图节点(以图层名作为根结点) DevComponents.AdvTree.Node pNode = new DevComponents.AdvTree.Node(); pNode = (DevComponents.AdvTree.Node)CreateAdvTreeNode(_AppHk.DataTree.Nodes, pFeaClsNameStr, pFeaClsNameStr, _AppHk.DataTree.ImageList.Images[6], true);//图层名节点 //显示进度条 ShowProgressBar(true); int tempValue = 0; ChangeProgressBar((_AppHk as Plugin.Application.IAppFormRef).ProgressBar, 0, 1, tempValue); dataCheckCls.MathematicsCheck(pFeatureClass, standardSpatialRef, out eError); if (eError != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数学基础性正确检查失败。" + eError.Message); pSysLog.CloseDbConnection(); return; } tempValue += 1;//进度条的值加1 ChangeProgressBar((_AppHk as Plugin.Application.IAppFormRef).ProgressBar, -1, -1, tempValue); //改变树图运行状态 ChangeTreeSelectNode(pNode, "完成图层" + pFeaClsNameStr + "的数据基础性正确检查", false); } SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据检查完成!"); pSysLog.CloseDbConnection(); //隐藏进度条 ShowProgressBar(false); } catch (Exception ex) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", ex.Message); pSysLog.CloseDbConnection(); return; } } }
/// <summary> /// 创建一个要素集 /// </summary> private void CreateFeatureClass() { string path = txt_org.Text; string PRJFile = txt_prj.Text; AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass(); IFeatureWorkspace pFeatureWorkspace = pAccessFact.OpenFromFile(path, 0) as IFeatureWorkspace; ISpatialReferenceFactory2 Isp = new SpatialReferenceEnvironmentClass(); //创建一个空间参照的接口空间 ISpatialReference spatial = Isp.CreateESRISpatialReferenceFromPRJFile(PRJFile); //利用要素类的PRJ文件参照 ISpatialReferenceResolution pSRR = (ISpatialReferenceResolution)spatial; //设置分辨率 pSRR.SetDefaultXYResolution(); //设置默认XY值 ISpatialReferenceTolerance pSRT = (ISpatialReferenceTolerance)spatial; pSRT.SetDefaultXYTolerance();//设置默认容差值 IWorkspace space = pFeatureWorkspace as IWorkspace; IEnumDatasetName Dataset_name = space.get_DatasetNames(esriDatasetType.esriDTAny);//得到有多少个要素集合名字 Dataset_name.Reset(); IDatasetName Name_set = Dataset_name.Next(); while (Name_set != null) { if (Name_set.Name == "Geo_Topo_ice") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据集已存在,不用创建!"); this.Close();//如果要创建的数据集已存在,就返回,并关闭窗体 return; } Name_set = Dataset_name.Next(); } IFeatureDataset pfd = pFeatureWorkspace.CreateFeatureDataset("Geo_Topo_ice", spatial); //创建一个要素集 IEnumDataset dst = space.get_Datasets(esriDatasetType.esriDTAny); //得到所有的要素类的一个集合 dst.Reset(); IDataset det = dst.Next(); _AppHk.OperatorTips = "开始创建对应的要素类..."; while (det != null) { #region 给要素集创建空的要素类 if (det.Type == esriDatasetType.esriDTFeatureClass) //判定是不是要素类 { string org_name = det.Name; //原始的名字 _AppHk.OperatorTips = "开始创建" + org_name + "要素类..."; IFeatureClass f_class = pFeatureWorkspace.OpenFeatureClass(org_name); //打开源要素类 det.Rename(org_name + "_t"); //把源要素类进行重命名 IFields Fieldset = new FieldsClass(); //建立一个字段集 IFieldsEdit sField = Fieldset as IFieldsEdit; //字段集 if (f_class.FeatureType != esriFeatureType.esriFTAnnotation) { //shape IGeometryDefEdit d_edit; //定义一个用来接收要素类的SHAPE类型 d_edit = new GeometryDefClass(); //实例一个操作类 d_edit.GeometryType_2 = f_class.ShapeType; //将源要素类的SHAPE赋值给我们要创建的几何类型 d_edit.SpatialReference_2 = spatial; //空间参考 string OID = f_class.OIDFieldName; //ODI名字 string SHAPE = f_class.ShapeFieldName; //SHAPE名字 //IFields Fieldset = new FieldsClass();//建立一个字段集 //IFieldsEdit sField = Fieldset as IFieldsEdit;//字段集 //创建要素类里的字段 int count = f_class.Fields.FieldCount;//确定有多少个字段 #region 创建字段 for (int n = 0; n < count; n++) { IField f_ield = f_class.Fields.get_Field(n); IFieldEdit fieldEdit = f_ield as IFieldEdit; //Annotate if (f_ield.Name == SHAPE) { //shape field fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; //确定字段的类型 fieldEdit.GeometryDef_2 = d_edit; //把几何类型赋值给它 fieldEdit.Name_2 = SHAPE; //把几何类型SHPAE的名字赋值给它 f_ield = fieldEdit as IField; sField.AddField(f_ield); //加入要素集 } else if (f_ield.Name == OID) { //oid fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; //OID标识字段 fieldEdit.Name_2 = OID; //OID的名字 f_ield = fieldEdit as IField; sField.AddField(f_ield); //加入OID } else { //一般字段 fieldEdit.Name_2 = f_ield.Name; fieldEdit.Type_2 = f_ield.Type;//字段的类型 f_ield = fieldEdit as IField; sField.AddField(f_ield); } } #endregion Fieldset = sField as IFields; //将可编辑的字段集转成一般字段集 pfd.CreateFeatureClass(org_name, Fieldset, f_class.CLSID, null, esriFeatureType.esriFTSimple, SHAPE, ""); //给要素集中创建要素类 } else { createAnnoFeatureClass(org_name, pfd, pfd.Workspace as IFeatureWorkspace, sField, 2000); } det = dst.Next();//重新遍历下一个 } else { det = dst.Next();//重新遍历下一个 } #endregion } _AppHk.OperatorTips = "要素集合创建成功!"; GetValue(pFeatureWorkspace);//当对应的要素类建立好后,就开始给空要素类赋值 SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据处理完成!"); this.Close(); }
/// <summary> /// �����ռ�ο� /// </summary> /// <param name="headNode">VCTͷ�ڵ�</param> private ISpatialReference CreateProjection(HeadNode headNode) { try { string sPrjInfo = ""; //����ͶӰ�����еij�����ֵ�����ж���ʲô����ϵͳ������54������80��WGS��84�������ط�����ϵ�� //����54 double dMajorAxis = headNode.MajorMax.Y; //��ȡ�ο���������� �����ƣ������ᣬ���ʵĵ����� string sProjection = headNode.Spheroid.Split(',')[0]; dMajorAxis = Math.Abs(dMajorAxis - 6378245); //if (fabs( m_dSemiMajorAxis - 6378245) < 0.0001) if (dMajorAxis < 0.0001) { sPrjInfo = string.Format("PROJCS[\"{0}\",GEOGCS[\"GCS_Beijing_1954\",DATUM[\"D_Beijing_1954\"" + ",SPHEROID[\"{1}\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]," + "PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",{2}],PARAMETER[\"False_Northing\",0.0]," + "PARAMETER[\"Central_Meridian\",{3}],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0]," + "UNIT[\"Meter\",1.0]]", sProjection, "Gauss-Krueger", headNode.Excursion, headNode.Parametetor.OriginLongtitude); } //����80 else { // sPrjInfo = string.Format("PROJCS["%s\",GEOGCS[\"GCS_Xian_1980\",DATUM[\"D_Xian_1980\",SPHEROID[\"%s\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",%s],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",%f],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]", m_strProjection, m_strSpheroid, sPianYi, m_lMeridian); sPrjInfo = string.Format("PROJCS[\"{0}\",GEOGCS[\"GCS_Xian_1980\",DATUM[\"D_Xian_1980\"," + "SPHEROID[\"{1}\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]," + "PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",{2}],PARAMETER[\"False_Northing\",0.0]," + "PARAMETER[\"Central_Meridian\",{3}],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0]," + "UNIT[\"Meter\",1.0]]", sProjection, "Gauss-Krueger", headNode.Parametetor.EastOffset, headNode.Parametetor.OriginLongtitude); } //��������Ϣд�뵽Prj�ļ� string sPrjFilename = Application.StartupPath + "tempPrj.prj"; FileStream fs = File.Create(sPrjFilename); StreamWriter sw = new StreamWriter(fs); sw.Write(sPrjInfo); sw.Close(); fs.Close(); //����Prj�ļ����ɿռ�ο� ISpatialReferenceFactory ipSpatialFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference pSpatialReference = ipSpatialFactory.CreateESRISpatialReferenceFromPRJFile(sPrjFilename); pSpatialReference.SetDomain(headNode.MajorMin.X,headNode.MajorMax.X,headNode.MajorMin.Y,headNode.MajorMax.Y);// //���þ���,��ֹcutʧ�� //������λС�����ȡ��Ա�֤����ʱҲ����λ ISpatialReferenceTolerance ipSrTolerance = pSpatialReference as ISpatialReferenceTolerance; ipSrTolerance.XYTolerance = 0.000001; ipSrTolerance.MTolerance = 0.001; ipSrTolerance.ZTolerance = 0.001; ISpatialReferenceResolution ipSrResolution = pSpatialReference as ISpatialReferenceResolution; ipSrResolution.MResolution = 0.001; ipSrResolution.set_XYResolution(true, 0.000001); ipSrResolution.set_ZResolution(true, 0.001); //ɾ�����ɵ�Prj�ļ� File.Delete(sPrjFilename); //ISpatialReference pSpatialReference; //ISpatialReferenceFactory pSpatialreferenceFactory; //pSpatialreferenceFactory = new SpatialReferenceEnvironmentClass(); //IGeographicCoordinateSystem pGeographicCoordinateSystem; //pGeographicCoordinateSystem = pSpatialreferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCS3Type.esriSRGeoCS_Xian1980); //pSpatialReference = pGeographicCoordinateSystem as ISpatialReference; //pSpatialReference.SetFalseOriginAndUnits(-180, -90, 1000000);// return pSpatialReference; } catch (Exception ex) { LogAPI.WriteLog("�����ռ�ο�ʧ�ܣ�ϵͳĬ�ϴ����յĿռ�ο���\r\n"); LogAPI.WriteErrorLog(ex); ISpatialReference pSpatialReference = new UnknownCoordinateSystemClass(); pSpatialReference.SetDomain(headNode.MajorMin.X, headNode.MajorMax.X, headNode.MajorMin.Y, headNode.MajorMax.Y);// return pSpatialReference; } }
private void OnExecute() { Console.WriteLine(this.FeatureClassName); IWorkspaceFactory workspaceFactory = null; IWorkspace workspace = null; IFeatureClass featureClass = null; switch (DataSourceType) { case DataSourceType.Sde: { workspaceFactory = new SdeWorkspaceFactoryClass(); } break; case DataSourceType.Gdb: { workspaceFactory = new FileGDBWorkspaceFactoryClass(); } break; case DataSourceType.Shp: { workspaceFactory = new ShapefileWorkspaceFactoryClass(); } break; default: break; } workspace = workspaceFactory.OpenFromFile(DataSource, 0); featureClass = ((IFeatureWorkspace)workspace).OpenFeatureClass(FeatureClassName); IWorkspaceFactory outWorkspaceFactory = null; IWorkspace outWorkspace = null; IFeatureClass outFeatureClass = null; switch (OutDataSourceType) { case DataSourceType.Sde: { outWorkspaceFactory = new SdeWorkspaceFactoryClass(); } break; case DataSourceType.Gdb: { outWorkspaceFactory = new FileGDBWorkspaceFactoryClass(); } break; case DataSourceType.Shp: { outWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); } break; default: break; } outWorkspace = outWorkspaceFactory.OpenFromFile(OutDataSource, 0); outFeatureClass = ((IFeatureWorkspace)outWorkspace).OpenFeatureClass(OutFeatureClassName); ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); FileInfo projectionFile = new FileInfo(ProJectionFile); ISpatialReference spatialReference = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(projectionFile.FullName); FileInfo scalesFile = new FileInfo(ScalesFile); System.IO.FileStream fs = scalesFile.OpenRead(); StreamReader sr = new StreamReader(fs); string scalesString = sr.ReadToEnd(); var scales = scalesString.Split('\r').Where(str => double.TryParse(str, out var d)).Select(str => double.Parse(str)).ToArray(); sr.Close(); ; try { _indexOfFieldScale = outFeatureClass.FindField(FieldScale); } catch (Exception) { } try { _indexOfFieldFrame = outFeatureClass.FindField(FieldFrame); } catch (Exception) { } switch (Mode) { case Mode.Data: GenerateAnimationLines( featureClass: featureClass, outFeatureClass: outFeatureClass, spatialReference: Get3857Sr(), frameRate: FrameRate, lineLengthInPixel: LineLength, intervalInPixel: Interval); break; case Mode.Mxd: ModifyMxd(outFeatureClass, scales, spatialReference); break; default: break; } }
private void DoAttriAnalysis() { _Progress.SetProgress("分析叠置结果..."); Application.DoEvents(); ISpatialReferenceFactory pSpaFac = new SpatialReferenceEnvironmentClass(); ISpatialReference pSpaRef = pSpaFac.CreateESRISpatialReferenceFromPRJFile(_PrjFileName); IWorkspaceFactory pWSFact = new AccessWorkspaceFactoryClass(); IWorkspace pWorkspace = null; try { pWorkspace = pWSFact.OpenFromFile(_MdbPath + "\\" + _MdbName, 0); } catch { } if (pWorkspace == null) { return; } pSpaFac = null; pWSFact = null; IFeatureClass pInterFeaClass = (pWorkspace as IFeatureWorkspace).OpenFeatureClass(_IntersectName); IField pField = new FieldClass(); IFieldEdit pFieldEdit = pField as IFieldEdit; pFieldEdit.Name_2 = "jsmjtmp"; pFieldEdit.AliasName_2 = "计算面积"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; if (_Progress != null) { if (_Progress.UserAskCancel) { return; } } pInterFeaClass.AddField(pField); pField = null; int indexJSMJ = -1; indexJSMJ = pInterFeaClass.Fields.FindField("jsmjtmp"); _Progress.SetProgress("计算叠置结果的面积..."); Application.DoEvents(); IQueryFilter pFilter = new QueryFilterClass(); pFilter.WhereClause = "dl<>dl_1 or lz<>lz_1"; try { IFeatureCursor pCursor = pInterFeaClass.Search(pFilter, false); IFeature pFea = pCursor.NextFeature(); while (pFea != null) { if (_Progress != null) { if (_Progress.UserAskCancel) { return; } } IClone pClone = (IClone)pFea.Shape; IGeometry pGeo = pClone.Clone() as IGeometry; pGeo.Project(pSpaRef); IArea pArea = pGeo as IArea; if (pArea != null) { pFea.set_Value(indexJSMJ, pArea.Area); pFea.Store(); } pFea = pCursor.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor); pCursor = null; } catch { } _Progress.SetProgress("对叠置结果进行分析..."); Application.DoEvents(); if (_Progress != null) { if (_Progress.UserAskCancel) { return; } } //从叠置结果生成报表 string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _MdbPath + "\\" + _MdbName; OleDbConnection oledbconn = new OleDbConnection(connstr); oledbconn.Open(); OleDbCommand pCommand = oledbconn.CreateCommand(); ModTableFun.DropTable(oledbconn, "tmpBGJL"); pCommand.CommandText = "select shi,xian,xiang,cun,xbh,xbh_1,dl,dl_1,lz,lz_1,jsmjtmp into tmpBGJL from " + _IntersectName + " where dl<>dl_1 or lz<>lz_1"; pCommand.ExecuteNonQuery(); pCommand.CommandText = "delete from tmpBGJL where jsmjtmp<0.01"; pCommand.ExecuteNonQuery(); OleDbDataReader pReader = ModTableFun.GetReader(oledbconn, "select shi,xian,xiang,cun,xbh,dl_1,lz_1,dl,lz,round(jsmjtmp,2) from tmpBGJL"); FrmAnalysisResult pFrm = new FrmAnalysisResult(); DevComponents.DotNetBar.Controls.DataGridViewX pGrid = pFrm.ResultGrid; int intIndex = pGrid.Rows.Count; _Progress.SetProgress("准备展示分析结果..."); Application.DoEvents(); if (pReader == null) { return; } while (pReader.Read()) { if (_Progress != null) { if (_Progress.UserAskCancel) { oledbconn.Close(); return; } } try { pGrid.Rows.Add(pReader.GetValue(0).ToString(), pReader.GetValue(1).ToString(), pReader.GetValue(2).ToString(), pReader.GetValue(3).ToString(), pReader.GetValue(4).ToString(), pReader.GetValue(5).ToString(), pReader.GetValue(6).ToString(), pReader.GetValue(7).ToString(), pReader.GetValue(8).ToString(), pReader.GetValue(9).ToString()); intIndex++; } catch { } } pReader.Close(); oledbconn.Close(); oledbconn = null; _Progress.Close(); _Progress = null; pFrm.Show(); }
private void btnSelect_Click(object sender, EventArgs e) { System.Windows.Forms.OpenFileDialog flg = new OpenFileDialog(); flg.Filter = "�����ļ�(*prj)|*.prj"; string coordPath = Application.StartupPath + "\\����ϵͳ"; if (!System.IO.Directory.Exists(coordPath)) System.IO.Directory.CreateDirectory(coordPath); flg.InitialDirectory = coordPath; if (flg.ShowDialog() == DialogResult.OK) { ISpatialReferenceFactory SpRefFac = new SpatialReferenceEnvironmentClass(); ISpatialReference SpRef = SpRefFac.CreateESRISpatialReferenceFromPRJFile(flg.FileName); this.m_SpatialReferenceName = SpRef.Name; if (flg.FileName.Contains("�������ϵ")) { this.m_CurGeoCoord = SpRef as IGeographicCoordinateSystem; this.m_Datum = m_CurGeoCoord.Datum.Name; this.txtName.Text = m_CurGeoCoord.Name; this.LoadGeoCoord(true, this.m_CurGeoCoord); this.LoadFileContent(flg.FileName); } else if (flg.FileName.Contains("ƽ������ϵ")) { this.m_CurProCoord = SpRef as IProjectedCoordinateSystem; this.m_Datum = m_CurProCoord.GeographicCoordinateSystem.Datum.Name; this.txtName.Text = m_CurProCoord.Name; this.LoadProCoord(true, this.m_CurProCoord); this.LoadFileContent(flg.FileName); } } }
/// <summary> /// 创建空间参考 /// </summary> /// <param name="headNode">VCT头节点</param> private ISpatialReference CreateProjection(HeadNode headNode) { try { string sPrjInfo = ""; //根据投影参数中的长半轴值,来判断是什么坐标系统(北京54,西安80,WGS-84,其他地方坐标系) //北京54 double dMajorAxis = headNode.MajorMax.Y; //读取参考椭球的名称 (名称,长半轴,扁率的倒数) string sProjection = headNode.Spheroid.Split(',')[0]; dMajorAxis = Math.Abs(dMajorAxis - 6378245); //if (fabs( m_dSemiMajorAxis - 6378245) < 0.0001) if (dMajorAxis < 0.0001) { sPrjInfo = string.Format("PROJCS[\"{0}\",GEOGCS[\"GCS_Beijing_1954\",DATUM[\"D_Beijing_1954\"" + ",SPHEROID[\"{1}\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]," + "PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",{2}],PARAMETER[\"False_Northing\",0.0]," + "PARAMETER[\"Central_Meridian\",{3}],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0]," + "UNIT[\"Meter\",1.0]]", sProjection, "Gauss-Krueger", headNode.Excursion, headNode.Parametetor.OriginLongtitude); } //西安80 else { // sPrjInfo = string.Format("PROJCS["%s\",GEOGCS[\"GCS_Xian_1980\",DATUM[\"D_Xian_1980\",SPHEROID[\"%s\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",%s],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",%f],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]", m_strProjection, m_strSpheroid, sPianYi, m_lMeridian); sPrjInfo = string.Format("PROJCS[\"{0}\",GEOGCS[\"GCS_Xian_1980\",DATUM[\"D_Xian_1980\"," + "SPHEROID[\"{1}\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]," + "PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",{2}],PARAMETER[\"False_Northing\",0.0]," + "PARAMETER[\"Central_Meridian\",{3}],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0]," + "UNIT[\"Meter\",1.0]]", sProjection, "Gauss-Krueger", headNode.Parametetor.EastOffset, headNode.Parametetor.OriginLongtitude); } //将坐标信息写入到Prj文件 string sPrjFilename = Application.StartupPath + "tempPrj.prj"; FileStream fs = File.Create(sPrjFilename); StreamWriter sw = new StreamWriter(fs); sw.Write(sPrjInfo); sw.Close(); fs.Close(); //根据Prj文件生成空间参考 ISpatialReferenceFactory ipSpatialFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference pSpatialReference = ipSpatialFactory.CreateESRISpatialReferenceFromPRJFile(sPrjFilename); pSpatialReference.SetDomain(headNode.MajorMin.X,headNode.MajorMax.X,headNode.MajorMin.Y,headNode.MajorMax.Y);// //设置精度,防止cut失败 //设置六位小数精度。以保证导出时也是六位 ISpatialReferenceTolerance ipSrTolerance = pSpatialReference as ISpatialReferenceTolerance; ipSrTolerance.XYTolerance = 0.000001; ipSrTolerance.MTolerance = 0.001; ipSrTolerance.ZTolerance = 0.001; ISpatialReferenceResolution ipSrResolution = pSpatialReference as ISpatialReferenceResolution; ipSrResolution.MResolution = 0.001; ipSrResolution.set_XYResolution(true, 0.000001); ipSrResolution.set_ZResolution(true, 0.001); //删除生成的Prj文件 File.Delete(sPrjFilename); //ISpatialReference pSpatialReference; //ISpatialReferenceFactory pSpatialreferenceFactory; //pSpatialreferenceFactory = new SpatialReferenceEnvironmentClass(); //IGeographicCoordinateSystem pGeographicCoordinateSystem; //pGeographicCoordinateSystem = pSpatialreferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCS3Type.esriSRGeoCS_Xian1980); //pSpatialReference = pGeographicCoordinateSystem as ISpatialReference; //pSpatialReference.SetFalseOriginAndUnits(-180, -90, 1000000);// return pSpatialReference; } catch (Exception ex) { LogAPI.WriteLog("创建空间参考失败,系统默认创建空的空间参考!\r\n"); LogAPI.WriteErrorLog(ex); ISpatialReference pSpatialReference = new UnknownCoordinateSystemClass(); pSpatialReference.SetDomain(headNode.MajorMin.X, headNode.MajorMax.X, headNode.MajorMin.Y, headNode.MajorMax.Y);// return pSpatialReference; } }