Newby asking for help

Feb 7, 2012 at 2:29 PM
Edited Feb 7, 2012 at 2:30 PM

Hi guys,

I've created some tiles of a region in germany. All are saved as png files with heigthxwidt = 256x256px.

Now I'm trying to load them via Brutile. They should be shown on a picturebox.

tiles\1\0 - 2 pics (north west, south west of the region)

tiles\1\1 - 2 pics (noth east, south east of the region)

tiles\2\0 - 3 pics

tiles\2\1  - 3 pics

tiles\2\2   - 3 pics

tiles\2\3   - 3 pics

and so on. Every subdirectory of tiles includes another zoom level.

Can anybody explain to me how i can load for example the file from tiles\1\... to the picturebox?

I tried it like this.

const string DATA_PATH = @"D:/myfiles/Dokumente/Bachelorarbeit/code_und_co/tiles/";

FileTileProvider ftp = new FileTileProvider(new BruTile.Cache.FileCache(DATA_PATH, "png"));


and add it to a SharpMap

_sharpMap = new SharpMap.Map(new Size(600, 300));

_sharpMap.BackColor = Color.Transparent;            

ITileSource tileSource = new TileSource(ftp, new BruTile.PreDefined.SphericalMercatorInvertedWorldSchema());

TileLayer tL = new TileLayer(tileSource, "TestLayer");



picMap.Image = _sharpMap.GetMap();


I'm new at both thematics (sharpmap and brutile) so it would be nice if anybody could help. 

I was searching at and other discussions before, but can't find an entry for me to get it working.

Feb 7, 2012 at 3:08 PM

You need to know in what tileschema those tiles are. How did you end up with a number of tiles on your disk? How were they generated? If you don't know the schema I will be very hard to find it with find it with trial and error.

The MapTiler sample of Mapsui.Windows.cs might help, but still you need the right schema.

Feb 14, 2012 at 8:20 AM
Edited Feb 14, 2012 at 8:30 AM

Thanks for your reply.

folder structure



















tiles\3          subfolder 1-6; in every sub 1.png - 4.png

tiles\4          subfolder 2-13; in every sub 2.png - 9.png

... and so on.

all files have the same size (width x height) but different zoom levels of the region.


which infos do i have to know to work with this files?

I'm realy interested but i don't have a good overview  about this stuff yet.

thanks for all your replies and tries to help.

Feb 27, 2012 at 9:59 AM
Edited Feb 27, 2012 at 10:02 AM

i get it to work. here is my code

public Form1()

            sharpMapImage = InitMapImage(new Size(contentContainer.Panel2.Width, contentContainer.Panel2.Height));
            contentContainer.BorderStyle = BorderStyle.Fixed3D;

            CoordinateSystemFactory csf = new CoordinateSystemFactory();

            IGeographicCoordinateSystem wgs84 = csf.CreateGeographicCoordinateSystem("WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East));
            EPSG4326 = wgs84;

            List<ProjectionParameter> parameters = new List<ProjectionParameter>();
            parameters.Add(new ProjectionParameter("semi_major", 6378137.0));
            parameters.Add(new ProjectionParameter("semi_minor", 6378137.0));
            parameters.Add(new ProjectionParameter("latitude_of_origin", 0.0));
            parameters.Add(new ProjectionParameter("central_meridian", 0.0));
            parameters.Add(new ProjectionParameter("scale_factor", 1.0));
            parameters.Add(new ProjectionParameter("false_easting", 0.0));
            parameters.Add(new ProjectionParameter("false_northing", 0.0));
            IProjection projection = csf.CreateProjection("Google Mercator", "mercator_1sp", parameters);
            EPSG900913 = csf.CreateProjectedCoordinateSystem("Google Mercator", wgs84, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

private SharpMap.Forms.MapImage InitMapImage(Size size)
            BruTile.Cache.FileCache fileCache = new BruTile.Cache.FileCache(tileCachePath, tileFileType);
            BruTile.FileSystem.FileTileProvider fileProvider = new BruTile.FileSystem.FileTileProvider(fileCache);
            TileSource tileSource = new TileSource(fileProvider, new BruTile.PreDefined.SphericalMercatorInvertedWorldSchema());

            SharpMap.Map _map = new SharpMap.Map(size);
            _map.BackColor = Color.Transparent;

            var tileLayer = new SharpMap.Layers.TileLayer(tileSource, tileCacheName);
            SharpMap.Forms.MapImage _img = new SharpMap.Forms.MapImage();
            _img.Size = size;
            _img.Map = _map;
            _img.ActiveTool = SharpMap.Forms.MapImage.Tools.ZoomIn;
            _img.ActiveTool = SharpMap.Forms.MapImage.Tools.Pan;
            return _img;

Feb 27, 2012 at 10:02 AM

Thanks for posting this back!


Feb 27, 2012 at 10:11 AM
Edited Feb 27, 2012 at 10:29 AM

Now i have a new problem.

I've calculated the convex hull of a polygon and want to draw it on my map.

but if I try the folowing the LinearRing has an false value at "IsRing"


LinearRing lr = new LinearRing(pointArray);                SharpMap.Geometries.Polygon poly = new Polygon();
if i insert the point that i added first again after all others the value is true.
LinearRing lr = new LinearRing(pointArray);                
SharpMap.Geometries.Polygon poly = new Polygon(lr);

after that, I create a GeometryProvider and VectorLayer and assign it to the map
ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctfac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
var gp = new SharpMap.Data.Providers.GeometryProvider(poly);                
VectorLayer vl = new VectorLayer(layerName);                
vl.CoordinateTransformation = ctfac.CreateFromCoordinateSystems(EPSG4326, EPSG900913);
vl.DataSource = gp;                
Color col = Color.FromArgb(2, color);                
vl.Style.Fill = new SolidBrush(col);                


The problem is that the polygon is not painted. If i create a multipoint and set it as GeometryProvider, it is working (same input Points). Can anyone tell me where is the mistake ???

Feb 27, 2012 at 10:42 AM

Is IsRing  false directly after creating it? Did you close this ring, i.e. the start and endpoint is the same?


Feb 27, 2012 at 11:00 AM
Edited Feb 27, 2012 at 11:12 AM

directly after creating it, the IsRing value has no value: "System.Application.Exception"

After adding my posittions / points the ring ist true. start and endpoint are the same:


_Vertices Count = 17 System.Collections.Generic.IList<SharpMap.Geometries.Point> {System.Collections.ObjectModel.Collection<SharpMap.Geometries.Point>}

EndPoint {POINT (10.96406 51.85224)} SharpMap.Geometries.Point

GeometryType LineString SharpMap.Geometries.GeometryType2

IsRing true bool

Length 0.19984660752416503 double

NumPoints 17 int+ StartPoint {POINT (10.96406 51.85224)} SharpMap.Geometries.Point

Area 0.0026499742999703813 double


The Points are gps positions presenting the convex hull of a polygon area:


[0] {POINT (10.96406 51.85224)} SharpMap.Geometries.Point  	[1] {POINT (10.93637 51.83149)} SharpMap.Geometries.Point

[2] {POINT (10.93186 51.8244)} SharpMap.Geometries.Point	[3] {POINT (10.92811 51.80885)} SharpMap.Geometries.Point

[4] {POINT (10.92836 51.80831)} SharpMap.Geometries.Point	[5] {POINT (10.93987 51.79237)} SharpMap.Geometries.Point

[6] {POINT (10.94113 51.79187)} SharpMap.Geometries.Point	[7] {POINT (10.94192 51.79172)} SharpMap.Geometries.Point

[8] {POINT (10.94274 51.79164)} SharpMap.Geometries.Point	[9] {POINT (10.95442 51.79065)} SharpMap.Geometries.Point

[10] {POINT (10.95515 51.79059)} SharpMap.Geometries.Point	[11] {POINT (10.97929 51.79452)} SharpMap.Geometries.Point

[12] {POINT (10.98687 51.79607)} SharpMap.Geometries.Point	[13] {POINT (10.99739 51.80222)} SharpMap.Geometries.Point

[14] {POINT (10.99782 51.8037)} SharpMap.Geometries.Point	[15] {POINT (10.99788 51.80406)} SharpMap.Geometries.Point

[16] {POINT (10.96406 51.85224)} SharpMap.Geometries.Point




if i create a LineString with the same points I can see it. And I Can See that the created Ring is Closed.

Feb 27, 2012 at 11:37 AM

I am not sure what this could be. Maybe this question could be answered in the SharpMap forum. But first you could try to include the code and step through it to understand what is going on.

Feb 27, 2012 at 1:02 PM

Ok. Thanks for your supplies. If I get an Awnser, i'll post here too.