BruTile (FileTileProvider)

Apr 18, 2011 at 11:49 AM
Edited Apr 18, 2011 at 11:51 AM

Hi,

I have the following situation:

I have in my local E:\SLUPH\Maps\25000\ around 300 images with extension .sid, all of them georeferenced. So I want to render on mapImage like Tiles. The initial view is in the point (X: 377107, Y: 4671200 with a resolution of 25000). I did something like this:

 

const string DATA_PATH = @"E:\SLUPH\Mapas\25000\";
private void Form1_Load(object sender, EventArgs e)
{
mapa = new SharpMap.Map(mapImage1.Size);
mapa.BackColor = Color.Black;

//GDAL //SharpMap.Layers.GdalRasterLayer MapLayer = new SharpMap.Layers.GdalRasterLayer(DATA_NAME, DATA_PATH); //mapa.Layers.Add(MapLayer); // ######### // BruTile // ######### ITileSchema schema = CreateTileSchema(); ITileSource tileSource = new TileSource(new BruTile.FileSystem.FileTileProvider
(new FileCache(DATA_PATH, "sid")), schema);

TileLayer tileLayer = new TileLayer(tileSource, "OSM");

mapa.Layers.Add(tileLayer);

//--> Zoom the map to the entire extent
mapa.ZoomToExtents();
mapImage1.Image = mapa.GetMap();
}

private static ITileSchema CreateTileSchema()
{

double[] resolutions = new double[] {
250, 1000, 2500, 5000, 10000, 25000, 50000, 125000, 250000};

TileSchema schema = new TileSchema();
schema.Name = "Catalu�aMaps";
foreach (float resolution in resolutions) schema.Resolutions.Add(resolution);
schema.OriginX = 377107;
schema.OriginY = 4671200;
schema.Axis = AxisDirection.InvertedY;
schema.Extent = new Extent(377107, 377107, 4671200, 4671200);
schema.Height = 256;
schema.Width = 256;
schema.Format = "sid";
schema.Srs = "EPSG:900913";
return schema;
}

But after that, the mapImage is empty. Any idea?

Thanks!

Coordinator
Apr 19, 2011 at 7:51 AM

hi Javier,

sid is not a supported format. I never tried to work with it myself. With the current architecture the binary image data is directly converted to an image class by either WPF/SL or GDI+. This will fail for the sid format because it isnt a regular image format. So even if there is a way to read sid then the architecture needs to change to allow some converter. 

I would actually expect an exception when trying to read sid so perhaps there is also a problem with the tile schema. You need to define a tile schema that corresponds with the way your sid files are tiled. If you proceed with this approach I would advice to include the BruTile prj in your solution so you can step through all the code.

Paul

Apr 19, 2011 at 10:09 AM

Thanks Paul,

I will try to convert my images to TIFF extension.

Apr 19, 2011 at 11:52 AM

Can I use TIFF images really? Is the same TIFF and GeoTIFF?

Coordinator
Apr 19, 2011 at 12:54 PM

I use the .net framework capabilities to read images. I expect tiff to work as well. GeoTiff is Tiff was some extra meta info. It should not make a difference. The meta info is not used by BruTile though. All meta info is in the schema definition.

Paul

Apr 20, 2011 at 9:08 AM
Edited Apr 20, 2011 at 10:02 AM

Now, I try with this code:

 

const string DATA_PATH = @"E:\SLUPH\Mapas\25000\";

private void Form1_Load(object sender, EventArgs e)
{
mapa = new SharpMap.Map(mapImage1.Size);
mapa.BackColor = Color.Black;

// #### BruTile #### SharpMap.Geometries.BoundingBox worldBox = new SharpMap.Geometries.BoundingBox(257925, 4484617, 535702, 4752699);
ITileSchema schema = CreateTileSchema();
ITileSource tileSource = new TileSource(new BruTile.FileSystem.FileTileProvider
(new FileCache(DATA_PATH, "tif")), schema);

TileLayer tileLayer = new TileLayer(tileSource, "tif");

mapa.Layers.Add(tileLayer);

//--> Zoom the map to the entire extent mapa.ZoomToExtents(); // It is necessary? I tried both
mapImage1.Image = mapa.GetMap();
}

 

My image is totally black, my function CreateTileSchema is as before. I miss something?

Some doubts:

1.- I am not sure which values I have to put in schema.Resolutions.

2.- Is it necessary rename the image files with some format?

3.- How TileCache take a TileIndex and the associated bitmap? I need define TileIndex?

Coordinator
Apr 23, 2011 at 9:30 AM

The problem is probably that your schema is not correct. It is not very easy to get this rigth. You have to try to get some understanding of how things work. And I advise you start stepping through the BruTile code see how it works. 

The way things should work as that the tiles are generated by some tool that also generates the schema for you. In your case you have to reverse engineer the schema from your tile set. 

Paul

May 4, 2011 at 8:22 AM
Edited May 4, 2011 at 12:04 PM

After reading BruTile code, I reestructured my directory tree to use FileCache. I have now 3 folders for each zoom level, each level contain some folders for each column, and each column folder has the images named by rows.

Now, the images from the same column folder have same height but different width. And the image height in the different column folders are different. Is it possible? Because I must configure schema.width and schema.height for all images with same values, really?

Example: E:\Maps\Level_1\Col_3\Row_0.tif   --> Size: 1429x970

       \Row_1.tif --> Size: 1431x970

E:\Maps\Level_1\Col_4\Row_0.tif --> Size: 1416x968

       \Row_1.tif --> Size: 1414x968

May 4, 2011 at 4:11 PM

My problem appears in the next command:

IList<TileInfo> infos = schema.GetTilesInView(mapTransform.Extent, level);
Because infos.count = 0. I will continue researching

May 5, 2011 at 8:45 AM

In this function:

                 public IList<TileInfo> GetTilesInView(Extent extent, int level)

¿Which values I have to put in Extent( minX, minY, maxX, maxY)?

Coordinator
May 8, 2011 at 8:29 AM

hi Javier,

unfortunately it is not possible to have differences in width/height between resolutions. I would like to add this because it is needed by the WMTS protocol. But I probably won't allow differences in width and height between columns. A possible workaround is to put the sets of same width/height each in separate schemas.

But actually, looking at the sizes of your tiles, I think you source data is not suited for a BruTile layer at all. BruTile is meant for tile sets that are cut up into tiles for faster performance. Your tile sets could better be handles by a GDALLayer. You could try to generate a TMS tile sets from the GDALLayer.

Paul

Developer
May 10, 2011 at 11:59 PM

you can try to process the mrsids' with MapTiler http://www.maptiler.org/ and then use the generated tiles in BruTile. Steps are basically described here http://arcbrutile.codeplex.com/wikipage?title=ArcBruTile%20and%20MapTiler 

Coordinator
May 11, 2011 at 9:32 AM

@bertt Good idea!