基于ArcGIS10.0和Oracle10g的空间数据管理平台(C#开发)-AE常用操作代码

本来打算睡觉了,但是突然看到自己保留的一个单独的C#文件,原来是AE常用操作的代码,这也是自己在做ArcGIS空间数据管理平台的项目时积累下来的,这里贴出来供需要使用的人。
[csharp]  view plain copy
  1. /******************************************************** 
  2.  *  
  3.  * 本类部分功能接口依附于_workSpaceInstance 
  4.  * 必须首先使用CreateWorkspace或者OpenWorkspaceFromFile 
  5.  * 实例化_workSpaceInstance,才能使用 
  6.  * 
  7. ********************************************************/  
  8. using System;  
  9. using System.Windows.Forms;  
  10. using System.IO;  
  11. using System.Data;  
  12. using ESRI.ArcGIS.esriSystem;  
  13. using ESRI.ArcGIS.Geodatabase;  
  14. using ESRI.ArcGIS.Geometry;  
  15. using ESRI.ArcGIS.CatalogUI;  
  16.   
  17. namespace ControlLibrary  
  18. {  
  19.     class RuleDBCreater  
  20.     {  
  21.         private static IWorkspace _workSpaceInstance;  
  22.         public RuleDBCreater()  
  23.         {  
  24.             //  
  25.             // TODO: 在此处添加构造函数逻辑  
  26.             //  
  27.         }  
  28.   
  29.         public static void setWorkSpaceInstance(IWorkspace ws)  
  30.         {  
  31.             _workSpaceInstance = ws;  
  32.         }  
  33.   
  34.         public static IWorkspace getWorkSpaceInstance()  
  35.         {  
  36.             return _workSpaceInstance;  
  37.         }  
  38.         /// <summary>  
  39.         /// 创建规则数据库workspace  
  40.         /// </summary>  
  41.         /// <param name="workspaceType"></param>  
  42.         /// <param name="WorkspaceDirectory"></param>  
  43.         /// <returns>返回workspace实例</returns>  
  44.         public static IWorkspace CreateWorkspace(string pName, string pPath)  
  45.         {  
  46.             IWorkspaceFactory workspaceFactory = null;  
  47.             Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");  
  48.             workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);  
  49.             Directory.CreateDirectory(pPath);  
  50.             IWorkspaceName workspaceName = workspaceFactory.Create(pPath, pName,null, 0);  
  51.             IName Name = (IName)workspaceName;  
  52.             _workSpaceInstance = (IWorkspace)(Name.Open());  
  53.             return _workSpaceInstance;  
  54.         }  
  55.         /// <summary>  
  56.         /// 从文件创建规则数据库workspace  
  57.         /// </summary>  
  58.         /// <param name="WorkspaceDirectory"></param>  
  59.         /// <returns>返回workspace实例</returns>  
  60.         public static IWorkspace OpenWorkspaceFromFile(string WorkspaceDirectory)  
  61.         {  
  62.             IWorkspaceFactory workspaceFactory = null;  
  63.             Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");  
  64.             workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);  
  65.             _workSpaceInstance = workspaceFactory.OpenFromFile(WorkspaceDirectory, 0);  
  66.             return _workSpaceInstance;  
  67.         }  
  68.         /// <summary>  
  69.         /// 创建要素数据集  
  70.         /// </summary>  
  71.         /// <param name="name"></param>  
  72.         /// <returns>IFeatureDataset</returns>  
  73.         public static IFeatureDataset CreateFeatureDataSet(/*string name,ISpatialReference srf*/)  
  74.         {  
  75.             IFeatureDatasetDialog fdlg = new FeatureDatasetDefDialog();  
  76.             IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)_workSpaceInstance;  
  77.             return fdlg.DoModalCreate(featureWorkspace, 0);  
  78.             //if (_workSpaceInstance == null) return null;  
  79.             //IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)_workSpaceInstance;  
  80.             //IFeatureDataset tmp = featureWorkspace.CreateFeatureDataset(name, srf);  
  81.             //return tmp;  
  82.         }  
  83.         /// <summary>  
  84.         /// 删除要素数据集  
  85.         /// </summary>  
  86.         /// <param name="name"></param>  
  87.         /// <param name="srf"></param>  
  88.         /// <returns></returns>  
  89.         public static void DeleteFeatureDataSet(string name)  
  90.         {  
  91.             IFeatureDataset fds = GetFeatureDataSet(name);  
  92.             if (fds != null)  
  93.                 fds.Delete();  
  94.         }  
  95.         /// <summary>  
  96.         /// 获取数据库中IFeatureDataset  
  97.         /// </summary>  
  98.         /// <param name="name"></param>  
  99.         /// <returns></returns>  
  100.         public static IFeatureDataset GetFeatureDataSet(string name)  
  101.         {  
  102.             if (_workSpaceInstance == nullreturn null;  
  103.             IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)_workSpaceInstance;  
  104.             IFeatureDataset tmp = featureWorkspace.OpenFeatureDataset(name);  
  105.             return tmp;  
  106.         }  
  107.         /// <summary>  
  108.         /// 重命名DataSet  
  109.         /// </summary>  
  110.         /// <param name="fds"></param>  
  111.         /// <param name="newname"></param>  
  112.         public static void RenameFeatureDataSet(IFeatureDataset fds,string newname)  
  113.         {  
  114.             if (fds.CanRename())  
  115.             {  
  116.                 fds.Rename(newname);  
  117.             }  
  118.         }  
  119.         /// <summary>  
  120.         /// 获取IFeatureDataset空间参照  
  121.         /// </summary>  
  122.         /// <param name="ds"></param>  
  123.         /// <returns></returns>  
  124.         public static ISpatialReference GetFdsSpatialReference(IFeatureDataset ds)  
  125.         {  
  126.             IGeoDataset gds = ds as IGeoDataset;  
  127.             return gds.SpatialReference;  
  128.         }  
  129.         /// <summary>  
  130.         /// 设置IFeatureDataset空间参照  
  131.         /// </summary>  
  132.         /// <param name="ds"></param>  
  133.         /// <returns></returns>  
  134.         public static void SetFdsSpatialReference(IFeatureDataset ds)  
  135.         {  
  136.             IGeoDataset gds = ds as IGeoDataset;  
  137.             // Cast the geodataset to the IGeoDatasetSchemaEdit interface and set the Spatial Reference.      
  138.             IGeoDatasetSchemaEdit geoDatasetSchemaEdit = (IGeoDatasetSchemaEdit)gds;  
  139.             if (geoDatasetSchemaEdit.CanAlterSpatialReference)  
  140.             {  
  141.                 geoDatasetSchemaEdit.AlterSpatialReference(EditSpatialReferenceDlg(gds.SpatialReference));  
  142.             }  
  143.         }  
  144.         /// <summary>  
  145.         /// 创建属性字段  
  146.         /// </summary>  
  147.         /// <param name="shapeType"></param>  
  148.         /// <param name="dgrc"></param>  
  149.         /// <param name="spr"></param>  
  150.         /// <returns></returns>  
  151.         public static IFields CreateFields(string shapeType, DataTable dt, ISpatialReference spr,bool hasM,bool hasZ)  
  152.         {  
  153.             IField oField = new FieldClass();  
  154.             IFieldEdit oFieldEdit = oField as IFieldEdit;  
  155.             IFields oFields = new FieldsClass();  
  156.             IFieldsEdit oFieldsEdit = oFields as IFieldsEdit;  
  157.   
  158.             IGeometryDef geometryDef = new GeometryDefClass();  
  159.             IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;  
  160.   
  161.             foreach(DataRow dr in dt.Rows)  
  162.             {  
  163.                 switch (dr[1].ToString())  
  164.                 {  
  165.                     case "Object ID":  
  166.                         oFieldEdit.Name_2 = "ObjectID";  
  167.                         oFieldEdit.AliasName_2 = "FID";  
  168.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;  
  169.                         oFieldsEdit.AddField(oField);  
  170.                         break;  
  171.                     case "Multipoint Features":  
  172.                         oField = new FieldClass();  
  173.                         oFieldEdit = oField as IFieldEdit;  
  174.                         oFieldEdit.Name_2 = "SHAPE";  
  175.                         oFieldEdit.IsNullable_2 = true;  
  176.                         oFieldEdit.Required_2 = true;  
  177.   
  178.                         geometryDefEdit.AvgNumPoints_2 = 1;  
  179.                         geometryDefEdit.GridCount_2 = 0;  
  180.                         geometryDefEdit.HasM_2 = hasM;  
  181.                         geometryDefEdit.HasZ_2 = hasZ;  
  182.                         geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryMultipoint;  
  183.                         geometryDefEdit.SpatialReference_2 = spr;  
  184.   
  185.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;  
  186.                         oFieldEdit.GeometryDef_2 = (GeometryDef)geometryDefEdit;  
  187.                         oFieldsEdit.AddField(oField);  
  188.                         break;  
  189.                     case "MultiPatch Features":  
  190.                         oField = new FieldClass();  
  191.                         oFieldEdit = oField as IFieldEdit;  
  192.                         oFieldEdit.Name_2 = "SHAPE";  
  193.                         oFieldEdit.IsNullable_2 = true;  
  194.                         oFieldEdit.Required_2 = true;  
  195.                          
  196.                         geometryDef = new GeometryDefClass();  
  197.                         geometryDefEdit = geometryDef as IGeometryDefEdit;  
  198.                         geometryDefEdit.AvgNumPoints_2 = 1;  
  199.                         geometryDefEdit.GridCount_2 = 0;  
  200.                         geometryDefEdit.HasM_2 = hasM;  
  201.                         geometryDefEdit.HasZ_2 = hasZ;  
  202.                         geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryMultiPatch;  
  203.                         geometryDefEdit.SpatialReference_2 = spr;  
  204.   
  205.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;  
  206.                         oFieldEdit.GeometryDef_2 = (GeometryDef)geometryDefEdit;  
  207.                         oFieldsEdit.AddField(oField);  
  208.                         break;  
  209.                     case "Point Features":  
  210.                         oField = new FieldClass();  
  211.                         oFieldEdit = oField as IFieldEdit;  
  212.                         oFieldEdit.Name_2 = "SHAPE";  
  213.                         oFieldEdit.IsNullable_2 = true;  
  214.                         oFieldEdit.Required_2 = true;  
  215.   
  216.                         geometryDef = new GeometryDefClass();  
  217.                         geometryDefEdit = geometryDef as IGeometryDefEdit;  
  218.                         geometryDefEdit.AvgNumPoints_2 = 1;  
  219.                         geometryDefEdit.GridCount_2 = 0;  
  220.                         geometryDefEdit.HasM_2 = hasM;  
  221.                         geometryDefEdit.HasZ_2 = hasZ;  
  222.                         geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;  
  223.                         geometryDefEdit.SpatialReference_2 = spr;  
  224.   
  225.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;  
  226.                         oFieldEdit.GeometryDef_2 = (GeometryDef)geometryDefEdit;  
  227.                         oFieldsEdit.AddField(oField);  
  228.                         break;  
  229.                     case "Line Features":  
  230.                         oField = new FieldClass();  
  231.                         oFieldEdit = oField as IFieldEdit;  
  232.                         oFieldEdit.Name_2 = "SHAPE";  
  233.                         oFieldEdit.IsNullable_2 = true;  
  234.                         oFieldEdit.Required_2 = true;  
  235.               
  236.                         geometryDef = new GeometryDefClass();  
  237.                         geometryDefEdit = geometryDef as IGeometryDefEdit;  
  238.                         geometryDefEdit.AvgNumPoints_2 = 1;  
  239.                         geometryDefEdit.GridCount_2 = 0;  
  240.                         geometryDefEdit.HasM_2 = hasM;  
  241.                         geometryDefEdit.HasZ_2 = hasZ;  
  242.                         geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryLine;  
  243.                         geometryDefEdit.SpatialReference_2 = spr;  
  244.   
  245.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;  
  246.                         oFieldEdit.GeometryDef_2 = (GeometryDef)geometryDefEdit;  
  247.                         oFieldsEdit.AddField(oField);  
  248.                         break;  
  249.                     case "Polygon Features":  
  250.                         oField = new FieldClass();  
  251.                         oFieldEdit = oField as IFieldEdit;  
  252.                         oFieldEdit.Name_2 = "SHAPE";  
  253.                         oFieldEdit.IsNullable_2 = true;  
  254.                         oFieldEdit.Required_2 = true;  
  255.   
  256.                         geometryDef = new GeometryDefClass();  
  257.                         geometryDefEdit = geometryDef as IGeometryDefEdit;  
  258.                         geometryDefEdit.AvgNumPoints_2 = 1;  
  259.                         geometryDefEdit.GridCount_2 = 0;  
  260.                         geometryDefEdit.HasM_2 = hasM;  
  261.                         geometryDefEdit.HasZ_2 = hasZ;  
  262.                         geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;  
  263.                         geometryDefEdit.SpatialReference_2 = spr;  
  264.   
  265.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;  
  266.                         oFieldEdit.GeometryDef_2 = (GeometryDef)geometryDefEdit;  
  267.                         oFieldsEdit.AddField(oField);  
  268.                         break;  
  269.                     case "Short Int":  
  270.                         oField = new FieldClass();  
  271.                         oFieldEdit = oField as IFieldEdit;  
  272.                         oFieldEdit.Name_2 = dr[0].ToString();  
  273.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger;  
  274.                         oFieldEdit.IsNullable_2 = true;  
  275.                         oFieldsEdit.AddField(oField);  
  276.                         break;  
  277.                     case "Long Int":  
  278.                         oField = new FieldClass();  
  279.                         oFieldEdit = oField as IFieldEdit;  
  280.                         oFieldEdit.Name_2 = dr[0].ToString();  
  281.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;  
  282.                         oFieldsEdit.AddField(oField);  
  283.                         break;  
  284.                     case "Float":  
  285.                         oField = new FieldClass();  
  286.                         oFieldEdit = oField as IFieldEdit;  
  287.                         oFieldEdit.Name_2 = dr[0].ToString();  
  288.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSingle;  
  289.                         oFieldsEdit.AddField(oField);  
  290.                         break;  
  291.                     case "Double":  
  292.                         oField = new FieldClass();  
  293.                         oFieldEdit = oField as IFieldEdit;  
  294.                         oFieldEdit.Name_2 = dr[0].ToString();  
  295.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;  
  296.                         oFieldsEdit.AddField(oField);  
  297.                         break;  
  298.                     case "Text":  
  299.                         oField = new FieldClass();  
  300.                         oFieldEdit = oField as IFieldEdit;  
  301.                         oFieldEdit.Name_2 = dr[0].ToString();  
  302.                         oFieldEdit.Length_2 = 30; // Only string fields require that you set the length.  
  303.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;  
  304.                         oFieldsEdit.AddField(oField);  
  305.                         break;  
  306.                     case "Date":  
  307.                         oField = new FieldClass();  
  308.                         oFieldEdit = oField as IFieldEdit;  
  309.                         oFieldEdit.Name_2 = dr[0].ToString();  
  310.                         oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate;  
  311.                         oFieldsEdit.AddField(oField);  
  312.                         break;  
  313.                     //case "Guid":  
  314.                     //    IField fld12 = new FieldClass();  
  315.                     //    IFieldEdit fldedt12 = (IFieldEdit)fld12;  
  316.                     //    fldedt12.Name_2 = dr[0].ToString();  
  317.                     //    fldedt12.Type_2 = esriFieldType.esriFieldTypeGUID;  
  318.                     //    fieldsEdit.set_Field(i, fld12);  
  319.                     //    break;  
  320.                     //case "Geomery":  
  321.                     //    IField fld13 = new FieldClass();  
  322.                     //    IFieldEdit fldedt13 = (IFieldEdit)fld13;  
  323.                     //    fldedt13.Name_2 = dr[0].ToString();  
  324.                     //    fldedt13.IsNullable_2 = true;  
  325.                     //    fldedt13.Required_2 = true;  
  326.                     //    IGeometryDef geometryDef13 = new GeometryDefClass();  
  327.                     //    IGeometryDefEdit geometryDefEdit13 = (IGeometryDefEdit)geometryDef13;  
  328.                     //    geometryDef13 = new GeometryDefClass();  
  329.                     //    geometryDefEdit13 = (IGeometryDefEdit)geometryDef13;  
  330.                     //    geometryDefEdit13.AvgNumPoints_2 = 1;  
  331.                     //    geometryDefEdit13.GridCount_2 = 0;  
  332.                     //    geometryDefEdit13.HasM_2 = hasM;  
  333.                     //    geometryDefEdit13.HasZ_2 = hasZ;  
  334.                     //    fldedt13.Type_2 = esriFieldType.esriFieldTypeGeometry;  
  335.                     //    geometryDefEdit13.GeometryType_2 = esriGeometryType.esriGeometryAny;  
  336.                     //    //Generate a default Spatial Reference  
  337.                     //    geometryDefEdit13.SpatialReference_2 = spr;  
  338.                     //    fldedt13.GeometryDef_2 = (GeometryDef)geometryDefEdit13;  
  339.                     //    fldedt13.Type_2 = esriFieldType.esriFieldTypeGeometry;  
  340.                     //    fieldsEdit.set_Field(i, fld13);  
  341.                     //    break;  
  342.                     //case "Raster":  
  343.                     //    IField fld14 = new FieldClass();  
  344.                     //    IFieldEdit fldedt14 = (IFieldEdit)fld14;  
  345.                     //    fldedt14.Name_2 = dr[0].ToString();  
  346.                     //    fldedt14.Type_2 = esriFieldType.esriFieldTypeRaster;  
  347.                     //    fieldsEdit.set_Field(i, fld14);  
  348.                     //    break;  
  349.                 }  
  350.             }  
  351.             return oFields;  
  352.         }       
  353.         /// <summary>  
  354.         /// 创建要素类  
  355.         /// </summary>  
  356.         /// <param name="workspace"></param>  
  357.         /// <param name="featureDataset"></param>  
  358.         /// <param name="featureClassName"></param>  
  359.         /// <param name="fields"></param>  
  360.         /// <param name="CLSID"></param>  
  361.         /// <param name="CLSEXT"></param>  
  362.         /// <param name="strConfigKeyword"></param>  
  363.         /// <returns></returns>  
  364.         public static IFeatureClass CreateFeatureClass(IFeatureDataset featureDataset, String featureClassName, IFields fields)  
  365.         {  
  366.             if (_workSpaceInstance == nullreturn null;  
  367.             IFeatureClass featureClass = null;  
  368.             IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)_workSpaceInstance;   
  369.   
  370.             // assign the class id value if not assigned  
  371.             ESRI.ArcGIS.esriSystem.UID CLSID = null;  
  372.             ESRI.ArcGIS.esriSystem.UID CLSEXT = null;  
  373.             string strConfigKeyword = "";  
  374.             if (CLSID == null)  
  375.             {  
  376.                 CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();  
  377.                 CLSID.Value = "esriGeoDatabase.Feature";  
  378.             }  
  379.   
  380.             System.String strShapeField = "";  
  381.   
  382.             // locate the shape field  
  383.             for (Int32 j = 0; j < fields.FieldCount; j++)  
  384.             {  
  385.                 esriFieldType dd = fields.get_Field(j).Type;  
  386.                 if (dd == esriFieldType.esriFieldTypeGeometry)  
  387.                 {  
  388.                     strShapeField = fields.get_Field(j).Name;  
  389.                 }  
  390.             }  
  391.   
  392.             // finally create and return the feature class  
  393.             if (featureDataset != null)  
  394.             {  
  395.                 featureClass = featureDataset.CreateFeatureClass(featureClassName, fields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);  
  396.             }  
  397.               
  398.             return featureClass;  
  399.         }  
  400.         /// <summary>  
  401.         /// 获取FeatureClass从IFeatureDataset  
  402.         /// </summary>  
  403.         /// <param name="featDs"></param>  
  404.         /// <param name="className"></param>  
  405.         /// <returns></returns>  
  406.         public static IFeatureClass GetFeatureClassFromFeatureDataset(IFeatureDataset featDs, string className)  
  407.         {  
  408.             IFeatureClass featClass;  
  409.             IFeatureClassContainer fcContainer = featDs as IFeatureClassContainer;  
  410.             for (int i = 0; i < fcContainer.ClassCount; i++)  
  411.             {  
  412.                 featClass = fcContainer.get_Class(i);  
  413.                 if (RuleDBCreater.GetFeatureClassName(featClass) == className)  
  414.                 {  
  415.                     return featClass;  
  416.                 }  
  417.             }  
  418.             return null;  
  419.         }  
  420.         /// <summary>  
  421.         /// 重命名FeatureClass  
  422.         /// </summary>  
  423.         /// <param name="fds"></param>  
  424.         /// <param name="newname"></param>  
  425.         public static void RenameFeatureClass(IFeatureClass fc,string newname)  
  426.         {  
  427.             IDataset ds = fc as IDataset;  
  428.             if (ds.CanRename())  
  429.             {  
  430.                 ds.Rename(newname);  
  431.             }  
  432.         }  
  433.         /// <summary>  
  434.         /// 从数据集删除要素类  
  435.         /// </summary>  
  436.         /// <param name="featureDataset"></param>  
  437.         /// <param name="featureClassName"></param>  
  438.         /// <param name="fields"></param>  
  439.         /// <returns></returns>  
  440.         public static void DeleteFeatureClass(IFeatureDataset featureDataset, String featureClassName)  
  441.         {  
  442.             IFeatureClass fc = GetFeatureClassFromFeatureDataset(featureDataset, featureClassName);  
  443.             if (fc != null)  
  444.             {  
  445.                 IDataset ds = fc as IDataset;  
  446.                 if (ds.CanDelete())  
  447.                 {  
  448.                     ds.Delete();  
  449.                 }  
  450.             }  
  451.         }  
  452.         /// <summary>  
  453.         /// 编辑空间参照  
  454.         /// </summary>  
  455.         /// <param name="inputSpr"></param>  
  456.         /// <returns></returns>  
  457.         public static ISpatialReference EditSpatialReferenceDlg(ISpatialReference inputSpr)  
  458.         {  
  459.             ESRI.ArcGIS.CatalogUI.ISpatialReferenceDialog2 spatialReferenceDialog2 = new ESRI.ArcGIS.CatalogUI.SpatialReferenceDialogClass();  
  460.             ISpatialReference spf = spatialReferenceDialog2.DoModalEdit(inputSpr, falsefalsefalsefalsefalsefalsefalse, 0);  
  461.             return spf;  
  462.         }  
  463.         /// <summary>  
  464.         /// 创建空间参照  
  465.         /// </summary>  
  466.         /// <param name="coordinateSystem"></param>  
  467.         /// <returns></returns>  
  468.         public static ISpatialReference CreateSpatialReferenceDlg()//  
  469.         {  
  470.             ESRI.ArcGIS.CatalogUI.ISpatialReferenceDialog2 spatialReferenceDialog2 = new ESRI.ArcGIS.CatalogUI.SpatialReferenceDialogClass();  
  471.             ISpatialReference spatialReference = spatialReferenceDialog2.DoModalCreate(truefalsefalse, 0);  
  472.             //ISpatialReferenceTolerance spatialReferenceTolerance = spatialReference as ISpatialReferenceTolerance;  
  473.             return spatialReference;  
  474.         }  
  475.   
  476.         public static ISpatialReference SetXYZMTolerance(ISpatialReference srf,double xytolerance,double ztolerance,double mtolerance)  
  477.         {  
  478.             ISpatialReferenceTolerance spatialReferenceTolerance = srf as ISpatialReferenceTolerance;  
  479.             //spatialReferenceTolerance.XYTolerance = xytolerance;  
  480.             //spatialReferenceTolerance.ZTolerance = ztolerance;  
  481.             //spatialReferenceTolerance.MTolerance = mtolerance;  
  482.             return srf;  
  483.         }  
  484.   
  485.         public static void GetXYZMTolerance(ISpatialReference srf,out double xytolerance,out double ztolerance,out double mtolerance)  
  486.         {  
  487.             ISpatialReferenceTolerance spatialReferenceTolerance = srf as ISpatialReferenceTolerance;  
  488.             xytolerance = spatialReferenceTolerance.XYTolerance;  
  489.             ztolerance = spatialReferenceTolerance.ZTolerance;  
  490.             mtolerance = spatialReferenceTolerance.MTolerance;  
  491.         }  
  492.         /// <summary>  
  493.         /// 获取工作区内所有数据集名称  
  494.         /// </summary>  
  495.         /// <param name="ws"></param>  
  496.         /// <returns></returns>  
  497.         public static IEnumDatasetName GetFeatureDataSetNames(IWorkspace ws)  
  498.         {  
  499.             return ws.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);  
  500.         }  
  501.   
  502.         public static bool IsArcDbFile(string path)  
  503.         {  
  504.             IWorkspaceFactory workspaceFactory = null;  
  505.             Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");  
  506.             workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);  
  507.             return workspaceFactory.IsWorkspace(path);  
  508.         }  
  509.   
  510.         public static string GetFeatureClassName(IFeatureClass fc)  
  511.         {  
  512.             IDataset ds = fc as IDataset;  
  513.             return ds.Name;  
  514.         }  
  515.   
  516.         public static IEnumFeatureClass GetFeatureClasses(IFeatureDataset fds)  
  517.         {  
  518.             IFeatureClassContainer pFeatureclassContainer = (IFeatureClassContainer)fds;  
  519.             return (IEnumFeatureClass)pFeatureclassContainer.Classes;  
  520.         }  
  521.   
  522.         public static bool IsFeatureDataSetExist(string name)  
  523.         {  
  524.             //if (_workSpaceInstance == null) return true;  
  525.             IEnumDatasetName iEdn = GetFeatureDataSetNames(_workSpaceInstance);  
  526.             iEdn.Reset();  
  527.             IDatasetName iDsn = iEdn.Next();  
  528.             while (iDsn is IFeatureDatasetName)  
  529.             {  
  530.                 if (iDsn.Name == name)     
  531.                     return true;  
  532.                 iDsn = iEdn.Next();  
  533.             }  
  534.             return false;  
  535.         }  
  536.   
  537.         public static bool IsFeatureClassExist(string dsname, string fcname)  
  538.         {  
  539.             IEnumFeatureClass iEfc = GetFeatureClasses(GetFeatureDataSet(dsname));  
  540.             iEfc.Reset();  
  541.             IFeatureClass fcn = iEfc.Next();  
  542.             while (fcn is IFeatureClass)  
  543.             {  
  544.                 if (fcname == fcn.AliasName)  
  545.                     return true;  
  546.                 fcn = iEfc.Next();  
  547.             }  
  548.             return false;  
  549.         }  
  550.         /// <summary>  
  551.         /// 设置VerticalCoordinateSystem  
  552.         /// </summary>  
  553.         public static ISpatialReference3 SetVerticalCoordinateSystem(ISpatialReference3 spatialReference3)  
  554.         {  
  555.             ISpatialReferenceFactory3 spatialReferenceFactory3 = new SpatialReferenceEnvironmentClass();  
  556.             IVerticalCoordinateSystem verticalCoordinateSystem = spatialReferenceFactory3.CreateVerticalCoordinateSystem((int)esriSRVerticalCSType.esriSRVertCS_NAVD1988);  
  557.             spatialReference3.VerticalCoordinateSystem = verticalCoordinateSystem;  
  558.             return spatialReference3;  
  559.         }  
  560.     }  
  561. }  
  562. //public static bool IsNameValid(string str)  
  563. //{  
  564. //    System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z]\w{0,17}{1}quot;);  
  565. //    if (reg.IsMatch(s))  
  566. //    {  
  567. //        return true;  
  568. //    }  
  569. //    else  
  570. //    {  
  571. //        return false;  
  572. //    }  
  573. //}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值