I am making a WMS service that is able to handle different types of data. I am using SharpMap 1.0 (the downloaded version).
For Shapefiles the server is working perfectly. The files are reprojected on the fly and projected as a layer in an OpenLayers application.
For the Rasterfiles I have decided to use Gdal Warp to reproject the files into a temporary file (see thread 611767). The layer tiles are rendered from these temporary files. For some unknown reasons some of the tiles are rendered as a black image and others
are rendered correctly. After a while (zooming in and out) the problem disappears. I have spent quite some time trying to fix this problem but I still have no idea where the problems comes from.
I suspect that is has something to do with a (GDI) file-lock after it is created. It looks like the file does not except too many request at the same time just after it is created. I have read some Threads about a GDI+ problem, but did not really find a solution
I suppose the problem is somewhere in GdalRasterLayer.cs, but I do not know which part of code is causing it. I was hoping one of you could point me in the right direction, so I could try to fix it. In the case it is too complex to fix I would like to try a
workaround by checking if the error occurs and redraw the tile. Because I am not going to check all cells one-by-one I need to find which piece of code is causing the problem.
I am creating the temporary file as follows:
// creating a reprojected temporary raster file. Reprojecting on the fly is too heavy to compute.
// declaring the GDAL driver
// determine target format
if (Path.GetExtension(path) == ".asc")
dout = Gdal.GetDriverByName("AAIGrid");
dout = Gdal.GetDriverByName("GTiff");
// target projection
string refnew = "PROJCS[\"WGS 84 / Pseudo-Mercator\",GEOGCS[\"WGS 84\",DATU....etc.;
// open the file
ra = Gdal.Open(path, Access.GA_ReadOnly);
WmsException.ThrowWmsException("unable to open file");
// get current projection
string refone = ra.GetProjection();
// rewarp into new projection
warp = Gdal.AutoCreateWarpedVRT(ra, refone, refnew, ResampleAlg.GRA_NearestNeighbour, 0.0);
// if not able to reproject create an image
WmsException.ThrowWmsException("The projection is not supported try: " + ImageHelper.rasterMap(path));
// save temporary image.
dout.CreateCopy(url, warp, 0, null, null, "");
And rendering the tiles as follows:
//creating the raster map for the tiles
public static Map RasterTiles(string path)
Map map = new Map(new Size(1, 1));
// The layer is always called "shapefile" since there is only one layer at a time
GdalRasterLayer rlay = new GdalRasterLayer("shapefile", path);
rlay.Transparency = 20;
// adding layer to map
Perhaps a little bit off topic but it could be important for people with a related issue:
I also found another problem with GDI on IIS express. I received a general GDI+ error. Apparently this error only occurs under certain circumstances. I had to make the following workaround at the end of Cache.cs in sharpmap.web to let it work (really ugly):
MemoryStream tempStream = new MemoryStream();
Image map2 = Image.FromStream(tempStream);
using (var stream = new MemoryStream())
HttpContext.Current.Cache.Insert(guid, stream.ToArray(), null,
I work on a windows XP computer with visual 2010 + IIS express server.
Sorry for the long post and thanks in advance.