//在数据集中创建要素 private void menuItem25_Click(object sender, System.EventArgs e) { CreateFClassInPDB(@"C:\ArcGIS\ArcTutor\BuildingaGeodatabase\Montgomery.mdb"); } public static void CreateFClassInPDB(string filePath){ string shapeFieldName="shape"; IFeatureWorkspace pFWS; try { pFWS=openPDB(filePath); //IEnumDataset pDatasets; //pDatasets=pWS.get_Datasets(esriDatasetType.esriDTFeatureDataset); IFeatureDataset pFeatureDataset=pFWS.OpenFeatureDataset("Water"); //MessageBox.Show(pFeatureDataset.Name); // IDataset pDataset=pDatasets.Next(); // IFeatureDataset pFeatureDataset=pDataset as IFeatureDataset; IGeoDataset pGeoDataset=pFeatureDataset as IGeoDataset; IFields pFields = null; IFieldsEdit pFieldsEdit = null; pFields = new FieldsClass(); pFieldsEdit=pFields as IFieldsEdit; pFieldsEdit.FieldCount_2=2; IField pField = null; IFieldEdit pFieldEdit = null; //Make the shape field it will need a geometry definition, with a spatial reference pField=new FieldClass(); pFieldEdit=pField as IFieldEdit; pFieldEdit.Name_2=shapeFieldName; pFieldEdit.Type_2=esriFieldType.esriFieldTypeGeometry; IGeometryDef pGeomDef = null; IGeometryDefEdit pGeomDefEdit = null; pGeomDef = new GeometryDefClass(); pGeomDefEdit =pGeomDef as IGeometryDefEdit; pGeomDefEdit.GeometryType_2=esriGeometryType.esriGeometryPolygon; pGeomDefEdit.SpatialReference_2=pGeoDataset.SpatialReference;//get the spatial reference pFieldEdit.GeometryDef_2=pGeomDefEdit; //pFieldsEdit.AddField(pField); pFieldsEdit.set_Field(0,pField); //Add another miscellaneous text field pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.Length_2=30; pFieldEdit.Name_2="TextField"; pFieldEdit.Type_2=esriFieldType.esriFieldTypeString; //pFieldsEdit.AddField(pField); pFieldsEdit.set_Field(1,pField); //pFeatureDataset.CreateFeatureClass("test",pFields,null,null,esriFeatureType.esriFTSimple,"Shape",""); UID pUID; pUID = new UIDClass(); pUID.Value="esriGeoDatabase.Feature"; //pFeatureDataset.CreateFeatureClass("test",pFields,pUID,null,esriFeatureType.esriFTSimple,"Shape",""); pFeatureDataset.CreateFeatureClass("test",pFields,pUID,null,esriFeatureType.esriFTSimple,"Shape",""); MessageBox.Show("创建成功"); } catch(Exception e){ MessageBox.Show(e.Message); } } //创建shapefile文件 public static void createShapeFile(String folderName,String shapeName){ if(folderName==""||shapeName=="") return; string shapeFieldName="shape"; try { IFeatureWorkspace pFWS = null; IWorkspaceFactory pWorkspaceFactory = null; pWorkspaceFactory = new Shapef ileWorkspaceFactoryClass(); //if(pWorkspaceFactory.IsWorkspace(folderName)==false) return; pFWS=pWorkspaceFactory.OpenFromFile(folderName,0) as IFeatureWorkspace; IFields pFields = null; IFieldsEdit pFieldsEdit = null; pFields = new FieldsClass(); pFieldsEdit=pFields as IFieldsEdit; IField pField = null; IFieldEdit pFieldEdit = null; //Make the shape field it will need a geometry definition, with a spatial reference pField=new FieldClass(); pFieldEdit=pField as IFieldEdit; pFieldEdit.Name_2=shapeFieldName; pFieldEdit.Type_2=esriFieldType.esriFieldTypeGeometry; IGeometryDef pGeomDef = null; IGeometryDefEdit pGeomDefEdit = null; pGeomDef = new GeometryDefClass(); pGeomDefEdit =pGeomDef as IGeometryDefEdit; pGeomDefEdit.GeometryType_2=esriGeometryType.esriGeometryPolygon; pGeomDefEdit.SpatialReference_2=new UnknownCoordinateSystemClass(); pFieldEdit.GeometryDef_2=pGeomDefEdit; pFieldsEdit.AddField(pField); //Add another miscellaneous text field pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.Length_2=30; pFieldEdit.Name_2="TextField"; pFieldEdit.Type_2=esriFieldType.esriFieldTypeString; pFieldsEdit.AddField(pField); IFeatureClass pFeatClass = null; pFeatClass = pFWS.CreateFeatureClass(shapeName, pFields, null, null,esriFeatureType.esriFTSimple, shapeFieldName, ""); MessageBox.Show("名为"+shapeName+"的shape文件创建成功"); } catch(Exception e){ MessageBox.Show(e.Message); } }
没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。
本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/6655669.html
,如需转载请自行联系原作者