ThinkGeo.com    |     Documentation    |     Premium Support

GetBoundingBox Error For Image

Hi,

I’ve been using the HasBoundingBox property to see if an image has the bounding box so that I can load the image without having the user supply a world file. However, I am now finding that for any image that doesn’t have the internal bounding box defined that the HasBoundingBox property still returns True at least for the NativeImageRasterLayer type.

E.G.

if (layer.HasBoundingBox)
{
RectangleShape bounds = layer.GetBoundingBox();
// Exception thrown: ‘System.InvalidOperationException’ in ThinkGeo.MapSuite.dll

       layer = new NativeImageRasterLayer(fileName, bounds);

}

Thanks,
Damian

Thanks Damian,
I looked into the NativeImageRasterLayer. It just return true for the GetBoundingBox

public override bool HasBoundingBox
{
get { return true; }
}

and the GetBoundingBoxCore always use world file to get the Bounding box.

protected override RectangleShape GetBoundingBoxCore()
{
return worldFile.GetBoundingBox(GetImageWidthCore(), GetImageHeightCore());
}

I don’t think this one has the “internal bounding box defined”. You may need have to provide the world file. If not you could specify the whole world as bounding box.

Thanks

Frank

Hi Frank,

So you are saying the code is not correct. Any idea when it will be fixed?

This post links to my previous post about certain images having internally defined bounding boxes and thusly when loading them do not require a world file or bounding box in the constructor.

Unfortunately, if you try and create an image layer without a bounding box in the constructor and it turns out the image doesn’t have this internally defined bounding box, you get an error.

I have temporarily implemented my own HasBoundingBox method that uses a Try block to determine which constructor to use, but would clearly rather the property was fixed.

                if (!new FileInfo(worldFile).Exists)
                {
                    layer = new NativeImageRasterLayer(newFileName);
                    if (!HasBoundingBox(layer))  // My implementation
                    //if (!layer.HasBoundingBox)  // This is returning true no matter
                        layer = new NativeImageRasterLayer(newFileName, extent);
                }
                else
                    layer = new NativeImageRasterLayer(newFileName, newWorldFile);

Thanks,
Damian

Thanks Damian,
I talked with Ben. layer.HasBoundingBox means the layer support BoundingBox file. So you may need use layer.HasBoundingBox && world file exist which is the same as your current code.

Thanks

Frank