Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have an IMap (include elements: text, line) and I want to store it into a field of a table in SQL, so I can load it again later. I used below codes, but I got an the error :

public class Test 
{
  IStream stream;
  IMap myMap;
  void Save()
  {
    IPersistStream perStream;
    IMemoryBlobStream memoryStream = new MemoryBlobStreamClass();
    stream = memoryStream as IStream;
    perStream = (IPersistStream ) myMap ;
    perStream.Save(stream, 0);  
  }
  void Load()
  {
     IMemoryBlobStream memoryStream = new MemoryBlobStreamClass();
     IPersistStream pstm = new MapClass();  
     pstm.Load(stream); **// throw error: Error HRESULT E_FAIL has been returned from a call to a COM component.**

     myMap = (IMap)pstm;     
  }
}

Are there anyone can help ?

Thanks and regards,


I found out one way to save elements to an binary file and can load it again later as below codes:

void Save (AxPageLayoutControl pageControl)
{
                IPersistStream perStream;
                IMemoryBlobStream memoryStream = new MemoryBlobStreamClass();

                IGraphicsContainer graphicsContainer = pageControl.ActiveView.GraphicsContainer;
                graphicsContainer.Reset();
                IElement pElement = graphicsContainer.Next();
                while (pElement != null)
                {
                    if (pElement is IMapFrame)
                    {
                        perStream = (IPersistStream)pElement ;
                        perStream.Save(memoryStream, 0);

                        memoryStream.SaveToFile("C:/image.bmp"); 
                        break;

                    }
                    pElement = graphicsContainer.Next();
                }
}

void Load (AxPageLayoutControl pageControl)
{
            IPersistStream perStream;
            IMemoryBlobStream memoryStream = new MemoryBlobStreamClass();
            IGraphicsContainer graphicsContainer = pageControl.ActiveView.GraphicsContainer;
            graphicsContainer.Reset();
            IElement pElement = graphicsContainer.Next();
            while (pElement != null)
            {
                if (pElement is IMapFrame)
                {

                    memoryStream.LoadFromFile("C:/image.bmp");
                    perStream = (IPersistStream)pElement;
                    perStream.Load(memoryStream);
                    IMapFrame frame = new MapFrameClass();
                    frame   = (IMapFrame)perStream;
                    pElement = (IElement)frame;
                    break;

                }                
                pElement = graphicsContainer.Next();
            }
            pageControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}

But, I am finding a way to convert IPersistStream or IMemoryBlobStream to byte[] format, so I can store in SQL Server and load later. Are there anyone know this ?

Thanks and regards,

share|improve this question
    
So do you want to store just the elements, the map or the entire map document? –  blah238 Oct 29 '12 at 3:26
    
@blah238: I am not sure, any suitable ways, maybe all elements (that I added into the IMap via the satement: IGraphicsContainer.AddElement(..)). I want to store it into binary data format in SQL, then can load it later into my IMap –  taibc Oct 29 '12 at 4:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.