//函数号: //函数名:LoadRasterToCatalogDatabase //函数功能:Raster导入Database //参数:pWorkspace:数据库,pWorkspace可以是Access 或者SDE // strCata:Catalog名称 // pRasterDs:需要入库的Rasterdataset //备注:insert a raster dataset with given path and file name to an existing raster catalog public void LoadRasterToCatalogDatabase(IWorkspace pWorkspace, string strCata, IRasterDataset pRasterDs, string name) { //QI IRasterWorkspaceEx to IWorkspace IRasterWorkspaceEx pRasWKS = pWorkspace as IRasterWorkspaceEx; //Open raster catalog //IRasterCatalog相当于一个FeatureClass(表),表中的每一个记录可以存放Raster IRasterCatalog pInCatalog = pRasWKS.OpenRasterCatalog(strCata); // get raster field index int iRaster = pInCatalog.RasterFieldIndex; // QI IFeatureClass for inserting IFeatureClass pFeatureClass = pInCatalog as IFeatureClass; // get insert cursor IFeatureCursor pCursor = pFeatureClass.Insert(false); // create raster value from raster dataset with default storagedef IRasterValue pRasterValue = new RasterValueClass(); pRasterValue.RasterDataset = pRasterDs; pRasterValue.RasterStorageDef = new RasterStorageDefClass(); pRasterValue.RasterDatasetName.NameString = name; //这里可以设置新的RasterStorageDef // insert the rastervalue ' it will update name, metadata and geometry field IFeatureBuffer pRow = pFeatureClass.CreateFeatureBuffer(); pRow.set_Value(iRaster, pRasterValue); pCursor.InsertFeature(pRow); }
//Open SDE RasterCatalog // Libraries needed to run the code: // ESRI.ArcGIS.esriSystem, ESRI.ArcGIS.Geodatabase, and ESRI.ArcGIS.DataSourcesGDB public IRasterCatalog OpenSDERasCata(string server, string instance, string database, string user, string password, string rasterCatalogName, string version) { // Open an ArcSDE raster Catalog with the given name // server, instance, database, user, password, version are database connection info // rasterCatalogName is the name of the raster Catalog //Open the ArcSDE workspace IPropertySet propertySet = new PropertySetClass(); propertySet.SetProperty("server", server); propertySet.SetProperty("instance", instance); propertySet.SetProperty("database", database); propertySet.SetProperty("user", user); propertySet.SetProperty("password", password); propertySet.SetProperty("version", version); // cocreate the workspace factory IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass(); // Open the raster workspace using the previously defined porperty set // and QI to the desired IRasterWorkspaceEx interface to access the existing catalog IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.Open(propertySet, 0) as IRasterWorkspaceEx; //Open the ArcSDE raster Catalog IRasterCatalog rasterCatalog = null; rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName); return(rasterCatalog); }
static void Mosaic(IRasterCatalog rasterCatalog) { try { //Mosaics all rasters in the raster catalog to an output raster dataset IMosaicRaster mosaicRaster = new MosaicRasterClass(); mosaicRaster.RasterCatalog = rasterCatalog; //Set mosaicking options, you may not need to set these for your data mosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH; mosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST; //Open output workspace IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass(); IWorkspace workspace = workspaceFactory.OpenFromFile(outputFolder, 0); //Save out to a target raster dataset //It can be saved to TIFF, IMG, GRID, BMP, GIF, JPEG2000, JPEG, Geodatabase, ect. ISaveAs saveas = (ISaveAs)mosaicRaster; saveas.SaveAs(outputName, workspace, "TIFF"); } catch (Exception exc) { Console.WriteLine(exc.Message); } }
public IList <RasterName> get_RasterDataSetNames() { IList <RasterName> names = new List <RasterName>(); if (this.m_workSpace != null) { IEnumDatasetName enumDatasetName = m_workSpace.get_DatasetNames(esriDatasetType.esriDTRasterCatalog); IDatasetName datasetName = enumDatasetName.Next();//DataSet的名字 IRasterWorkspaceEx rasterWorkspaceEx = m_workSpace as IRasterWorkspaceEx; while (datasetName != null) { RasterName name = new RasterName(); name.RasDCName = datasetName.Name.ToString(); IRasterCatalogName rasterCaName = (IRasterCatalogName)datasetName; IRasterCatalog rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(name.RasDCName); ITable table = rasterCatalog as ITable; ICursor cursor = table.Search(null, false); IRow row = cursor.NextRow(); while (row != null) { name.RDSName.Add(row.get_Value(cursor.FindField("NAME")).ToString()); row = cursor.NextRow(); } names.Add(name); datasetName = enumDatasetName.Next(); } } return(names); }
//RasterDataset to RasterCatalog public void RasDSToCatalog(IRasterDataset pRasterDs, IFeatureClass pCatalog) { //IRasterCatalogItem pCatalogFeature; IFeatureCursor pCursor; IFeatureBuffer pRow; pCursor = pCatalog.Insert(false); IRasterCatalog pCat = pCatalog as IRasterCatalog; IDataset pDs; // loop through all the datasets and load if (pRasterDs != null) { pDs = pRasterDs as IDataset; pRow = pCatalog.CreateFeatureBuffer(); pRow.set_Value(pCat.RasterFieldIndex, createRasterValue(pRasterDs)); /*try * { * pCursor.InsertFeature(pRow); * } * catch * { * * }*/ pCursor.InsertFeature(pRow); } //pCursor.Flush(); pRasterDs = null; }
public override void OnClick() { if (m_pCommand == null) { return; } (m_pCommand as GeoProperties.LayerPropertiesTool).CurLayer = _AppHk.MapControl.CustomProperty as ILayer; // shduan 20110721 增加RasterLayer和RasterCatalog图层属性************************* if (_AppHk.MapControl.CustomProperty is IFeatureLayer) { IFeatureLayer pFeatLayer = _AppHk.MapControl.CustomProperty as IFeatureLayer; IFeatureLayerDefinition pFLDefinition = pFeatLayer as IFeatureLayerDefinition; IFeatureClass pFeatClass = pFeatLayer.FeatureClass; } else if (_AppHk.MapControl.CustomProperty is IRasterLayer) { IRasterLayer pRasterLayer = _AppHk.MapControl.CustomProperty as IRasterLayer; } else if (_AppHk.MapControl.CustomProperty is IRasterCatalog) { IRasterCatalog pRC = _AppHk.MapControl.CustomProperty as IRasterCatalog; } //end ****************************************************************************** if (this.WriteLog) { Plugin.LogTable.Writelog("打开" + Message);//xisheng 2011.07.08 增加日志 } m_pCommand.OnClick(); }
/// <summary> /// 加载栅格库体 /// </summary> /// <param name="m_Hook">主程序hook</param> /// <param name="DbEleInfo">矢量库体对应的库体信息XmlElement</param> /// <param name="ex">输出错误信息</param> public static void AddRasterLayer(Plugin.Application.IAppDBIntegraRef m_Hook, XmlElement DbEleInfo, out Exception ex) { ex = null; try { IGroupLayer pGroupLayer = new GroupLayerClass(); pGroupLayer.Name = m_Hook.ProjectTree.SelectedNode.DataKeyString + "_" + m_Hook.ProjectTree.SelectedNode.Text; // string rasterDBType = (m_Hook.ProjectTree.SelectedNode.Tag as XmlElement).GetAttribute("存储类型"); // string rasterDBType = DbEleInfo.GetAttribute("存储类型"); string rasterDBType = string.Empty; XmlElement RasterEle = DbEleInfo.SelectSingleNode(".//栅格数据库") as XmlElement; rasterDBType = RasterEle.GetAttribute("存储类型").Trim(); XmlElement elementTemp = DbEleInfo.SelectSingleNode(".//栅格数据库/连接信息") as XmlElement; IWorkspace TempWorkSpace = ModDBOperate.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace; if (TempWorkSpace == null) { // SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接数据库失败!"); ex = new Exception("连接数据库失发生异常"); return; } IRasterWorkspaceEx pRasterWS = TempWorkSpace as IRasterWorkspaceEx; if (pRasterWS == null) { return; } string feaclsName = (elementTemp.FirstChild as XmlElement).GetAttribute("名称"); if (rasterDBType.Trim() == "栅格编目") { //栅格编目数据加载 IRasterCatalog pRasterCatalog = pRasterWS.OpenRasterCatalog(feaclsName); IGdbRasterCatalogLayer pGDBRCLayer = new GdbRasterCatalogLayerClass(); if (!pGDBRCLayer.Setup(pRasterCatalog as ITable)) { return; } IFeatureLayer mFeaLayer = pGDBRCLayer as IFeatureLayer; pGroupLayer.Add(mFeaLayer as ILayer); } else if (rasterDBType.Trim() == "栅格数据集") { //栅格数据集加载 IRasterDataset pRasterDataset = pRasterWS.OpenRasterDataset(feaclsName); IRasterLayer pRasterLayer = new RasterLayerClass(); pRasterLayer.CreateFromDataset(pRasterDataset); if (pRasterLayer == null) { return; } pGroupLayer.Add(pRasterLayer as ILayer); } m_Hook.MapControl.Map.AddLayer(pGroupLayer); } catch (Exception eError) { ex = eError; return; } }
private void button2_Click(object sender, EventArgs e) { if (this.listBox1.SelectedItems == null) { MessageBox.Show("请选择图幅名!"); return; } string sqlText = ""; for (int i = 0; i < this.listBox1.SelectedItems.Count; i++) { sqlText = "select name,DATASTRUCTURE from sheetmetadata where NAME='" + listBox1.SelectedItems[i] + "'"; m_oraCmd.CommandText = sqlText; OracleDataReader dr = m_oraCmd.ExecuteReader(); if (!dr.HasRows) { MessageBox.Show("图幅不存在!"); return; } while (dr.Read()) { // this.listBox1.Items.Add(dr.GetValue(0).ToString()); if (dr.GetValue(1).ToString() == "矢量") { IFeatureLayer feaLyr; feaLyr = m_gdata.AddFeatureClassToMap(dr.GetValue(0).ToString()); this.m_mapControl.Map.AddLayer(feaLyr); } if (dr.GetValue(1).ToString() == "影像") { IRasterWorkspaceEx rasterWS = m_workSpace as IRasterWorkspaceEx; IRasterCatalog rasterCatalog = rasterWS.OpenRasterCatalog("COASTALGIS." + dr.GetValue(1).ToString()); ITable table = rasterCatalog as ITable; ICursor cursor = table.Search(null, false); IRow row = cursor.NextRow(); IRasterDataset rasterDS = null; while (row != null) { IRasterCatalogItem rasterCatalogItem = row as IRasterCatalogItem; if (dr.GetValue(0).ToString() == row.get_Value(cursor.FindField("NAME")).ToString()) { rasterDS = rasterCatalogItem.RasterDataset; break; } row = cursor.NextRow(); } IRasterLayer rasterLayer = new RasterLayerClass(); rasterLayer.CreateFromDataset(rasterDS); this.m_mapControl.Map.AddLayer(rasterLayer); } } } }
public void ToRasterCatalog(IList ilist_0, IFeatureClass ifeatureClass_0) { IFeatureCursor featureCursor = ifeatureClass_0.Insert(false); IRasterCatalog ifeatureClass0 = ifeatureClass_0 as IRasterCatalog; for (int i = 0; i < ilist_0.Count; i++) { IRasterDataset rasterDataset = (ilist_0[i] as IName).Open() as IRasterDataset; IFeatureBuffer featureBuffer = ifeatureClass_0.CreateFeatureBuffer(); featureBuffer.Value[ifeatureClass0.RasterFieldIndex] = this.createRasterValue(rasterDataset); featureCursor.InsertFeature(featureBuffer); } }
//Open SDE RasterCatalog2 // Libraries needed to run the code: // ESRI.ArcGIS.esriSystem, ESRI.ArcGIS.Geodatabase, and ESRI.ArcGIS.DataSourcesGDB public IRasterCatalog OpenSDERasCata2(IWorkspace pWorkspace, string rasterCatalogName) { // Open the raster workspace using the previously defined porperty set // and QI to the desired IRasterWorkspaceEx interface to access the existing catalog IRasterWorkspaceEx rasterWorkspaceEx = pWorkspace as IRasterWorkspaceEx; //Open the ArcSDE raster Catalog IRasterCatalog rasterCatalog = null; rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName); return(rasterCatalog); }
/// <summary> /// 合并栅格目录中的所有栅格 /// </summary> /// <param name="pRasterCatalog"></param> /// <param name="outputFolder"></param> /// <param name="pOutputName"></param> public void Mosaic(IRasterCatalog pRasterCatalog, IWorkspace pWorkspace, string pOutputName) { IMosaicRaster pMosaicRaster = new MosaicRasterClass(); pMosaicRaster.RasterCatalog = pRasterCatalog; pMosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH; pMosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST; ISaveAs pSaveas = (ISaveAs)pMosaicRaster; pSaveas.SaveAs(pOutputName, pWorkspace, "IMAGINE Image"); }
public static void ToRasterCatalog(IList ilist_0, IFeatureClass ifeatureClass_0) { IFeatureCursor o = ifeatureClass_0.Insert(false); IRasterCatalog catalog = ifeatureClass_0 as IRasterCatalog; for (int i = 0; i < ilist_0.Count; i++) { IRasterDataset dataset = (ilist_0[i] as IName).Open() as IRasterDataset; IFeatureBuffer buffer = ifeatureClass_0.CreateFeatureBuffer(); buffer.set_Value(catalog.RasterFieldIndex, createRasterValue(dataset)); o.InsertFeature(buffer); } o.Flush(); ComReleaser.ReleaseCOMObject(o); }
//Open Personal Geodatabase RasterCatalog // ESRI.ArcGIS.Geodatabase, ESRI.ArcGIS.DataSourcesGDB public IRasterCatalog OpenPGDBRasterCatalog(string pathName, string rasterCatalogName) { // Open personal geodatabase raster catalog with the given name // pathName is the PGDB path (location of the personal geodatabase) // rasterCatalogName is the name of the raster catalog to be opened //Open the Access workspace IWorkspaceFactory2 workspaceFactory = new AccessWorkspaceFactoryClass(); IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.OpenFromFile(pathName, 0) as IRasterWorkspaceEx; //Open the PGDB raster Catalog IRasterCatalog rasterCatalog = null; rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName); return(rasterCatalog); }
public IRasterCatalog CreateRasterCat(string name, string sdePath) { ESRI.ArcGIS.Geoprocessor.Geoprocessor geoProcessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); CreateRasterCatalog createRasterCatalog = new CreateRasterCatalog(); IGPCoordinateSystem rSR = new GPCoordinateSystemClass(); IGPSpatialReference gSR = new GPSpatialReferenceClass(); rSR.SpatialReference = new UnknownCoordinateSystemClass(); gSR.SpatialReference = new UnknownCoordinateSystemClass(); createRasterCatalog.out_path = sdePath; createRasterCatalog.out_name = name; createRasterCatalog.raster_spatial_reference = (object)rSR; createRasterCatalog.spatial_reference = (object)gSR; geoProcessor.Execute(createRasterCatalog, null); IRasterCatalog rastercat = ((IRasterWorkspaceEx)this.m_workSpace).OpenRasterCatalog(name); return(rastercat); }
static void Main(string[] args) { ESRI.ArcGIS.esriSystem.AoInitialize aoInit = null; try { ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); aoInit = new AoInitializeClass(); esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic); Console.WriteLine("License Checkout successful."); } catch (Exception exc) { // If it fails at this point, shutdown the test and ignore any subsequent errors. Console.WriteLine(exc.Message); } try { //Create temporary unmanaged raster catalog and load all rasters CreateUnmanagedRasterCatalog(); //Open raster catalog IRasterWorkspaceEx rasterWorkspaceEx = (IRasterWorkspaceEx)OpenRasterPGDBWorkspace(tempPGDBPath); IRasterCatalog rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(tempRasterCatalog); //Mosaic rasters in the raster catalog Mosaic(rasterCatalog); } catch (Exception exc) { Console.WriteLine(exc.Message); } Console.Write("Please press any key to close the application."); Console.ReadKey(); //Do not make any call to ArcObjects after ShutDown() call aoInit.Shutdown(); }
//函数编号:Raster-08 //函数名: DirToGDB //函数功能:把一个空间中的所有RasterDataset对象全部存入IRasterCatalog的对象中。 //参数: // pWs:包含RasterDataset 的空间 // pCatalog:IRasterCatalog public void DirToGDB(IWorkspace pWs, IFeatureClass pCatalog) { //IRasterWorkspaceEx pSDERasterWs; // pEunmDatasets; //IRasterCatalogItem pCatalogFeature; IRasterDataset pRasterDs; //pCursor; IFeatureBuffer pRow; //get the list of datasets in the input workspace IEnumDataset pEunmDatasets = pWs.get_Datasets(esriDatasetType.esriDTRasterDataset); pEunmDatasets.Reset(); //load raster datasets from the input workspace pRasterDs = pEunmDatasets.Next() as IRasterDataset; IFeatureCursor pCursor = pCatalog.Insert(false); IRasterCatalog pCat = pCatalog as IRasterCatalog; IDataset pDs; //loop through all the datasets and load while (pRasterDs != null) { pDs = pRasterDs as IDataset; //StatusBar.Message(0) = "Loading " & pDs.Name & "......" pRow = pCatalog.CreateFeatureBuffer(); //pRow.set_Value(pCat.RasterFieldIndex , createRasterValue(pRasterDs)); pCursor.InsertFeature(pRow); pRasterDs = pEunmDatasets.Next() as IRasterDataset; } //cleanup pCatalog = null; //pSDERasterWs = null; pEunmDatasets = null; //pCatalogFeature = null; pRasterDs = null; }
public static IRasterCatalog createCatalog(IRasterWorkspaceEx irasterWorkspaceEx_0, string string_0, string string_1, string string_2, ISpatialReference ispatialReference_0, ISpatialReference ispatialReference_1, bool bool_0, IFields ifields_0, string string_3) { if (ifields_0 == null) { ifields_0 = createFields(string_1, string_2, bool_0, ispatialReference_0, ispatialReference_1); } if (string_3.Length == 0) { string_3 = "DEFAULTS"; } IRasterCatalog catalog = null; try { catalog = irasterWorkspaceEx_0.CreateRasterCatalog(string_0, ifields_0, string_2, string_1, string_3); } catch (Exception exception) { MessageBox.Show(exception.Message); } return(catalog); }
public void RasDSToCatalogWithTime(IRasterDataset pRasterDs, IFeatureClass pCatalog, string DataField, string strData, IRasterStorageDef pRasStoreDef) { //IRasterCatalogItem pCatalogFeature; IFeatureCursor pCursor; IFeatureBuffer pRow; pCursor = pCatalog.Insert(false); IRasterCatalog pCat = pCatalog as IRasterCatalog; IDataset pDs; // loop through all the datasets and load if (pRasterDs != null) { pDs = pRasterDs as IDataset; pRow = pCatalog.CreateFeatureBuffer(); pRow.set_Value(pCat.RasterFieldIndex, createRasterValue(pRasterDs, pRasStoreDef)); pRow.set_Value(pCatalog.FindField(DataField), Convert.ToDateTime(strData)); pCursor.InsertFeature(pRow); } pRasterDs = null; }
private void btnOK_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; Exception err = null; #region 检查设置是否完备 //服务器连接设置检查 if (comBoxType.SelectedIndex == 1) { if (txtUser.Text.Length == 0 || txtPassWord.Text.Length == 0) { labelXErr.Text = "请完整设置SDE服务器访问参数!"; return; } } else { if (txtDataBase.Text.Length == 0) { labelXErr.Text = "请完整设置本地数据库路径!"; return; } } //判断数据库是否已经存在 if (comBoxType.Text.Trim().ToUpper() == "PDB") { if (File.Exists(txtDataBase.Text.Trim())) { MessageBox.Show("数据库'" + txtDataBase.Text.Trim().Substring(txtDataBase.Text.Trim().LastIndexOf('\\') + 1) + "'已经存在,请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } else if (comBoxType.Text.Trim().ToUpper() == "GDB") { if (Directory.Exists(txtDataBase.Text.Trim())) { MessageBox.Show("数据库'" + txtDataBase.Text.Trim().Substring(txtDataBase.Text.Trim().LastIndexOf('\\') + 1) + "'已经存在,请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } if (rbdataset.Checked)// cmbRasterType.Text.Trim() == "栅格数据集") { //栅格数据集设置检查 if (cmbCompression.Text.Trim() == "") { MessageBox.Show("请选择压缩类型!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (cmbResampleType.Text.Trim() == "") { MessageBox.Show("请选择重采样类型!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { if (txtPyramid.Text.Trim() != "") { Convert.ToInt32(txtPyramid.Text.Trim()); } Convert.ToInt32(tileH.Text.Trim()); Convert.ToInt32(tileW.Text.Trim()); Convert.ToInt32(txtBand.Text.Trim()); } catch (System.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); } //******************************************************************** MessageBox.Show("请填写有效的数字!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //labelXErr.Text = "请填写有效的数字!"; return; } } if (txtRasterName.Text == "") { labelXErr.Text = "请设置栅格编目名称或栅格数据集名称!"; return; } #endregion #region 设置数据库连接 //SysCommon.Gis.SysGisDataSet pSysDT = new SysCommon.Gis.SysGisDataSet(); if (this.comBoxType.SelectedIndex == 2) //PDB库体 { //pSysDT.SetWorkspace(txtDataBase.Text.Trim(),SysCommon.enumWSType.PDB,out err); SetDestinationProp("PDB", txtDataBase.Text, "", "", "", ""); } else if (this.comBoxType.SelectedIndex == 1) //SDE库体 { //pSysDT.SetWorkspace(txtServer.Text, txtInstance.Text, "", txtUser.Text, txtPassWord.Text, txtVersion.Text, out err); SetDestinationProp("SDE", txtServer.Text, txtInstance.Text, txtUser.Text, txtPassWord.Text, txtVersion.Text); } else if (this.comBoxType.SelectedIndex == 0) //GDB库体 { //pSysDT.SetWorkspace(txtDataBase.Text.Trim(), SysCommon.enumWSType.GDB, out err); SetDestinationProp("GDB", txtDataBase.Text, "", "", "", ""); } if (err != null) { MessageBox.Show("连接数据库出错!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //pworkSpace=pSysDT.WorkSpace; #endregion //创建库体 //ISpatialReference pGeoSpaRef = GetSpatialRef(cmbGeoSpaRef.Text.Trim()); //ISpatialReference pRasterSpaRef = GetSpatialRef(cmbRasterSpaRef.Text.Trim()); //几何空间参考 ISpatialReference pGeoSpaRef = GetSpatialRef(txtGeoSpati.Text.Trim(), out err); if (err != null) { return; } //栅格空间参考 ISpatialReference pRasterSpaRef = GetSpatialRef2(txtRasterSpati.Text.Trim(), out err); if (err != null) { return; } rstPixelType pPixelType = GetPixelType(); //栅格数据工作空间 IRasterWorkspaceEx pRasterWSEx = pworkSpace as IRasterWorkspaceEx; if (pRasterWSEx == null) { labelXErr.Text = "数据库连接出错!"; return; } if (rbcatalog.Checked) { //首先判断栅格目录是否存在 try { IRasterCatalog tempRasterCatalog = pRasterWSEx.OpenRasterCatalog(txtRasterName.Text.Trim()); if (tempRasterCatalog != null) { MessageBox.Show("栅格数据'" + txtRasterName.Text.Trim() + "'已经存在,请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch (System.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); } //******************************************************************** } //创建栅格目录 //********************************************************* //guozheng added CreateCatalog Log List <string> Pra = new List <string>(); Pra.Add(txtRasterName.Text.Trim()); if (ModData.SysLog != null) { ModData.SysLog.Write("创建栅格目录", Pra, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write("创建栅格目录", Pra, DateTime.Now); } //********************************************************* //创建栅格目录 CreateCatalog(pRasterWSEx, txtRasterName.Text.Trim(), "Raster", "Shape", pRasterSpaRef, pGeoSpaRef, "", true, out err); } else if (rbdataset.Checked) { //首先判断栅格目录是否存在 try { IRasterDataset tempRasterDataset = pRasterWSEx.OpenRasterDataset(txtRasterName.Text.Trim()); if (tempRasterDataset != null) { MessageBox.Show("栅格数据'" + txtRasterName.Text.Trim() + "'已经存在,请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch (System.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); } //******************************************************************** } //创建栅格数据集 //********************************************************* //guozheng added CreateRasterDataset Log List <string> Pra = new List <string>(); Pra.Add(txtRasterName.Text.Trim()); if (ModData.SysLog != null) { ModData.SysLog.Write("创建栅格数据集", Pra, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write("创建栅格数据集", Pra, DateTime.Now); } //********************************************************* //创建栅格数据集 CreateRasterDataset(pRasterWSEx, txtRasterName.Text.Trim(), Convert.ToInt32(txtBand.Text.Trim()), pPixelType, pRasterSpaRef, pGeoSpaRef, null, null, "", out err); } else { MessageBox.Show("请选择栅格数据库的类型!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (err != null) { MessageBox.Show(err.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //labelXErr.Text = err.Message; return; } ///将现势库信息写入配置文件(res\\schema) /// DevComponents.AdvTree.Node pCurNode = m_Hook.ProjectTree.SelectedNode; ///获得树图上选择的工程节点 string pProjectname = pCurNode.Name; System.Xml.XmlNode Projectnode = m_Hook.DBXmlDocument.SelectSingleNode("工程管理/工程[@名称='" + pProjectname + "']"); System.Xml.XmlElement ProjectNodeElement = Projectnode as System.Xml.XmlElement; //设置存储类型,栅格目录,栅格数据集 System.Xml.XmlElement DbTypeEle = ProjectNodeElement.SelectSingleNode(".//栅格数据库") as System.Xml.XmlElement; if (rbcatalog.Checked) { DbTypeEle.SetAttribute("存储类型", "栅格编目"); } else if (rbdataset.Checked) { DbTypeEle.SetAttribute("存储类型", "栅格数据集"); } System.Xml.XmlElement ProjectConnEle = ProjectNodeElement.SelectSingleNode(".//栅格数据库/连接信息") as System.Xml.XmlElement; ///设置数据库连接类型 if (this.comBoxType.SelectedIndex == 2) { ProjectConnEle.SetAttribute("类型", "PDB"); ProjectConnEle.SetAttribute("数据库", txtDataBase.Text); } else if (this.comBoxType.SelectedIndex == 0) { ProjectConnEle.SetAttribute("类型", "GDB"); ProjectConnEle.SetAttribute("数据库", txtDataBase.Text); } else if (this.comBoxType.SelectedIndex == 1) { ProjectConnEle.SetAttribute("类型", "SDE"); ProjectConnEle.SetAttribute("服务器", txtServer.Text); ProjectConnEle.SetAttribute("服务名", txtInstance.Text); ProjectConnEle.SetAttribute("数据库", txtDataBase.Text); ProjectConnEle.SetAttribute("用户", txtUser.Text); ProjectConnEle.SetAttribute("密码", txtPassWord.Text); ProjectConnEle.SetAttribute("版本", txtVersion.Text); } ///设置数据集名称 /// System.Xml.XmlElement ProjectUserDSEle = ProjectConnEle.SelectSingleNode(".//库体") as System.Xml.XmlElement; ProjectUserDSEle.SetAttribute("名称", txtRasterName.Text.Trim()); //设置栅格数据参数 System.Xml.XmlElement rasterParaEle = ProjectNodeElement.SelectSingleNode(".//栅格数据库/参数设置") as System.Xml.XmlElement; rasterParaEle.SetAttribute("重采样类型", cmbResampleType.Text.Trim()); rasterParaEle.SetAttribute("压缩类型", cmbCompression.Text.Trim()); rasterParaEle.SetAttribute("金字塔", txtPyramid.Text.Trim()); rasterParaEle.SetAttribute("瓦片高度", tileH.Text.Trim()); rasterParaEle.SetAttribute("瓦片宽度", tileW.Text.Trim()); rasterParaEle.SetAttribute("波段", txtBand.Text.Trim()); m_Hook.DBXmlDocument.Save(ModData.v_projectXML); MessageBox.Show("创建成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// 在Geodatabase中创建栅格数据编目 /// </summary> /// <param name="pRasterWSEx">目标Geodatabase工作区</param> /// <param name="pCatalogName">栅格编目的名称</param> /// <param name="pRasterFielsName">栅格列的名称</param> /// <param name="pShapeFieldName">几何要素列名称(Shape)</param> /// <param name="pRasterSpatialRef">几何要素列空间参考</param> /// <param name="pGeoSpatialRef">栅格列空间参考</param> /// <param name="pKeyword"> 栅格编目表的字段</param> /// <param name="eError">ArcSDE 适用, 表示configuration keyword</param> /// <returns></returns> private IRasterCatalog CreateCatalog(IRasterWorkspaceEx pRasterWSEx, string pCatalogName, string pRasterFielsName, string pShapeFieldName, ISpatialReference pRasterSpatialRef, ISpatialReference pGeoSpatialRef, string pKeyword, bool ismanaged, out Exception eError) { eError = null; IRasterCatalog pRasterCat = null; try { #region 创建字段 IFields pFields = new FieldsClass(); IFieldsEdit pFeildsEdit = pFields as IFieldsEdit; IField pField = null; pField = CreateCommonField("Name", esriFieldType.esriFieldTypeString); if (pField == null) { eError = new Exception("创建'name'字段出错!"); return(null); } pFeildsEdit.AddField(pField); IField2 pField2 = CreateRasterField(pRasterFielsName, pRasterSpatialRef, ismanaged); if (pField == null) { eError = new Exception("创建栅格字段出错!"); return(null); } pFeildsEdit.AddField(pField2); pField = CreateShapeField(pShapeFieldName, pGeoSpatialRef); if (pField == null) { eError = new Exception("创建几何字段出错!"); return(null); } pFeildsEdit.AddField(pField); pField = CreateOIDField("OBJECTID"); if (pField == null) { eError = new Exception("创建OID字段出错!"); return(null); } pFeildsEdit.AddField(pField); pField = null; if (pKeyword.Trim() == "") { pKeyword = "defaults"; } pFields = pFeildsEdit as IFields; //创建用户自定义字段 #endregion pRasterCat = pRasterWSEx.CreateRasterCatalog(pCatalogName, pFields, pShapeFieldName, pRasterFielsName, pKeyword); return(pRasterCat); } catch (System.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 = new Exception("创建栅格编目出错!\n" + ex.Message); return(null); } }
//cyf 2011065 modify public override void OnClick() { Exception err = null; /////获取工程项目名称 DevComponents.AdvTree.Node ProjectNode = new DevComponents.AdvTree.Node(); ProjectNode = m_Hook.ProjectTree.SelectedNode; while (ProjectNode.Parent != null) { ProjectNode = ProjectNode.Parent; } //cyf 20110625 add: DevComponents.AdvTree.Node DBNode = new DevComponents.AdvTree.Node(); //数据库树节点 //获取数据库节点 DBNode = m_Hook.ProjectTree.SelectedNode; while (DBNode.Parent != null && DBNode.DataKeyString != "DB") { DBNode = DBNode.Parent; } if (DBNode.DataKeyString != "DB") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据库节点失败!"); return; } DevComponents.AdvTree.Node DtSetNode = new DevComponents.AdvTree.Node(); //数据集树节点 #region 获取数据集节点 if (DBNode.Text == "现势库" || DBNode.Text == "历史库" || DBNode.Text == "临时库") //.DataKeyString == "现势库" { //获取数据集节点 DtSetNode = m_Hook.ProjectTree.SelectedNode; while (DtSetNode.Parent != null && DtSetNode.DataKeyString != "FD") { DtSetNode = DtSetNode.Parent; } if (DtSetNode.DataKeyString != "FD") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集节点失败!"); return; } } else if (DBNode.Text == "栅格数据库") { //cyf 20110626 add:获取栅格数据库图层节点 DtSetNode = m_Hook.ProjectTree.SelectedNode; if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "RC") { while (DtSetNode.Parent != null && DtSetNode.DataKeyString != "RC") { DtSetNode = DtSetNode.Parent; } if (DtSetNode.DataKeyString != "RC") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集节点失败!"); return; } } else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "RD") { while (DtSetNode.Parent != null && DtSetNode.DataKeyString != "RD") { DtSetNode = DtSetNode.Parent; } if (DtSetNode.DataKeyString != "RD") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集节点失败!"); return; } } //end } #endregion XmlElement elementTemp = (DBNode.Tag as XmlElement).SelectSingleNode(".//连接信息") as XmlElement; IWorkspace TempWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace; if (TempWorkSpace == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接数据库失败!"); return; } //cyf 20110625 modify ILayer player = null; //ILayer player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, m_Hook.ProjectTree.SelectedNode.DataKeyString + "_" + ProjectNode.Text); if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FD") { player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, m_Hook.ProjectTree.SelectedNode.Text + "_" + ProjectNode.Text); } else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FC") { player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, DtSetNode.Text + "_" + ProjectNode.Text); } //cyf 20110626 add:添加获取栅格数据图层 else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "RC" || m_Hook.ProjectTree.SelectedNode.DataKeyString == "RD") { //获取栅格数据图层 player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, DtSetNode.Text + "_" + ProjectNode.Text); } //end if (player != null) { m_Hook.MapControl.Map.DeleteLayer(player); m_Hook.TOCControl.Update(); } //end IGroupLayer pGroupLayer = new GroupLayerClass(); //cyf 20110625 if (DBNode.Text == "现势库" || DBNode.Text == "历史库" || DBNode.Text == "临时库") //.DataKeyString == "现势库" { /////////若为历史库管理状态退出该状态,加载现势库 m_Hook.MapControl.Map.ClearLayers(); Plugin.Interface.ICommandRef HisBaseCommand = null; bool GetSeccess = Plugin.ModuleCommon.DicCommands.TryGetValue("GeoDBATool.ControlsDBHistoryManage", out HisBaseCommand); if (GetSeccess) { HisCommand = HisBaseCommand as ControlsDBHistoryManage; if (HisCommand.Checked) { HisCommand.IsHistory = false;//判断是不是历史库点的加载,若是现势库就卸载掉历史库,若是历史库就不操作 HisCommand.OnClick(); } } #region 加载数据 SysCommon.Gis.SysGisDataSet sysGisDataset = new SysCommon.Gis.SysGisDataSet(TempWorkSpace); //cyf 20110625 modify IFeatureDataset featureDataset = null; //数据集 if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FD") { featureDataset = sysGisDataset.GetFeatureDataset(m_Hook.ProjectTree.SelectedNode.Text, out err); if (err != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集失败,请检查该数据集是否存在!"); return; } pGroupLayer.Name = m_Hook.ProjectTree.SelectedNode.Text + "_" + ProjectNode.Text; } else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FC") { featureDataset = sysGisDataset.GetFeatureDataset(DtSetNode.Text, out err); if (err != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集失败!"); return; } pGroupLayer.Name = DtSetNode.Text + "_" + ProjectNode.Text; } //end List <IDataset> lstDataset = sysGisDataset.GetFeatureClass(featureDataset); //遍历要素类,加载图层 string dbType = ""; string userName = "";//用户名 userName = elementTemp.GetAttribute("用户"); dbType = elementTemp.GetAttribute("类型"); foreach (IDataset dataset in lstDataset) { IFeatureClass pFeatureClass = dataset as IFeatureClass; if (pFeatureClass == null) { continue; } IFeatureLayer pFeatureLayer = new FeatureLayerClass(); if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) { pFeatureLayer = new FDOGraphicsLayerClass(); } pFeatureLayer.FeatureClass = pFeatureClass; if (dbType.Trim().ToUpper() == "SDE") { //cyf 20110706 modify:修改为不去掉用户名 changed by xisheng 0906 去掉用户名 if (dataset.Name.ToUpper().Contains(userName.Trim().ToUpper())) { //SDE用户图层名去掉用户名 pFeatureLayer.Name = dataset.Name.Substring(userName.Trim().Length + 1); } else { pFeatureLayer.Name = dataset.Name; } //end } else { pFeatureLayer.Name = dataset.Name; } //cyf 20110625 modify if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FC") { //加载指定的图层 if (m_Hook.ProjectTree.SelectedNode.Text != pFeatureLayer.Name) { continue; } } else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FD") { //加载具备权限的图层 XmlElement feaclsElem = null; try { feaclsElem = (m_Hook.ProjectTree.SelectedNode.Tag as XmlElement).SelectSingleNode(".//图层名") as XmlElement; } catch { } if (feaclsElem != null) { if (!feaclsElem.GetAttribute("名称").Contains(pFeatureLayer.Name)) { //若不具备数据权限,则不进行加载 continue; } } } //end pGroupLayer.Add(pFeatureLayer as ILayer); } m_Hook.MapControl.Map.AddLayer(pGroupLayer); #endregion } //else if (DBNode.Text == "历史库") //{ // //历史库加载 // //ModDBOperator.WriteLog("GetCommand"); // Plugin.Interface.ICommandRef HisBaseCommand = null; // bool GetSeccess = Plugin.ModuleCommon.DicCommands.TryGetValue("GeoDBATool.ControlsDBHistoryManage", out HisBaseCommand); // if (GetSeccess) // { // HisCommand = HisBaseCommand as ControlsDBHistoryManage; // //判断是不是历史库点的加载,若是现势库就卸载掉历史库,若是历史库就不操作 // HisCommand.IsHistory = true; // HisCommand.OnClick(); // if (HisCommand.MyControlHistoryBar != null) // { // string HisDBType = elementTemp.GetAttribute("类型"); // string[] strTemp = new string[] { elementTemp.GetAttribute("服务器"), elementTemp.GetAttribute("服务名"), elementTemp.GetAttribute("数据库"), elementTemp.GetAttribute("用户"), elementTemp.GetAttribute("密码"), elementTemp.GetAttribute("版本") }; // HisCommand.MyControlHistoryBar.AddHistoryData(strTemp, HisDBType); // } // } //} //加载sde数据后,注册版本 //if (dbType.Trim().ToUpper() == "SDE") //{ // IDataset pFeaDt = featureDataset as IDataset; // if (pFeaDt != null) // { // IVersionedObject pVerObj = pFeaDt as IVersionedObject; // if (!pVerObj.IsRegisteredAsVersioned) // { // //注册版本 // pVerObj.RegisterAsVersioned(true); // } // else // { // pVerObj.RegisterAsVersioned(false); // } // } //} else if (DBNode.Text == "栅格数据库") { //栅格数据加载,分为两种情况:栅格数据集、栅格编目 //cyf 20110625 modify pGroupLayer.Name = m_Hook.ProjectTree.SelectedNode.Text + "_" + ProjectNode.Text; //end string rasterDBType = (m_Hook.ProjectTree.SelectedNode.Tag as XmlElement).GetAttribute("存储类型"); elementTemp = (DBNode.Tag as XmlElement).SelectSingleNode(".//连接信息") as XmlElement; //cyf 20110626 TempWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace; if (TempWorkSpace == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接数据库失败!"); return; } IRasterWorkspaceEx pRasterWS = TempWorkSpace as IRasterWorkspaceEx; if (pRasterWS == null) { return; } //string feaclsName = (elementTemp.FirstChild as XmlElement).GetAttribute("名称"); string feaclsName = m_Hook.ProjectTree.SelectedNode.Text; try { if (rasterDBType.Trim() == "栅格编目") { //栅格编目数据加载 IRasterCatalog pRasterCatalog = pRasterWS.OpenRasterCatalog(feaclsName); IGdbRasterCatalogLayer pGDBRCLayer = new GdbRasterCatalogLayerClass(); if (!pGDBRCLayer.Setup(pRasterCatalog as ITable)) { return; } IFeatureLayer mFeaLayer = pGDBRCLayer as IFeatureLayer; pGroupLayer.Add(mFeaLayer as ILayer); //IFeatureClass pFeaCls = pRasterCatalog as IFeatureClass; //if (pFeaCls == null) return; //IFeatureCursor pFeaCursor=pFeaCls.Search(null,false); //if(pFeaCursor==null) return; //IFeature pFea=pFeaCursor.NextFeature(); //while (pFea != null) //{ // IRasterCatalogItem pRCItem = pFea as IRasterCatalogItem; // IRasterDataset pRasterDt = pRCItem.RasterDataset; // IRasterLayer mRasterLayer = new RasterLayerClass(); // mRasterLayer.CreateFromDataset(pRasterDt); // if (mRasterLayer == null) return; // pGroupLayer.Add(mRasterLayer as ILayer); // pFea = pFeaCursor.NextFeature(); // //IFeatureLayer pFeaLayer = new FeatureLayerClass(); // //pFeaLayer.FeatureClass = pFeaCls as IFeatureClass; // //pFeaLayer.Name = feaclsName; // //pGroupLayer.Add(pFeaLayer as ILayer); //} } else if (rasterDBType.Trim() == "栅格数据集") { //栅格数据集加载 IRasterDataset pRasterDataset = pRasterWS.OpenRasterDataset(feaclsName); //IRasterPyramid pRasterPyramid = pRasterDataset as IRasterPyramid; //if(!pRasterPyramid.Present) //{ // if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "未构建金字塔,是否构建金字塔?")) // { // pRasterPyramid.Create(); // } //} IRasterLayer pRasterLayer = new RasterLayerClass(); pRasterLayer.CreateFromDataset(pRasterDataset); if (pRasterLayer == null) { return; } pGroupLayer.Add(pRasterLayer as ILayer); } m_Hook.MapControl.Map.AddLayer(pGroupLayer); } 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; } } //对图层进行排序 SysCommon.Gis.ModGisPub.LayersCompose(m_Hook.MapControl); //符号化 去掉加载的符号化 20111025 席胜 //GeoUtilities.ControlsRenderLayerByMxd RenderLayerByMxd = new GeoUtilities.ControlsRenderLayerByMxd(); //RenderLayerByMxd.OnCreate(m_Hook); //RenderLayerByMxd.OnClick(); }
private void comboBoxDataSource_SelectedIndexChanged(object sender, EventArgs e) { //cyf 20110613 add //this.comboBoxFeaClass.Items.Clear(); //end SysGisTable sysTable = new SysGisTable(_tmpWorkspace); Exception eError; //根据用户选择的数据源,得到数据源的工作空间 string DataSourceName = this.comboBoxDataSource.Text; string conninfostr = sysTable.GetFieldValue("DATABASEMD", "CONNECTIONINFO", "DATABASENAME='" + DataSourceName + "'", out eError).ToString(); int type = int.Parse(sysTable.GetFieldValue("DATABASEMD", "DATAFORMATID", "DATABASENAME='" + DataSourceName + "'", out eError).ToString()); string strDBPara = sysTable.GetFieldValue("DATABASEMD", "DBPARA", "DATABASENAME='" + DataSourceName + "'", out eError).ToString(); int index6 = conninfostr.LastIndexOf("|"); //string strdataset = conninfostr.Substring(index6 + 1); IWorkspace pWorkspace = ModuleMap.GetWorkSpacefromConninfo(conninfostr, type); if (pWorkspace == null) { return; } _ListDataset.Clear(); _ListTypeOfDataset.Clear(); string strDatasets = conninfostr.Substring(index6 + 1); string[] strTemp = strDatasets.Split(new char[] { ',' }); IFeatureWorkspace pFeaWorkSpace = pWorkspace as IFeatureWorkspace; if (pFeaWorkSpace != null) { for (int k = 0; k < strTemp.Length; k++) { IDataset pTmpdataset = null; if (strDBPara.Contains("栅格数据集")) { IRasterWorkspaceEx rasterWorkspace = (IRasterWorkspaceEx)pFeaWorkSpace; IRasterDataset pRDataset = rasterWorkspace.OpenRasterDataset(strTemp[k]); pTmpdataset = pRDataset as IDataset; if (pTmpdataset != null) { _ListTypeOfDataset.Add("RD"); } } else if (strDBPara.Contains("栅格编目")) { IRasterWorkspaceEx rasterWorkspace = (IRasterWorkspaceEx)pFeaWorkSpace; IRasterCatalog pRCatalog = rasterWorkspace.OpenRasterCatalog(strTemp[k]); pTmpdataset = pRCatalog as IDataset; if (pTmpdataset != null) { _ListTypeOfDataset.Add("RC"); } } else { pTmpdataset = pFeaWorkSpace.OpenFeatureDataset(strTemp[k]) as IDataset; if (pTmpdataset != null) { _ListTypeOfDataset.Add("FC"); } } if (pTmpdataset != null) { _ListDataset.Add(pTmpdataset); } } } _dataWorkspace = pWorkspace; if (pWorkspace == null) { return; } }
/// <summary> /// Occurs in the master geodatabase after data changes in either a replica /// geodatabase or delta database are transferred to the master geodatabase. /// </summary> /// <param name="targetReplica">The target replica.</param> /// <param name="dataChangesSource">A collection of changes made to the master geodatabase.</param> /// <param name="oidMappingTable">Not used in this implementation.</param> /// <param name="changesTable">Not used in this implemented.</param> public void AfterSynchronizingDataChanges(IReplica targetReplica, object dataChangesSource, ITable oidMappingTable, ITable changesTable) { // Make sure that the correct replica is being synchronized. String replicaName = targetReplica.Name; String unqualifiedReplicaName = replicaName.Substring(replicaName.LastIndexOf('.') + 1); if (!unqualifiedReplicaName.Equals(rasterReplicaName)) { return; } // Get the rasters to pull if connected synchronization is occurring. IDataChanges3 dataChanges3 = dataChangesSource as IDataChanges3; if (dataChanges3 != null) { // Get the source's replicas. IName sourceWorkspaceName = (IName)dataChanges3.ParentWorkspaceName; IWorkspace sourceWorkspace = (IWorkspace)sourceWorkspaceName.Open(); IWorkspaceReplicas sourceWorkspaceReplicas = (IWorkspaceReplicas)sourceWorkspace; // Get the replica generation numbers. int genBegin = 0; int genEnd = 0; int targetGen = 0; dataChanges3.GenerationNumbers(out genBegin, out genEnd, out targetGen); IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = String.Format("{0} > {1} or {0} is NULL", genFieldName, genBegin); // Open a cursor to get the rasters to copy form the source. IRasterWorkspaceEx sourceRasterWorkspaceEx = (IRasterWorkspaceEx)sourceWorkspace; IRasterCatalog sourceRasterCatalog = sourceRasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName); IFeatureClass sourceFeatureClass = (IFeatureClass)sourceRasterCatalog; int sourceGenFieldIndex = sourceFeatureClass.FindField(genFieldName); IFeatureCursor sourceCursor = sourceFeatureClass.Search(queryFilter, true); // Open the target raster catalog. IRasterWorkspaceEx targetRasterWorkspaceEx = (IRasterWorkspaceEx)workspaceHelper.Workspace; IRasterCatalog targetRasterCatalog = targetRasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName); IFeatureClass targetFeatureClass = (IFeatureClass)targetRasterCatalog; int targetGenFieldIndex = targetFeatureClass.FindField(genFieldName); IFeatureCursor targetCursor = targetFeatureClass.Insert(true); // Copy the rasters from the source to the target. IFeature sourceFeature = null; while ((sourceFeature = sourceCursor.NextFeature()) != null) { // Copy the raster and set the target gen to -1 (received). IFeatureBuffer featureBuffer = targetFeatureClass.CreateFeatureBuffer(); featureBuffer.set_Value(targetRasterCatalog.RasterFieldIndex, sourceFeature.get_Value(sourceRasterCatalog.RasterFieldIndex)); featureBuffer.set_Value(targetGenFieldIndex, -1); targetCursor.InsertFeature(featureBuffer); // Set the source row value to the current generation. if (sourceFeature.get_Value(sourceGenFieldIndex) == DBNull.Value) { sourceFeature.set_Value(sourceGenFieldIndex, genEnd); } sourceFeature.Store(); } Marshal.FinalReleaseComObject(sourceCursor); Marshal.FinalReleaseComObject(targetCursor); } }
//工程设置添加文件 private void addFile11(TextBox tx, string tablename) { IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass(); string GdbPath = Application.StartupPath + "\\GISData.gdb"; string MdbPath = Application.StartupPath + "\\GISData.mdb"; IWorkspaceFactory pWks = new AccessWorkspaceFactoryClass(); IWorkspace pFwk = pWks.OpenFromFile(MdbPath, 0) as IWorkspace; IGxDialog dlg = new GxDialog(); IGxObjectFilterCollection filterCollection = dlg as IGxObjectFilterCollection; filterCollection.AddFilter(new GxFilterFeatureClasses(), true); IEnumGxObject enumObj; dlg.AllowMultiSelect = true; dlg.Title = "添加数据"; dlg.DoModalOpen(0, out enumObj); if (enumObj != null) { enumObj.Reset(); int a = 0; IGxObject gxObj = enumObj.Next(); while (gxObj != null) { Console.WriteLine(a++); if (gxObj is IGxDataset) { IGxDataset gxDataset = gxObj as IGxDataset; IDataset pDataset = gxDataset.Dataset; switch (pDataset.Type) { case esriDatasetType.esriDTFeatureClass: IFeatureClass pFc = pDataset as IFeatureClass; ISpatialReference pSpatialReference = (pFc as IGeoDataset).SpatialReference; //空间参考 CommonClass common = new CommonClass(); if (pSpatialReference.Name != common.GetConfigValue("SpatialReferenceName")) { MessageBox.Show("空间参考错误"); break; } else { tx.Text = pDataset.BrowseName; tx.Name = pDataset.BrowseName; } break; case esriDatasetType.esriDTFeatureDataset: IFeatureDataset pFeatureDs = pDataset as IFeatureDataset; //do anyting you like break; case esriDatasetType.esriDTRasterDataset: IRasterDataset rasterDs = pDataset as IRasterDataset; //do anyting you like break; case esriDatasetType.esriDTTable: ITable pTable = pDataset as ITable; //do anyting you like break; case esriDatasetType.esriDTTin: ITin pTin = pDataset as ITin; //do anyting you like break; case esriDatasetType.esriDTRasterCatalog: IRasterCatalog pCatalog = pDataset as IRasterCatalog; //do anyting you like break; default: break; } } else if (gxObj is IGxLayer) { IGxLayer gxLayer = gxObj as IGxLayer; ILayer pLayer = gxLayer.Layer; break; //do anything you like } gxObj = enumObj.Next(); } } }
IRasterDataset GetRasterCatalogItem(IRasterCatalog pCatalog, int pObjectID) { //栅格目录继承了IFeatureClass IFeatureClass pFeatureClass = (IFeatureClass)pCatalog; IRasterCatalogItem pRasterCatalogItem = (IRasterCatalogItem)pFeatureClass.GetFeature(pObjectID); return pRasterCatalogItem.RasterDataset; }