private string CreateMxdFolderAndGDB(string fulPath, string docName) { //在指定文件夹中创建与地图文档同名的GDB,如果地图文档名称为空,创建与文件夹同名的GDB DirectoryInfo path = new DirectoryInfo(fulPath); if (path == null) { return(string.Empty); } if (!path.Exists) { path.Create(); } if (string.IsNullOrEmpty(docName)) { docName = path.Name; } else { docName = System.IO.Path.GetFileNameWithoutExtension(docName); } //创建GDB ClsGDBDataCommon cls = new ClsGDBDataCommon(); if (!cls.Create_FileGDB(path.FullName, docName)) { MessageBox.Show("创建数据库失败!"); return(string.Empty); } return(docName); }
private void btnPolygonDataset_Click(object sender, EventArgs e) { try { SaveFileDialog fbd = new SaveFileDialog(); fbd.Title = "新建File Geodatabase"; if (fbd.ShowDialog() == DialogResult.OK) { if (System.IO.Directory.Exists(fbd.FileName + ".gdb") == true) { MessageBox.Show("GDB已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass(); //IWorkspaceName workspaceName = workspaceFactory.Create(System.IO.Path.GetDirectoryName(fbd.FileName), System.IO.Path.GetFileName(fbd.FileName), null, 0); ClsGDBDataCommon com = new ClsGDBDataCommon(); com.Create_FileGDB(System.IO.Path.GetDirectoryName(fbd.FileName), System.IO.Path.GetFileName(fbd.FileName) + ".gdb"); IWorkspace pws = com.OpenFromFileGDB(fbd.FileName + ".gdb"); pFeatureDataset = creatdataset(pws, System.IO.Path.GetFileName(fbd.FileName), pMapControl.SpatialReference); creatfeatureclass(System.IO.Path.GetFileName(fbd.FileName)); txtPolygonDataset.Text = fbd.FileName + ".gdb"; } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } }
//public IFeatureDataset CreateFeatureDataset_Example(IWorkspace workspace, string fdsName, ISpatialReference fdsSR) //{ // IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; // return featureWorkspace.CreateFeatureDataset(fdsName, fdsSR); //} public void ConvertLabelsToGDBAnnotationSingleLayer(IMap pMap, bool featureLinked) //(IMap pMap, int layerIndex, bool featureLinked) { try { IConvertLabelsToAnnotation pConvertLabelsToAnnotation = new ConvertLabelsToAnnotationClass(); ITrackCancel pTrackCancel = new CancelTrackerClass(); //Change global level options for the conversion by sending in different parameters to the next line. pConvertLabelsToAnnotation.Initialize(pMap, esriAnnotationStorageType.esriDatabaseAnnotation, esriLabelWhichFeatures.esriAllFeatures, true, pTrackCancel, null); //ILayer pLayer = pMap.get_Layer(layerIndex); IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer; if (pGeoFeatureLayer != null) { IFeatureClass pFeatureClass = pGeoFeatureLayer.FeatureClass; IDataset pDataset = pFeatureClass as IDataset; IFeatureWorkspace pFeatureWorkspace = pDataset.Workspace as IFeatureWorkspace; //Add the layer information to the converter object. Specify the parameters of the output annotation feature class here as well. //if (pFeatureClass.FeatureDataset != null) //{ // pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer, // pGeoFeatureLayer.Name + "_Anno", pFeatureWorkspace, // pFeatureClass.FeatureDataset, featureLinked, false, false, true, true, ""); //} //else //{ //必须指定路径,默认存放到原有GDB中会造成无法第二次创建的问题 if (MessageBox.Show("请指定一个位置生成GeoDatabase存放注记图层", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { SaveFileDialog saveFileDlg = new SaveFileDialog(); saveFileDlg.DefaultExt = "gdb"; saveFileDlg.Filter = "(文件型数据库)*.gdb|*.gdb"; if (saveFileDlg.ShowDialog() == DialogResult.OK) { string strFileGDB = saveFileDlg.FileName; string strPath = System.IO.Path.GetDirectoryName(strFileGDB); string strName = System.IO.Path.GetFileName(strFileGDB); ClsGDBDataCommon com = new ClsGDBDataCommon(); com.Create_FileGDB(strPath, strName); string strfile = strPath + "\\" + strName; IWorkspace pws = com.OpenFromFileGDB(strfile); IFeatureDataset pdataset = creatdataset(pws, pLayer.Name + "Anno", pMap.SpatialReference); pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer, pGeoFeatureLayer.Name + "_Anno", (IFeatureWorkspace)pws, pdataset, featureLinked, false, false, true, true, ""); } } //} //Do the conversion. pConvertLabelsToAnnotation.ConvertLabels(); IEnumLayer pEnumLayer = pConvertLabelsToAnnotation.AnnoLayers; //Turn off labeling for the layer converted. pGeoFeatureLayer.DisplayAnnotation = false; //Add the result annotation layer to the map. pMap.AddLayers(pEnumLayer, true); //Refresh the map to update the display. IActiveView pActiveView = pMap as IActiveView; pActiveView.Refresh(); } } catch (System.Exception ex) { MessageBox.Show("该图层已存在注记图层", "提示", MessageBoxButtons.OK); } }