Unable to remove and Image layer

Jan 27, 2011 at 3:45 PM

Hello,

I am working on an application using the dotspatial dll's to retreive and display an image from a web service. This image is saved to the drive along with the prj information and then added as a layer to the map and legend. When the user pans or zooms the previously added image layer is removed and a new layer is added.

Everything was working fine in the previous build, but in the latest build - 12/15/2010, Map.Layers.Remove(IMapLayer) is throwing an error. The stack trace or the error is below:

   at DotSpatial.Data.InRamImageData.OnBoundsChanged(IRasterBounds bounds) in c:\Dev\DotSpatial\DotSpatial.Data\DotSpatial.Data\InRamImageData.cs:line 457
   at DotSpatial.Data.RasterBoundDataSet.set_Bounds(IRasterBounds value) in c:\Dev\DotSpatial\DotSpatial.Data\DotSpatial.Data\RasterBoundDataSet.cs:line 57
   at DotSpatial.Data.RasterBoundDataSet.set_Bounds(IRasterBounds value) in c:\Dev\DotSpatial\DotSpatial.Data\DotSpatial.Data\RasterBoundDataSet.cs:line 51
   at DotSpatial.Data.ImageData.Dispose(Boolean disposeManagedResources) in c:\Dev\DotSpatial\DotSpatial.Data\DotSpatial.Data\ImageData.cs:line 538
   at DotSpatial.Data.DisposeBase.Dispose() in c:\Dev\DotSpatial\DotSpatial.Data\DotSpatial.Data\DisposeBase.cs:line 55
   at DotSpatial.Symbology.Layer.Dispose(Boolean disposeManagedResources) in c:\Dev\DotSpatial\DotSpatial.Symbology\DotSpatial.Symbology\Layer.cs:line 865
   at DotSpatial.Symbology.ImageLayer.Dispose(Boolean disposeManagedResources) in c:\Dev\DotSpatial\DotSpatial.Symbology\DotSpatial.Symbology\ImageLayer.cs:line 173
   at DotSpatial.Symbology.Layer.Dispose() in c:\Dev\DotSpatial\DotSpatial.Symbology\DotSpatial.Symbology\Layer.cs:line 784
   at DotSpatial.Symbology.LayerEventList`1.OnExclude(T item) in c:\Dev\DotSpatial\DotSpatial.Symbology\DotSpatial.Symbology\LayerEventList.cs:line 220
   at DotSpatial.Symbology.LayerCollection.OnExclude(ILayer item) in c:\Dev\DotSpatial\DotSpatial.Symbology\DotSpatial.Symbology\LayerCollection.cs:line 100
   at DotSpatial.Serialization.BaseList`1.RemoveAt(Int32 index) in c:\Dev\DotSpatial\DotSpatial.Serialization\DotSpatial.Serialization\BaseList.cs:line 160
   at 

 

This is my code for adding the layer, which I am trying to remove:

 IImageData imageData = new ImageData(string.Format("{0}\\{1}.jpg", Properties.Settings.Default.ApplicationFilesLocation, fileName));

IMapImageLayer layer = new MapImageLayer(imageData);

GlobalVariable.g_Map.Layers.Add(layer);

layer.LegendText = layerName;

Please let me know how I can fix this.

Thanks,

VK.

Developer
Jan 27, 2011 at 4:42 PM

This looks like a bug related to extents and is probably a quick fix.  I would report this as an issue instead of a discussion because this looks like a an invalid casting exception or null exception that probably came about by the changes from Envelope to Extent.  In the mean time, you can probably skate around the issue by just keeping a single image layer loaded, for instance, and changing the ImageData that it uses as the data object and updating the extents as you swap out images.  But yes, this looks like something that needs to be fixed on our end at line 457 in InRamImageData.

Ted

Jan 27, 2011 at 5:05 PM

Thanks Ted,

I have added this as an issue. I will try your approach to delete a layer for now.

Thanks,

VK.

Jan 27, 2011 at 7:42 PM

Ted,

I am getting the same error on following your approach.

Here's what I tried:

IMapImageLayer layer = GetLayer(removeLayerName) as IMapImageLayer; 
IImageData imageData = new ImageData(string.Format("{0}\\{1}.jpg", Properties.Settings.Default.ApplicationFilesLocation, fileName)); 
layer.DataSet = imageData; 
Please advise.

Thanks,

VK.

Developer
Jan 28, 2011 at 3:16 PM

You said you were working with the December release.  Maybe if you got the latest release from source and built it this bug would be addressed.  I had planned on creating a release last weekend but never got around to it.  I will do so this weekend though.  But you can build any time from the latest source, which has had some bug fixes and changes, so maybe this is addressed.

Ted

 

May 11, 2011 at 11:16 PM

Ted,

I am getting this error with the latest buid - DotSpatial 4-22-2011.

It was working fine with earlier builds. Please advise.

Thank you,

VK.

Jun 22, 2011 at 1:14 PM

Hi Ted,

I'm still getting this error with the latest build 5-23-2011

Is there any planned fix? Or a work around?

thanks

matt

Aug 29, 2011 at 10:39 PM

Ted,

Is there any fix for this?

Thanks,

VK.

Aug 30, 2011 at 8:44 PM

This method in InRamImageData.cs seems to be causing the exception

  protected override void OnBoundsChanged(IRasterBounds bounds)
        {
            WorldFile.Affine = bounds.AffineCoefficients;
        }
 I Commented it out and everything I need seems to be working. I did this on the source code associated with the 05/23 release.

Thanks,

VK.