Tiff taking too long to load..

Dec 15, 2012 at 8:16 AM

I am creating an application using mapwingis control. I am able to display shapefiles but when I am trying to load tif file, it;s taking too long to load. Please find below sample code


public void LoadTIFF(string fileName)
    MapWinGIS.Utils u = new MapWinGIS.Utils();
    MapWinGIS.Grid grd = new MapWinGIS.Grid();
    MapWinGIS.GridColorScheme sch = new MapWinGIS.GridColorScheme();

    //check geotiff or not
    if (axMap1.IsTIFFGrid(fileName) == true)
	grd.Open(fileName, MapWinGIS.GridDataType.DoubleDataType, true, MapWinGIS.GridFileType.GeoTiff, null);

	sch.UsePredefined(Convert.ToDouble(grd.Minimum), Convert.ToDouble(grd.Maximum), MapWinGIS.PredefinedColorScheme.DeadSea);
	//This call takes time
	MapWinGIS.Image gridImage = u.GridToImage(grd, sch, null);
	//Display image
	int layerHandle = -1;
	layerHandle = axMap1.AddLayer(gridImage, true);

Also I would like to display raster as black and white i.e. don't want to use pre-defined color schemes. How can I do that.

I would appreciate help on this.


Dec 16, 2012 at 6:16 PM

What happens when you open the tiff file as an image? Normally this would be much faster.


Dec 17, 2012 at 4:39 AM
Edited Dec 17, 2012 at 4:45 AM

Hi Paul,

Thanks for reply.
When I try to open as an image using following line of code

myImage.Open(fileName, MapWinGIS.ImageType.TIFF_FILE, false, null);


and then adding it to map I am not able to see the image but when I hover a mouse over map I can see the co-ordinates are in range of tiff image. but if I add following line I am able to see the image.

myImage._pushSchemetkRaster(myScheme); //is this right thing to do?
Also could you please let me know how can I make the image to be displayed in two colours i.e. black on white background.

Dec 19, 2012 at 11:13 AM

I'm not sure how to convert your tiff file to black and white.

We use gdal (www.gdal.org) to open tiff files. Perhaps they have an option to convert your colored tiff file to black and white.

Could you send me your tiff file so I can have a look why you don't see anything when you add it as a layer.
You can send it to bontepaarden[AT]gmail[DOT]com



Jan 28, 2013 at 2:53 PM

For what it's worth, we are using MapWinGIS to display a 4 GB TIFF file and the performance is awesome.  You absolutely need the various indexing and pyramiding files though that accompany the tiff file though to get that kind of performance (for example, an .OVR file)

Jan 29, 2013 at 2:59 AM

Thanks fairbanj

Tiff files of loading are very small in few KB but the quantity is large. After few suggestions from this forum I am loading them as images with OVR files (it is certainly better than loading as an grid).

The loading time is quite high e.g.it takes about 3-4 minutes to load about 300 tiff files of an average 100KB in size. Also the after loading the map control becomes bit sluggish. Could you please give me some tips on performance improvement.

Could you please explain me bit more on indexing and overviews like how many overviews should I build. 

Feb 4, 2013 at 1:52 PM
You should have a look at vrt-files.
This is a XML file which can hold several tiff-files but reacts as just one image.
This means only the portion that is needed will be loaded in memory.
The ocx can read vrt-files. Just open it as an image file. In the Utils class you have a vrtBuilder() method that can create a vrt-file.
Here's some more info about VRT files and how you can create them manually:
Feb 6, 2013 at 4:40 AM
How can I create vrt automatically using mapwingis. I can't find vrtBuilder() method in the Utils class.
Feb 6, 2013 at 2:46 PM
Edited Feb 8, 2013 at 6:46 AM
You need to have the latest version of the ocx. If you run MapWindow you can look here how to update: http://www.mapwindow.org/phorum/read.php?4,24284
If you 'just' use the ocx, you can get the latest here: http://svn.mapwindow.org/svnroot/MapWindow4Dev/Bin/

You need to look for Utils.GDALBuildVrt();