/// <summary> /// Each BuilderItem contains a Function Raster Dataset which is used to create the thumbnail. /// The thumbnail is created by Nearest Neighbor resampling of the Function Raster Dataset. /// The resampled raster is exported as a byte array and saved Into the IMemoryBlobStreamVariant. /// The blob is then inserted into the Thumbnail field. /// </summary> /// <param name="mybuilderItem">Item containing the Function Dataset to be added to the Mosaic Dataset</param> private void Resampling(IBuilderItem mybuilderItem) { try { IFunctionRasterDataset pFuncRasterDataset = mybuilderItem.Dataset; // Get the FunctionRasterDataset from mybuilderItem IRasterDataset pRasterDataset; pRasterDataset = (IRasterDataset)pFuncRasterDataset; // Cast the FunctionRasterDataset to Raster Dataset IPropertySet thePropSet = pFuncRasterDataset.Properties; // Get the properties of the raster Dataset IRaster praster = pRasterDataset.CreateDefaultRaster(); // Create default raster from the above raster dataset praster.ResampleMethod = rstResamplingTypes.RSP_NearestNeighbor; // The raster is resampled by RSP_NearestNeighbor IRasterProps pRasterProps = (IRasterProps)praster; // Raster properties are used to update the height, width of the raster pRasterProps.Height = 256; pRasterProps.Width = 256; IRasterExporter pConverter = new RasterExporterClass(); // IRasterExporter object is used to convert the raster to byte array. byte[] pBytesArr; pBytesArr = pConverter.ExportToBytes(praster, "TIFF"); // Convert the resampled Raster to a Byte array IMemoryBlobStream memBlobStream = new MemoryBlobStream(); // Create new IMemoryBlobStream IMemoryBlobStreamVariant varBlobStream = (IMemoryBlobStreamVariant)memBlobStream; // Assign to IMemoryBlobStreamVariant object anObject = pBytesArr; varBlobStream.ImportFromVariant(anObject); // IMemoryBlobStreamVariant object is assigned the byte array thePropSet.SetProperty("ThumbNail", memBlobStream); // and saved to the property "ThumbNail" } catch (Exception ex) { System.Exception myExc = new System.Exception( "Error: Failed to Re-Sampled the raster.Thumbnails will not be created." + ex.Message, ex); throw myExc; } return; }
//从数据库向本地拷贝 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); } }
//当初当前系统参数的值,放在指定路径(限定该参数值是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; } }
//从数据库中读取MXD文档 private byte[] ReadByteFromBlob(string TableName, string QuerStr, string fieldName) { ICursor pCursor = null; byte[] newbyte = null; try { ITable pTable = (m_pWorkspace as IFeatureWorkspace).OpenTable(TableName); IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = QuerStr; pQueryFilter.SubFields = fieldName; pCursor = pTable.Search(pQueryFilter, false); if (pCursor == null) { return(null); } int FieldIndex = pCursor.Fields.FindField(fieldName); if (FieldIndex < 0) { return(null); } IRow pRow = pCursor.NextRow(); if (pRow == null) { return(null); } object resultValue = pRow.get_Value(FieldIndex); if (resultValue == null) { return(null); } if (resultValue is System.DBNull) { return(null); } IMemoryBlobStreamVariant pMemoryBlob = resultValue as IMemoryBlobStreamVariant; object outValue; pMemoryBlob.ExportToVariant(out outValue); newbyte = (byte[])outValue; } catch { return(null); } return(newbyte); }
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 void SymbolFeatrueLayer(IFeatureLayer pFealyr) { if (!(pFealyr is IGeoFeatureLayer)) { return; } try { string strXMLpath = System.Windows.Forms.Application.StartupPath + "\\..\\Template\\SymbolInfo.xml"; string strLyrName = pFealyr.Name; if (pFealyr.FeatureClass != null) { IDataset pDataset = pFealyr.FeatureClass as IDataset; strLyrName = pDataset.Name; } strLyrName = strLyrName.Substring(strLyrName.IndexOf('.') + 1); if (m_vDoc == null) { IFeatureWorkspace pFeaWks = ModFrameData.m_pFeatureWorkspace; ITable pTable = pFeaWks.OpenTable("SYMBOLINFO"); IQueryFilter pQueryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); pQueryFilter.WhereClause = "SYMBOLNAME='ALLSYMBOL'"; ICursor pCursor = pTable.Search(pQueryFilter, false); IRow pRow = pCursor.NextRow(); if (pRow == null) { return; } IMemoryBlobStreamVariant var = pRow.get_Value(pRow.Fields.FindField("SYMBOL")) as IMemoryBlobStreamVariant; object tempObj = null; if (var == null) { return; } var.ExportToVariant(out tempObj); XmlDocument doc = new XmlDocument(); byte[] btyes = (byte[])tempObj; string xml = Encoding.Default.GetString(btyes); doc.LoadXml(xml); DateTime updateTime = (DateTime)pRow.get_Value(pRow.Fields.FindField("UPDATETIME")); DateTime Nowtime; bool blnUpdate = false; //读一个日志算了 string strTimeLog = System.Windows.Forms.Application.StartupPath + "\\..\\Template\\UpdateTime.txt"; if (System.IO.File.Exists(strTimeLog)) { StreamReader sr = new StreamReader(strTimeLog); string strTime = sr.ReadLine(); sr.Close(); if (!DateTime.TryParse(strTime, out Nowtime)) { blnUpdate = true; } if (updateTime > Nowtime) { if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "存在最新符号信息,是否需要下载?")) { blnUpdate = true; } } } else { blnUpdate = true; } System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor); pCursor = null; //首先判断是否需要下载符号信息 if (System.IO.File.Exists(strXMLpath)) { if (blnUpdate) { doc.Save(strXMLpath); StreamWriter sw1 = new StreamWriter(strTimeLog); sw1.Write(updateTime.ToString()); sw1.Close(); } } else { doc.Save(strXMLpath); StreamWriter sw = new StreamWriter(strTimeLog); sw.Write(updateTime.ToString()); sw.Close(); } m_vDoc = new XmlDocument(); m_vDoc.Load(strXMLpath); } else { } XmlElement pElement = m_vDoc.SelectSingleNode("//" + strLyrName) as XmlElement; if (pElement == null) { return; } IFeatureRenderer pFeaRender = SysCommon.XML.XMLClass.XmlDeSerializer2(pElement.FirstChild.Value) as IFeatureRenderer; IGeoFeatureLayer pGeoLyr = pFealyr as IGeoFeatureLayer; pGeoLyr.Renderer = pFeaRender; } catch { } }