public object Deserialize(object data)
 {
     IMemoryBlobStreamVariant str = new MemoryBlobStreamClass();
     str.ImportFromVariant(data);
     ((IVariantStreamIO)vs).Stream = (IMemoryBlobStream)str;
     object o = vs.Read();
     return o;
 }
Esempio n. 2
0
        //从数据库中读取图层设置
        public static object GetLayerConfigFromBlob(string sql, IWorkspace pConfigWks)
        {
            Exception err = null;

            Fan.Common.Gis.IGisTable pGISTable = new Fan.Common.Gis.SysGisTable(pConfigWks);

            //获取Layer
            byte[] LayerByte = pGISTable.GetFieldValue("Render", "LayerConfig", sql, out err) as byte[];

            //是否得到了序列化的blob,没得到,则返回NULL
            if (LayerByte == null)
            {
                return(null);
            }
            //从数据库中得到图层的类型
            string strLayerType = pGISTable.GetFieldValue("Render", "LayerType", sql, out err).ToString();

            ILayer pLayer = null;

            switch (strLayerType)
            {
            case "FDOGraphicsLayer":        //注记层
                pLayer = new FDOGraphicsLayerClass();
                break;

            case "DimensionLayer":          //标注层
                pLayer = new DimensionLayerClass();
                break;

            case "GdbRasterCatalogLayer":           //影像层(RC)
                pLayer = new GdbRasterCatalogLayerClass();
                break;

            case "RasterLayer":             //影像数据集(RD)
                pLayer = new RasterLayerClass();
                break;

            case "FeatureLayer":            //普通地物层
                pLayer = new FeatureLayerClass();
                break;

            default:
                pLayer = new FeatureLayerClass();
                break;
            }
            IMemoryBlobStreamVariant pMemoryBlobStreamVariant = new MemoryBlobStreamClass();

            pMemoryBlobStreamVariant.ImportFromVariant((object)LayerByte);
            IStream pStream = pMemoryBlobStreamVariant as IStream;

            if (pLayer != null)
            {
                IPersistStream pPersistStream = pLayer as IPersistStream;
                pPersistStream.Load(pStream);
                pLayer = pPersistStream as ILayer;
            }
            return(pLayer);
        }
        public static EsriDataObject ConvertToEsriDataObject(IDataObject dataObject)
        {
            //
            EsriDataObject esriDataObject = new EsriDataObject();

            // Exit if dropped object is invalid
            if (EsriDataObject.IsValid(dataObject))
            {
                // Get Byte Array from DataObject
                object       esriLayers   = dataObject.GetData(EsriRegistry.DATAOBJECT_ESRILAYERS);
                MemoryStream memoryStream = (MemoryStream)esriLayers;
                byte[]       bytes        = memoryStream.ToArray();

                // Load Byte Array into a Stream (ESRI Wrapper of IStream)
                IMemoryBlobStreamVariant memoryBlobStreamVariant = new MemoryBlobStreamClass();
                memoryBlobStreamVariant.ImportFromVariant(bytes);
                IMemoryBlobStream2 memoryBlobStream = (IMemoryBlobStream2)memoryBlobStreamVariant;
                IStream            stream           = (IStream)memoryBlobStream;

                // Load Stream into an ESRI ObjectStream
                IObjectStream objectStream = new ObjectStreamClass();
                objectStream.Stream = stream;

                // Get Number of Layers in Dropped Object
                byte pv;
                uint cb = sizeof(int);
                uint pcbRead;
                objectStream.RemoteRead(out pv, cb, out pcbRead);
                int count = Convert.ToInt32(pv);

                // Define Guids
                Guid guidLayer = new Guid(EsriRegistry.INTERFACE_ILAYER);
                Guid guidTable = new Guid(EsriRegistry.INTERFACE_ITABLEPROPERTY);

                // Get Dropped Layers
                for (int i = 0; i < count; i++)
                {
                    object o     = objectStream.LoadObject(ref guidLayer, null);
                    ILayer layer = (ILayer)o;
                    esriDataObject.LayerCollection.Add(layer);
                }

                // Get Dropped TableProperties
                for (int i = 0; i < count; i++)
                {
                    object o = objectStream.LoadObject(ref guidTable, null);
                    if (o == null)
                    {
                        continue;
                    }
                    ITableProperty tableProperty = (ITableProperty)o;
                    esriDataObject.TablePropertyCollection.Add(tableProperty);
                }
            }

            return(esriDataObject);
        }
Esempio n. 4
0
        public object Deserialize(object data)
        {
            IMemoryBlobStreamVariant str = new MemoryBlobStreamClass();

            str.ImportFromVariant(data);
            ((IVariantStreamIO)vs).Stream = (IMemoryBlobStream)str;
            object o = vs.Read();

            return(o);
        }
Esempio n. 5
0
        public static ESRI.ArcGIS.Carto.IFeatureRenderer LoadRendererFromByte(byte[] _RendererValue, string _RendererType)
        {
            if (_RendererValue == null || _RendererValue.Length == 0)
            {
                return(null);
            }
            try
            {
                enumRendererType pRendererType = (enumRendererType)Enum.Parse(typeof(enumRendererType), _RendererType);
                ESRI.ArcGIS.Carto.IFeatureRenderer pRenderer = null;
                switch (pRendererType)
                {
                case enumRendererType.SimpleRenderer:
                    pRenderer = new ESRI.ArcGIS.Carto.SimpleRendererClass();
                    break;

                case enumRendererType.UniqueValueRenderer:
                    pRenderer = new ESRI.ArcGIS.Carto.UniqueValueRendererClass();
                    break;

                case enumRendererType.BreakColorRenderer:
                    pRenderer = new ESRI.ArcGIS.Carto.ClassBreaksRendererClass();
                    break;

                case enumRendererType.BreakSizeRenderer:
                    pRenderer = new ESRI.ArcGIS.Carto.ClassBreaksRendererClass();
                    break;
                }

                if (pRenderer == null)
                {
                    return(null);
                }

                IMemoryBlobStreamVariant pMemoryBlobStreamVariant = new MemoryBlobStreamClass();
                pMemoryBlobStreamVariant.ImportFromVariant((object)_RendererValue);
                IStream        pStream        = pMemoryBlobStreamVariant as IStream;
                IPersistStream pPersistStream = pRenderer as IPersistStream;
                pPersistStream.Load(pStream);
                pRenderer = pPersistStream as ESRI.ArcGIS.Carto.IFeatureRenderer;
                return(pRenderer);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 得到Renderer从数据库中
        /// </summary>
        /// <returns></returns>
        public static object GetRendererFromBlob(string sql, IWorkspace pConfigWks)
        {
            Exception err = null;

            SysCommon.Gis.IGisTable pGISTable = new SysCommon.Gis.SysGisTable(pConfigWks);

            //获取Renderer
            byte[] renderByte = pGISTable.GetFieldValue("Render", "Render", sql, out err) as byte[];

            //是否得到了序列化的blob,没得到,则返回NULL
            if (renderByte == null)
            {
                return(null);
            }

            IMemoryBlobStreamVariant pMemoryBlobStreamVariant = new MemoryBlobStreamClass();

            pMemoryBlobStreamVariant.ImportFromVariant((object)renderByte);
            IStream pStream = pMemoryBlobStreamVariant as IStream;

            //从数据库中得到符号的类型  shduan 20110721 增加RasterRenderer
            string strRenderType = pGISTable.GetFieldValue("Render", "RenderType", sql, out err).ToString();
            string strLyrType    = pGISTable.GetFieldValue("Render", "LayerType", sql, out err).ToString();

            if (strLyrType == "RasterLayer")
            {
                IRasterRenderer pRRenderer = null;
                switch (strRenderType)
                {
                case "RasterClassifyColorRampRenderer":
                    pRRenderer = new RasterClassifyColorRampRendererClass();
                    break;

                case "RasterUniqueValueRenderer":
                    pRRenderer = new RasterUniqueValueRendererClass();
                    break;

                case "RasterDiscreteColorRenderer":
                    pRRenderer = new RasterDiscreteColorRendererClass();
                    break;

                case "RasterRGBRenderer":
                    pRRenderer = new RasterRGBRendererClass();
                    break;

                case "RasterStretchColorRampRenderer":
                    pRRenderer = new RasterStretchColorRampRendererClass();
                    break;
                }
                IPersistStream pPersistStream = pRRenderer as IPersistStream;
                pPersistStream.Load(pStream);
                //pRRenderer = pPersistStream as IRasterRenderer;

                return(pRRenderer);
            }
            else
            {
                IFeatureRenderer pFRenderer = null;
                switch (strRenderType)
                {
                case "AnnoColor":
                    string sAnnoColor = Encoding.Default.GetString(renderByte);
                    return((object)sAnnoColor);

                case "SimpleRenderer":
                    pFRenderer = new SimpleRendererClass();
                    break;

                case "UniqueValueRenderer":
                    pFRenderer = new UniqueValueRendererClass();
                    break;

                case "ClassBreaksRenderer":
                    pFRenderer = new ClassBreaksRendererClass();
                    break;

                case "ProportionalSymbolRenderer":
                    pFRenderer = new ProportionalSymbolRendererClass();
                    break;

                case "ChartRenderer":
                    pFRenderer = new ChartRendererClass();
                    break;
                }
                IPersistStream pPersistStream = pFRenderer as IPersistStream;
                pPersistStream.Load(pStream);
                pFRenderer = pPersistStream as IFeatureRenderer;

                return(pFRenderer);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Method called when a feature is modified.
        /// </summary>
        /// <param name="obj">The object that was created</param>
        public void Events_OnChangeFeature(IObject obj)
        {
            if (EditorTrackHelper.extensionEnabled && trackingFields != null && obj != null)
            {
                ReplacementTemplate globaltemplates    = trackingFields.TemplateOnChangeFields[Constants.GlobalName];
                ReplacementTemplate featclasstemplates = null;

                if (trackingFields.TemplateOnCreateFields.ContainsKey((obj.Class as IDataset).Name))
                {
                    featclasstemplates = trackingFields.TemplateOnChangeFields[(obj.Class as IDataset).Name];
                }

                if (globaltemplates != null && globaltemplates.FieldReplacements != null)
                {
                    foreach (KeyValuePair <string, string> item in globaltemplates.FieldReplacements)
                    {
                        int i = obj.Fields.FindField(item.Key);

                        if (i > -1)
                        {
                            object val = this.EvaluateValue(obj, item, trackingFields.ReplacementFieldDictionary);

                            if (val != null)
                            {
                                if (val is byte[])
                                {
                                    IMemoryBlobStreamVariant memoryBlobStream = new MemoryBlobStreamClass();
                                    memoryBlobStream.ImportFromVariant(val);

                                    obj.set_Value(i, memoryBlobStream);
                                }
                                else
                                {
                                    obj.set_Value(i, val);
                                }
                            }
                        }
                    }
                }

                if (featclasstemplates != null && featclasstemplates.FieldReplacements != null)
                {
                    foreach (KeyValuePair <string, string> item in featclasstemplates.FieldReplacements)
                    {
                        int i = obj.Fields.FindField(item.Key);

                        if (i > -1)
                        {
                            object val = this.EvaluateValue(obj, item, trackingFields.ReplacementFieldDictionary);

                            if (val != null)
                            {
                                if (val is byte[])
                                {
                                    IMemoryBlobStreamVariant memoryBlobStream = new MemoryBlobStreamClass();
                                    memoryBlobStream.ImportFromVariant(val);

                                    obj.set_Value(i, memoryBlobStream);
                                }
                                else
                                {
                                    obj.set_Value(i, val);
                                }
                            }
                        }
                    }
                }
            }
        }