Trouble adding picture to shapefile... FileHandle = -1?

Sep 18, 2011 at 10:55 PM

Greetings,

I've been having the hardest time trying to display a .png graphic on a shapefile.  Here's the code...

        private void LoadData()
        {
            bool value;
            int handle;
            MapWinGIS.Shapefile sfStates = new MapWinGIS.Shapefile();
            value = sfStates.Open("states.shp", null);
            handle = m_Map.AddLayer(sfStates, true);
            MapWinGIS.Image image = new MapWinGIS.Image();
            value = image.Open("basketball.png", MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null);
            MapWinGIS.Shapefile shapefile = (MapWinGIS.Shapefile)m_Map.get_GetObject(handle);
            MapWinGIS.ShapeDrawingOptions options = shapefile.DefaultDrawingOptions;

            options.PointType = MapWinGIS.tkPointSymbolType.ptSymbolPicture;
            options.Picture = image;
            //options.PictureScaleX = 0.15f;
            //options.PictureScaleY = 0.15f;
            //options.FillBgTransparent = true;
            
            
        }

The shapefile will display and the boolean is true when I set a breakpoint at the end of the function.  However, I notice that the "FileHandle" property for the picture is a value of "-1".  The picture isn't that large, I believe its 180x180.  I use the installer version 4.8.4.0 and that registers the .ocx component just fine.  I've also been googling the hell outta this error and still no luck.  Any help would be greatly appreciated!

 

Thanks,

Stephen

Coordinator
Sep 19, 2011 at 1:47 PM
image.Open returns true or false.
You've just opened the image, not added it to the map.
And why are you 'getting' the shapefile again using get_GetObject. You already have the object as sfStates.

The best procedure is to open the files (shapefile or image), set any properties (drawing options, transparency) and finally add it to the map.
Sep 20, 2011 at 7:58 PM

If you look later on in the code, I add the image directly to the shape file layer.  

            MapWinGIS.Shapefile shapefile = (MapWinGIS.Shapefile)m_Map.get_GetObject(handle);
            MapWinGIS.ShapeDrawingOptions options = shapefile.DefaultDrawingOptions;

            options.PointType = MapWinGIS.tkPointSymbolType.ptSymbolPicture;
            options.Picture = image;

The reason behind doing so is because it's the only way I've discovered to set a picture at a certain angle.  I'm going to eventually be angling a plane a certain way based on the results of something else.  

That picture is then given a FileHandle of -1.  I'm worried that might be a sign of an error.  

I've also tried m_map.Refresh(); and m_map.Update(); and still no luck.

The reason I'm grabbing the shape file handle like so is because I will eventually be putting this all in its own separate function.