//OK Loop public ZhFeatureClass GetZhFeatureClass(string featureClassName) { ZhFeatureClass ZHfeatcls = null; IFeatureClass fc = GetFeatureClass(featureClassName); if (fc != null) { switch (fc.ShapeType) { case esriGeometryType.esriGeometryPolygon: ZHfeatcls = new ZhPolygonFeatureClass(fc); break; case esriGeometryType.esriGeometryPolyline: case esriGeometryType.esriGeometryLine: ZHfeatcls = new ZhPolylineFeatureClass(fc); break; case esriGeometryType.esriGeometryPoint: case esriGeometryType.esriGeometryMultipoint: ZHfeatcls = new ZhPointFeatureClass(fc); break; } } return(ZHfeatcls); }
//---- private void RefreshSpatialReferenceText(string file) { this.textBox3.Text = ""; try { //首先获取文件名,文件路径及文件类型 string[] sArray = file.Split('\\'); string filename = sArray[sArray.Length - 1]; string url = ""; for (int i = 0; i < sArray.Length - 1; i++) { url = url + sArray[i] + "\\"; } string[] sFile = filename.Split('.'); string file_ext = ""; if (sFile.Length > 0) { file_ext = sFile[sFile.Length - 1]; } file_ext = file_ext.ToLower(); //---- ShapefileWorkspaceFactoryClass wsf = new ShapefileWorkspaceFactoryClass(); IWorkspace ws = wsf.OpenFromFile(url, 0); IFeatureWorkspace pFeatureWorkspace; pFeatureWorkspace = (IFeatureWorkspace)ws; IFeatureClass pFeatureClass = null; pFeatureClass = pFeatureWorkspace.OpenFeatureClass(filename); this.RefreshSpatialReferenceText(pFeatureClass); ZhFeatureClass zhfeaclass = new ZhPolygonFeatureClass(pFeatureClass); List <string> FieldNames = zhfeaclass.GetFieldNames(); this.CB_Fields.Items.Clear(); foreach (string fn in FieldNames) { this.CB_Fields.Items.Add(fn); } TokayWorkspace.ComRelease(pFeatureClass); pFeatureClass = null; TokayWorkspace.ComRelease(ws); ws = null; wsf = null; } catch (Exception ee) { this.textBox3.Text = ""; MessageBox.Show(ee.Message, "选择文件提示"); } }