Layer misalignment

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Dec 13, 2015 at 2:01 AM
Hello,

I got some trouble aligning two layers, got one tilelayer and a shapefile backed layer.
The tilelayer's tiles are created using 'gdal2tiles' on NASA BlueMarble image.

The shapefile:
http://www.arcgis.com/home/item.html?id=3c4741e22e2e4af2bd4050511b9fc6ad
The base image for tiles:
http://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74393/world.topo.200407.3x21600x10800.jpg
The command I used in gdal2tiles:
gdal2tiles -p geodetic -s EPSG:4326 -z 0-4 world.topo.200407.3x21600x10800.jpg
(I renamed the resulting folder to 'world.topo.200407')

Now my problem is that both layers are misaligned: LINK
Image

My sourcecode: (I added four points as reference)
Dim vlay As New SharpMap.Layers.VectorLayer("Test")
vlay.DataSource = New SharpMap.Data.Providers.ShapeFile("SHF\continent.shp", True)
vlay.Style.Fill = Brushes.Transparent
vlay.Style.Outline = Pens.Yellow
vlay.Style.EnableOutline = True

Dim schema As New TileSchema
schema.Resolutions.Clear()
schema.Resolutions.Add(New Resolution() With {.Id = "0", .UnitsPerPixel = 0.703125})
schema.Resolutions.Add(New Resolution() With {.Id = "1", .UnitsPerPixel = 0.3515625})
schema.Resolutions.Add(New Resolution() With {.Id = "2", .UnitsPerPixel = 0.17578125})
schema.Resolutions.Add(New Resolution() With {.Id = "3", .UnitsPerPixel = 0.087890625})
schema.Resolutions.Add(New Resolution() With {.Id = "4", .UnitsPerPixel = 0.0439453125})
schema.Srs = "EPSG:4326"
schema.Extent = New Extent(-180, -90, 180, 90)
schema.Height = 256
schema.Width = 256
schema.Format = "png"
schema.OriginX = -180
schema.OriginY = -90

Dim ts As New TileSource(New FileTileProvider(New FileCache("world.topo.bathy.200407", "png")), schema)
Dim tl As New TileLayer(ts, "BM")

Dim geos As New List(Of IGeometry)
Dim gf As New GeometryFactory()
geos.Add(gf.CreatePoint(New Coordinate(-160, -70)))
geos.Add(gf.CreatePoint(New Coordinate(160, 70)))
geos.Add(gf.CreatePoint(New Coordinate(-160, 70)))
geos.Add(gf.CreatePoint(New Coordinate(160, -70)))

Dim gemlay As New VectorLayer("GL")
gemlay.DataSource = New Providers.GeometryProvider(geos)

MB1.Map.Layers.Add(tl)
MB1.Map.Layers.Add(vlay)
MB1.Map.Layers.Add(gemlay)

MB1.Map.ZoomToExtents()
MB1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan
MB1.Refresh()
Any Ideas?

Greetings, Xeoniz
Coordinator
Dec 15, 2015 at 7:02 AM
I followed the steps you are outlining and took a look at the output of gdal2tiles.
To me it seems that your extent is not correct. shouldn't it be schema.Extent = new Extent(-180, -90, 270, 180);

Where do the values for UnitsPerPixesl come from?