public FrmStatisticsConfig(IWorkspace pTmpWorkSpace) { _TmpWorkSpace = pTmpWorkSpace; if (pTmpWorkSpace != null) { SysCommon.ModSysSetting.CopyLayerTreeXmlFromDataBase(pTmpWorkSpace, _LayerTreePath); SysGisTable mSystable = new SysCommon.Gis.SysGisTable(pTmpWorkSpace); Exception err = null; Dictionary <string, object> pDic = mSystable.GetRow("SYSSETTING", "SETTINGNAME='统计配置'", out err); if (pDic != null) { if (pDic.ContainsKey("SETTINGVALUE2")) { if (pDic["SETTINGVALUE2"] != null) //这里仅能成功导出当初以文件类型导入的BLOB字段 { object tempObj = pDic["SETTINGVALUE2"]; IMemoryBlobStreamVariant pMemoryBlobStreamVariant = tempObj as IMemoryBlobStreamVariant; IMemoryBlobStream pMemoryBlobStream = pMemoryBlobStreamVariant as IMemoryBlobStream; if (pMemoryBlobStream != null) { try { pMemoryBlobStream.SaveToFile(_QueryConfigPath); } catch { return; } } } } } } InitializeComponent(); }
private void CopyConfigXml(string Settingname, string SettingPath) { try { SysGisTable mSystable = new SysCommon.Gis.SysGisTable(Plugin.ModuleCommon.TmpWorkSpace); Exception err = null; Dictionary <string, object> pDic = mSystable.GetRow("SYSSETTING", "SETTINGNAME='" + Settingname + "'", out err); if (pDic != null) { if (pDic.ContainsKey("SETTINGVALUE2")) { if (pDic["SETTINGVALUE2"] != null) //这里仅能成功导出当初以文件类型导入的BLOB字段 { object tempObj = pDic["SETTINGVALUE2"]; IMemoryBlobStreamVariant pMemoryBlobStreamVariant = tempObj as IMemoryBlobStreamVariant; IMemoryBlobStream pMemoryBlobStream = pMemoryBlobStreamVariant as IMemoryBlobStream; if (pMemoryBlobStream != null) { pMemoryBlobStream.SaveToFile(SettingPath); } } } } } catch (Exception err2) { } }
public static void CopyConfigXml(IWorkspace pWks, string Settingname, string SettingPath) { try { SysGisTable mSystable = new Fan.Common.Gis.SysGisTable(pWks); Exception err = null; Dictionary <string, object> pDic = mSystable.GetRow("SYSSETTING", "SETTINGNAME='" + Settingname + "'", out err); if (pDic != null) { if (pDic.ContainsKey("SETTINGVALUE2")) { if (pDic["SETTINGVALUE2"] != null) //这里仅能成功导出当初以文件类型导入的BLOB字段 { object tempObj = pDic["SETTINGVALUE2"]; IMemoryBlobStreamVariant pMemoryBlobStreamVariant = tempObj as IMemoryBlobStreamVariant; IMemoryBlobStream pMemoryBlobStream = pMemoryBlobStreamVariant as IMemoryBlobStream; if (pMemoryBlobStream != null) { pMemoryBlobStream.SaveToFile(SettingPath); } } } } mSystable = null; if (pDic != null) { pDic.Clear(); pDic = null; } } catch (Exception err2) { } }
private void SaveBookmarkDatFile(string filePath, ISceneBookmarks _SceneBookmarks) { try { IObjectStream pObjStream = new ObjectStreamClass(); _SceneBookmarks.SaveBookmarks(pObjStream.Stream); IMemoryBlobStream pMemBlobStream = pObjStream.Stream as IMemoryBlobStream; pMemBlobStream.SaveToFile(filePath); } catch { } }
//从数据库向本地拷贝 private void CopyEagleEyeMap(IWorkspace pWorkspace, string strPath) { Exception eError = null; //读取数据库表内容 object tempObj = GetFieldValue("SYSSETTING", "SETTINGVALUE2", "SETTINGNAME='鹰眼图'", pWorkspace, out eError); IMemoryBlobStreamVariant pMemoryBlobStreamVariant = tempObj as IMemoryBlobStreamVariant; IMemoryBlobStream pMemoryBlobStream = pMemoryBlobStreamVariant as IMemoryBlobStream; if (pMemoryBlobStream != null) { pMemoryBlobStream.SaveToFile(strPath); } }
private void btn_DownLoad_Click(object sender, EventArgs e) { SaveFileDialog sfd; if (this.xtraTabControl1.SelectedTabPageIndex == 0) { DataRow dr = gridView2.GetFocusedDataRow(); string fileName = dr["文件名称"].ToString(); string fileType = fileName.Substring(fileName.LastIndexOf('.')); if (_dictCad.ContainsKey(fileName)) { object fileCad = _dictCad[fileName]; sfd = new SaveFileDialog(); sfd.RestoreDirectory = true; sfd.Filter = "保存文件|*" + fileType; if (sfd.ShowDialog() == DialogResult.OK) { IMemoryBlobStream mbs = fileCad as IMemoryBlobStream; if (mbs == null) { return; } mbs.SaveToFile(sfd.FileName); } } } else { DataRow dr = gridView1.GetFocusedDataRow(); string fileName = dr["文件名称"].ToString(); string fileType = dr["文件类别"].ToString(); if (_dictFiles.ContainsKey(fileName)) { object file = _dictFiles[fileName]; sfd = new SaveFileDialog(); sfd.RestoreDirectory = true; sfd.Filter = "保存文件|*" + fileType; if (sfd.ShowDialog() == DialogResult.OK) { IMemoryBlobStream mbs = file as IMemoryBlobStream; if (mbs == null) { return; } mbs.SaveToFile(sfd.FileName); } } } }
//当初当前系统参数的值,放在指定路径(限定该参数值是BLOB类型,并且存入时是选取文件存入的) private void buttonXExport_Click(object sender, EventArgs e) { if (!comboBoxDataType.Text.Contains("File")) { return; } SaveFileDialog pOpenFileDlg = new SaveFileDialog(); pOpenFileDlg.Title = "选择文件"; switch (comboBoxDataType.Text) { case "XmlFile": //弹出对话框供用户设置导出的xml文件 pOpenFileDlg.Filter = "XML数据(*.xml)|*.xml"; break; case "MxdFile": pOpenFileDlg.Filter = "mxd文件(*.mxd)|*.mxd"; break; } if (pOpenFileDlg.ShowDialog() == DialogResult.OK) { //获得系统参数表的BLOB字段值,并导出到指定文件中 string strPath = pOpenFileDlg.FileName; SysGisTable mSystable = new SysCommon.Gis.SysGisTable(_TmpWorkSpace); Exception err = null; Dictionary <string, object> pDic = mSystable.GetRow("SYSSETTING", "SETTINGNAME='" + this.textBoxSettingName.Text + "'", out err); if (pDic != null) { if (pDic.ContainsKey("SETTINGVALUE2")) { if (pDic["SETTINGVALUE2"] != null) //这里仅能成功导出当初以文件类型导入的BLOB字段 { object tempObj = pDic["SETTINGVALUE2"]; IMemoryBlobStreamVariant pMemoryBlobStreamVariant = tempObj as IMemoryBlobStreamVariant; IMemoryBlobStream pMemoryBlobStream = pMemoryBlobStreamVariant as IMemoryBlobStream; if (pMemoryBlobStream != null) { pMemoryBlobStream.SaveToFile(strPath); MessageBox.Show("将文件" + strPath + "导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);//ygc 2012-12-17 新增提示信息 } } } } mSystable = null; } }
public static bool CopySysSettingtoFile(IWorkspace pWorkspace, string strSettingName, string strPath) { Exception eError = null; if (pWorkspace != null) { try { //读取数据库表内容 Fan.Common.Gis.SysGisTable sysTable = new Fan.Common.Gis.SysGisTable(pWorkspace); Exception err = null; Dictionary <string, object> pDic = sysTable.GetRow("SYSSETTING", "SETTINGNAME='" + strSettingName + "'", out err); if (pDic != null) { if (pDic.ContainsKey("SETTINGVALUE2")) { if (pDic["SETTINGVALUE2"] != null) //这里仅能成功导出当初以文件类型导入的BLOB字段 { object tempObj = pDic["SETTINGVALUE2"]; IMemoryBlobStreamVariant pMemoryBlobStreamVariant = tempObj as IMemoryBlobStreamVariant; IMemoryBlobStream pMemoryBlobStream = pMemoryBlobStreamVariant as IMemoryBlobStream; if (pMemoryBlobStream != null) { pMemoryBlobStream.SaveToFile(strPath); } sysTable = null; return(true); } } } sysTable = null; } catch (Exception err) {} } return(false); }
public static void TestThumbnailBuilder(string rasterTypeName, string rasterTypeProductFilter, string rasterTypeProductName, string dataSource, string dataSourceFilter, string fgdbParentFolder, bool saveToArt, string customTypeFilePath, bool clearGdbDirectory) { try { string[] rasterProductNames = rasterTypeProductName.Split(';'); string nameString = rasterTypeName.Replace(" ", "") + rasterTypeProductFilter.Replace(" ", "") + rasterProductNames[0].Replace(" ", ""); #region Directory Declarations string fgdbName = nameString + ".gdb"; string fgdbDir = fgdbParentFolder + "\\" + fgdbName; string MosaicDatasetName = nameString + "MD"; #endregion #region Global Declarations IMosaicDataset theMosaicDataset = null; IMosaicDatasetOperation theMosaicDatasetOperation = null; IMosaicWorkspaceExtensionHelper mosaicExtHelper = null; IMosaicWorkspaceExtension mosaicExt = null; #endregion #region Create File GDB Console.WriteLine("Creating File GDB: " + fgdbName); if (clearGdbDirectory) { try { Console.WriteLine("Emptying Gdb folder."); System.IO.Directory.Delete(fgdbParentFolder, true); System.IO.Directory.CreateDirectory(fgdbParentFolder); } catch (System.IO.IOException EX) { Console.WriteLine(EX.Message); return; } } // Create a File Gdb Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"); IWorkspaceFactory FgdbFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); FgdbFactory.Create(fgdbParentFolder, fgdbName, null, 0); #endregion #region Create Mosaic Dataset try { Console.WriteLine("Create Mosaic Dataset: " + MosaicDatasetName); // Setup workspaces. IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); IWorkspace fgdbWorkspace = workspaceFactory.OpenFromFile(fgdbDir, 0); // Create Srs ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference mosaicSrs = spatialrefFactory.CreateProjectedCoordinateSystem( (int)(esriSRProjCSType.esriSRProjCS_World_Mercator)); // Create the mosaic dataset creation parameters object. ICreateMosaicDatasetParameters creationPars = new CreateMosaicDatasetParametersClass(); // Create the mosaic workspace extension helper class. mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass(); // Find the right extension from the workspace. mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace); // Use the extension to create a new mosaic dataset, supplying the // spatial reference and the creation parameters object created above. theMosaicDataset = mosaicExt.CreateMosaicDataset(MosaicDatasetName, mosaicSrs, creationPars, ""); theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset); } catch (Exception exc) { Console.WriteLine("Error: Failed to create Mosaic Dataset : {0}.", MosaicDatasetName + " " + exc.Message); return; } #endregion #region Create Custom Raster Type Console.WriteLine("Preparing Raster Type"); // Create a Raster Type Name object. IRasterTypeName theRasterTypeName = new RasterTypeNameClass(); // Assign the name of the Raster Type to the name object. // The Name field accepts a path to an .art file as well // the name for a built in Raster Type. theRasterTypeName.Name = rasterTypeName; // Use the Open function from the IName interface to get the Raster Type object. IRasterType theRasterType = (IRasterType)(((IName)theRasterTypeName).Open()); if (theRasterType == null) { Console.WriteLine("Error:Raster Type not found " + rasterTypeName); return; } #endregion #region Prepare Raster Type // Set the URI Filter on the loaded raster type. if (rasterTypeProductFilter != "") { // Get the supported URI filters from the raster type object using the // raster type properties interface. IArray mySuppFilters = ((IRasterTypeProperties)theRasterType).SupportedURIFilters; IItemURIFilter productFilter = null; for (int i = 0; i < mySuppFilters.Count; ++i) { // Set the desired filter from the supported filters. productFilter = (IItemURIFilter)mySuppFilters.get_Element(i); if (productFilter.Name == rasterTypeProductFilter) { theRasterType.URIFilter = productFilter; } } } // Enable the correct templates in the raster type. bool enableTemplate = false; if (rasterProductNames.Length >= 1 && (rasterProductNames[0] != "")) { // Get the supported item templates from the raster type. IItemTemplateArray templateArray = theRasterType.ItemTemplates; for (int i = 0; i < templateArray.Count; ++i) { // Go through the supported item templates and enable the ones needed. IItemTemplate template = templateArray.get_Element(i); enableTemplate = false; for (int j = 0; j < rasterProductNames.Length; ++j) { if (template.Name == rasterProductNames[j]) { enableTemplate = true; } } if (enableTemplate) { template.Enabled = true; } else { template.Enabled = false; } } } ((IRasterTypeProperties)theRasterType).DataSourceFilter = dataSourceFilter; #endregion #region Save Custom Raster Type if (saveToArt) { IRasterTypeProperties rasterTypeProperties = (IRasterTypeProperties)theRasterType; IRasterTypeEnvironment rasterTypeHelper = new RasterTypeEnvironmentClass(); rasterTypeProperties.Name = customTypeFilePath; IMemoryBlobStream ipBlob = rasterTypeHelper.SaveRasterType(theRasterType); ipBlob.SaveToFile(customTypeFilePath); } #endregion #region Preparing Data Source Crawler Console.WriteLine("Preparing Data Source Crawler"); // Create a new property set to specify crawler properties. IPropertySet crawlerProps = new PropertySetClass(); // Specify a file filter crawlerProps.SetProperty("Filter", dataSourceFilter); // Specify whether to search subdirectories. crawlerProps.SetProperty("Recurse", true); // Specify the source path. crawlerProps.SetProperty("Source", dataSource); // Get the recommended crawler from the raster type based on the specified // properties using the IRasterBuilder interface. // Pass on the Thumbnailtype to the crawler... IDataSourceCrawler theCrawler = ((IRasterBuilder)theRasterType).GetRecommendedCrawler(crawlerProps); #endregion #region Add Rasters try { Console.WriteLine("Adding Rasters"); // Create a AddRaster parameters object. IAddRastersParameters AddRastersArgs = new AddRastersParametersClass(); // Specify the data crawler to be used to crawl the data. AddRastersArgs.Crawler = theCrawler; // Specify the Thumbnail raster type to be used to add the data. AddRastersArgs.RasterType = theRasterType; // Use the mosaic dataset operation interface to add // rasters to the mosaic dataset. theMosaicDatasetOperation.AddRasters(AddRastersArgs, null); } catch (Exception ex) { Console.WriteLine("Error: Add raster Failed." + ex.Message); return; } #endregion #region Compute Pixel Size Ranges Console.WriteLine("Computing Pixel Size Ranges."); try { // Create a calculate cellsize ranges parameters object. ICalculateCellSizeRangesParameters computeArgs = new CalculateCellSizeRangesParametersClass(); // Use the mosaic dataset operation interface to calculate cellsize ranges. theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null); } catch (Exception ex) { Console.WriteLine("Error: Compute Pixel Size Failed." + ex.Message); return; } #endregion #region Building Boundary Console.WriteLine("Building Boundary"); try { // Create a build boundary parameters object. IBuildBoundaryParameters boundaryArgs = new BuildBoundaryParametersClass(); // Set flags that control boundary generation. boundaryArgs.AppendToExistingBoundary = true; // Use the mosaic dataset operation interface to build boundary. theMosaicDatasetOperation.BuildBoundary(boundaryArgs, null); } catch (Exception ex) { Console.WriteLine("Error: Build Boundary Failed." + ex.Message); return; } #endregion #region Report Console.WriteLine("Successfully created MD: " + MosaicDatasetName + ". "); #endregion } catch (Exception exc) { #region Report Console.WriteLine("Exception Caught in TestThumbnailBuilder: " + exc.Message); Console.WriteLine("Failed."); Console.WriteLine("Shutting down."); #endregion } }