Jul 15, 2010 at 3:29 PM
Edited Jul 15, 2010 at 3:37 PM
After fixing my problems with getting GdalRasterLayers to work, I’ve started to create my WMS application. I have got the following code adding some layers to the map:
SharpMap.Layers.LayerGroup os250k = new SharpMap.Layers.LayerGroup("os250k");
os250k.SRID = 27700;
DirectoryInfo di = new DirectoryInfo(@"s:\data\opendata\250k");
foreach (FileInfo fi in di.GetFiles("*.tif"))
SharpMap.Layers.GdalRasterLayer layer = new SharpMap.Layers.GdalRasterLayer(fi.Name, @"s:\data\opendata\250k\" + fi.Name);
layer.SRID = 27700;
Essentially it takes all the TIF files within the directory and adds them to the map, all under a group called “os250k”. This appears to work okay, but there are a few problems that I’ve encountered.
The first problem is that a WMS request to “…/wms.aspx?request=GetMap&layers=os250k&bbox=0,0,100000,100000&width=400&height=400&crs=EPSG:27700&styles=normal&Format=image/png&version=1.3.0” gives the error:
Server Error in '/' Application.
Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[IndexOutOfRangeException: Index was outside the bounds of the array.]
SharpMap.Layers.GdalRasterLayer.GetPreview(Dataset dataset, Size size, Graphics g, BoundingBox displayBbox, ICoordinateSystem mapProjection, Map map) +9175
SharpMap.Layers.GdalRasterLayer.Render(Graphics g, Map map) +64
SharpMap.Layers.LayerGroup.Render(Graphics g, Map map) +121
SharpMap.Map.RenderMap(Graphics g) +240
SharpMap.Web.Wms.WmsServer.ParseQueryString(Map map, WmsServiceDescription description) +7068
Bluefox.WMS.WMS.Page_Load(Object sender, EventArgs e) +651
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
Which shouldn’t be occuring as the map data covers more than enough area to allow for this bit to be clipped out. It would appear that it’s failing when it comes to spanning more than one of the basemap TIFs maybe? Is there no way I can have
a layer made up of more than one TIF image? If not, then I’m pretty much stuck as a single image for that layer would be huge!
The second issue I’m having is that one of the layers in my map is formed of 25GB of TIF images, so adding them all to the map at one time simple isn’t possible. There are around 10.5k TIF images covering the whole of the UK at street level.
Is it possible for me to somehow figure out which of these images should be loaded into the map depending on the bounding box specified by the WMS call rather than attempting to load in 10.5k TIFs every time a request is made? As it stands now it times out
due to loading in too many files.
Thanks for any help you can provide.
Jul 15, 2010 at 11:44 PM
I'm sorry that I cannot reproduce your issue. I don't know what kind of tif images you use.
There is nothing wrong with your approach though, you should be able to wrap several gdalrasterlayers in a layergroup. I suspect that (s)one of your tif files has some oddity that causes the error. Unfortunately I cannot tell from the stacktrace you posted
at which line the error occurs, so could you please setup/modifiy a sample within the WinFormsSample project, to see if the error occurs there, too, and to locate the image in question and the line GdalRasterLayer fails.
Have you tried using virtual rasters with gdal? That way you wont have to add several image to a layergroup, just one "catalog" of rasters. On top of that you could build
pyramids for the virtual raster, that would result in better performance if your viewport requires a lot of scaling to produce the image. Be aware those pyramid image get huge.
Thanks, I’ll look into your suggestions. The virtual rasters bit sounds really promising as it’s exactly what I think I need to do. It’ll certainly make things more efficient. Thanks again for all your help this week!
Brilliant, that works perfectly. Using the virtual raster also solved the problem I was having with the out of bounds error. Thanks again!