Displaced Vector Data with OSM background layer

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Oct 29, 2013 at 9:23 AM
Hi,

I want to use SharpMap to show some geographic data in my application. So first I tried the sample project showing vector data (shape with wgs84) with an osm background layer. It worked fine.

Next step I tried to show a shape file in Gauss-Krueger coordinates. The prj file of the shape contains the following:
PROJCS["DHDN / 3-degree Gauss zone 4",GEOGCS["DHDN",DATUM["D_DHDN",SPHEROID["Bessel_1841",6377397.155,299.1528128254262]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",12],PARAMETER["scale_factor",1],PARAMETER["false_easting",4500000],PARAMETER["false_northing",0],UNIT["Meter",1]]
My Code to fill the map
Dim vecLyr As VectorLayer = New VectorLayer("MyShapeFile")
vecLyr.DataSource = New Providers.ShapeFile(shpFileName, True)
MapBox1.Map.Layers.Add(vecLyr)

MapBox1.Map.BackgroundLayer.Add(New SharpMap.Layers.TileAsyncLayer(New BruTile.Web.OsmTileSource(), "OSM"))

Dim ctFact As ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory = New ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory()
Dim csFact As ProjNet.CoordinateSystems.CoordinateSystemFactory = New ProjNet.CoordinateSystems.CoordinateSystemFactory()
Dim cTrans As GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation
Dim cTransR As GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation

Dim cs As GeoAPI.CoordinateSystems.ICoordinateSystem = vecLyr.CoordinateSystem
If Not cs Is Nothing Then
    ' if a .prj file exists
    cTrans = ctFact.CreateFromCoordinateSystems(cs, GetEPSG900913(csFact))
    cTransR = ctFact.CreateFromCoordinateSystems(GetEPSG900913(csFact), cs)
Else
    ' no .prj file exists - we assume wgs84 data
    cTrans = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, GetEPSG900913(csFact))
    cTransR = ctFact.CreateFromCoordinateSystems(GetEPSG900913(csFact), ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84)
End If

vecLyr.CoordinateTransformation = cTrans
vecLyr.ReverseCoordinateTransformation = cTransR

MapBox1.Map.ZoomToExtents()
MapBox1.Refresh()
Function GetEPSG900913() is taken from Example 4: Adding a Tiled layer as Background.

When the code is done the Map shows my vector data 104 m to the east and 216 m to the north displaced to the tile layer. (similar to thread 31821)

What am I doing wrong? Please help me.
Developer
Oct 29, 2013 at 10:48 AM
Do you have some sample data to make a test?
Oct 29, 2013 at 11:01 AM
Edited Oct 29, 2013 at 12:04 PM
You can find sample data here (PLine.zip)
(link removed)
Developer
Oct 29, 2013 at 11:08 AM
no way to download file using this service, sorry but I don't want to install any code.
try using as example dropbox|google drive|skydrive public folders
Oct 29, 2013 at 12:03 PM
okay, we try this: Link
Developer
Oct 29, 2013 at 12:27 PM
Edited Oct 29, 2013 at 12:28 PM
I've made a small example using GeoServer as WMS server and this is what I see
I suspect the problem is in the data.
Oct 29, 2013 at 12:37 PM
The same data I have loaded in a GIS with a WMS.
See Screen

Theoretically my code is correct?
Developer
Oct 29, 2013 at 1:49 PM
Edited Oct 29, 2013 at 1:49 PM
The code looks fine, maybe the WMS you're using declare a different SRS that proj file?
Coordinator
Oct 30, 2013 at 7:27 AM
You may want to replace the content of the prj file with the "postgis" definition of EPSG:31468
PROJCS["DHDN / 3-degree Gauss-Kruger zone 4",GEOGCS["DHDN",DATUM["Deutsches_Hauptdreiecksnetz",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[598.1,73.7,418.2,0.202,0.045,-2.455,6.7],AUTHORITY["EPSG","6314"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4314"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",12],PARAMETER["scale_factor",1],PARAMETER["false_easting",4500000],PARAMETER["false_northing",0],AUTHORITY["EPSG","31468"],AXIS["X",NORTH],AXIS["Y",EAST]]
Hth FObermaier
Marked as answer by FObermaier on 10/30/2013 at 2:57 AM
Oct 30, 2013 at 9:04 AM
Thank you very much. it works.
Developer
Oct 30, 2013 at 11:39 AM
FObermaier is the man :)