ThinkGeo.com    |     Documentation    |     Premium Support

Change the projection of a google map

Hi Ben,


I like to render a google map (or google areal) as background of a shape Layer.


The projection of the shapeLayer (my projection example is Germany DHDN3, epsg 31467) should also be applied to the google map.


Can you please send me an example (Visual Basic) for that. I also want to use Postgres layer as overlay. Is this possible?


Thank you very much


With best regards J


Jörg


 


Ps. Unfortunaly the following source code (containing some german highway) which I get from the examples works not correct. It produces an south shift of the shapes against the google data of about 10 km. 


If Not Page.IsPostBack Then Map1.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.FromHtml("#B3C6D4")) Map1.MapUnit = GeographyUnit.Meter Map1.MapTools.OverlaySwitcher.Enabled = True Map1.MapTools.MouseCoordinate.Enabled = True Dim google As New GoogleOverlay("Google Map") google.JavaScriptLibraryUri = New Uri(ConfigurationManager.AppSettings("GoogleUri")) google.GoogleMapType = GoogleMapType.Normal Dim shapeFileFeatureLayer As New ShapeFileFeatureLayer(MapPath("~/SampleData/Joerg/autobahn2.shp")) shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 2, True) shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20 Dim proj4 As New Proj4Projection() proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(31467) proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString() shapeFileFeatureLayer.FeatureSource.Projection = proj4 Dim shapeOverlay As New LayerOverlay("Shape Overlay", False, TileType.SingleTile) shapeOverlay.Layers.Add(shapeFileFeatureLayer) shapeOverlay.TransitionEffect = TransitionEffect.None shapeFileFeatureLayer.Open() Map1.CurrentExtent = shapeFileFeatureLayer.FeatureSource.GetBoundingBox() shapeFileFeatureLayer.Close() Map1.CustomOverlays.Add(google) Map1.CustomOverlays.Add(shapeOverlay) End If



I can't attach my example zip file, because the file type would be wrong. So I have send it to the adress support@thinkgeo.com.


Regards Jörg



Joerg,  
  
 I got your data and recreated the issue. I’m not sure why your data doesn’t match with Google, is there any chance the epsg number is wrong or that data is in fact not under 31467? We used an OpenSource component “Proj4” as our projection engine and hard to say, maybe it has some bugs.  
  
 Do you have some way to test the projection? For example, convert the data (or just convert a point) to Decimal Degree (4326), if it matches some given “correct” data, we can make sure it is in 31467. I think that’s the place with most possibilities to lead to this problem.  
  
 You already have a good sample codes in VB, here is the one with the PostGreFeatureLayer, you can see I only changed a couple lines. 
 
        If Not Page.IsPostBack Then
            Map1.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"))
            Map1.MapUnit = GeographyUnit.Meter

            Map1.MapTools.OverlaySwitcher.Enabled = True
            Map1.MapTools.MouseCoordinate.Enabled = True

            Dim google As New GoogleOverlay(“Google Map”)
            google.JavaScriptLibraryUri = New Uri(ConfigurationManager.AppSettings(“GoogleUri”))
            google.GoogleMapType = GoogleMapType.Normal

            Dim postgreFeatureLayer As New PostgreSqlFeatureLayer(“connectionString”, “tableName”, “featureIdColumn”)
            postgreFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 2, True)
            postgreFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

            Dim proj4 As New Proj4Projection()
            proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(31467)
            proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()
            postgreFeatureLayer.FeatureSource.Projection = proj4

            Dim layerOverlay As New LayerOverlay(“Shape Overlay”, False, TileType.SingleTile)
            layerOverlay.Layers.Add(postgreFeatureLayer)
            layerOverlay.TransitionEffect = TransitionEffect.None
            postgreFeatureLayer.Open()
            Map1.CurrentExtent = postgreFeatureLayer.FeatureSource.GetBoundingBox()
            postgreFeatureLayer.Close()
            Map1.CustomOverlays.Add(google)
            Map1.CustomOverlays.Add(layerOverlay)
        End If
 
  
 Thanks, 
  
 Ben

Hi Ben,


I have examined the coodinates of my highway example and found the same coodinates for the highwaycross like in Goggle earth. For example the upper right highway cross of the big highway triangle near by the city Ulm has the


WGS84-coordinates 10 07 11 Lat / 46 27 50 Lon.


The same location has in the german DHDN GK3-system following coodinates (seen also in my data example)


--> right 3582600 m/ upper 5370300 m.


You can examine the german coodinates with the viewer of the survey agency


deutschlandviewer.bayern.de/...iewer.html


So I guess something must be wrong with the proj4 Google overlay.


If I try the EPSG projection 3395 (WGS84. World Mercator) as external projection to my data I get also the same result like with "get google projection. The vector layer is located 10 km south to the google map


 


Is it possible to project Google data into the coodinate system of my vector layer?


Regards


Jörg



Joerg, 
  
 it’s impossible to project Google data following with your vector data. We can only get tiling images from GoogleMap and cannot do any projection based on that. 
  
 I tried to project the Point (3582600, 5370300) from projection 31467 to Decimal Degree(4326), and the result(10.1159, 48.4650) are not the same as the correct one you provide (10 07 11, 46 27 50). So we can almost say your data is in another projection other than 31467. if we can figure that out, I think proj4 can also handle your projection well. 
  
 Here is my code doing the projection. 
 
     Dim proj4 As New Proj4Projection(31467, 4326)
     proj4.Open()
     Dim a As PointShape = DirectCast(proj4.ConvertToExternalProjection(New PointShape(3582600, 5370300)), PointShape)
 
 So is there any other way you can get the Srid of that data? 
  
 Ben

Hi Ben,


you have given me the coordinates in decimal degrees.They are correct. 


I gave you the coodinates in degree/ minutes/seconds and I'm sorry with a mistake in the latitude (46<-> 48)


The right location ist 10  07 11, 427 50 and this is also correct. So both coodinates pairs, yours and my, are correct and describe the same location.


Also my coordinates, DHDN GK3, epsg 31467 (right 3582600, upper 5370300) describe the same location.


You can examine the german coodinates with the viewer of the survey agency. Look to the city Ulm and you will see the highway cross at the upper right of the city. I send it via email.


deutschlandviewer.bayern.de/...iewer.html


I guess that their must be something wrong with the north shift of the geodaetic datum in epsg 31467. As GoogleEarth shows the right location in degrees.


Regards Jörg



Hi Ben,  
 the task of this question " Is it possible to project a google map to another projection is solved with your last answer. You wrote  that it is not possible. But my projection problem with the overlay of my vektor layer is still open. So I open  a new question containing this question. Would you have a look to it? 
 Regards Jörg

Joerg, 
  
 Sorry for the delay. I didn’t forget this question, but cannot provide you a good answer now. Here is what I found for this problem 
 1, I changed the previous result (16.1159, 48.4650) to degree minute second and I get (16 06 57, 48 27 54), which is not exactly the same as the one you provided (10 07 11, 48 27 50). Maybe it’s in an acceptable tolerance but as far as I know for most cases, this tolerance is too big, maybe something is wrong here. So could you let me know how you get the connection between (10 07 11, 48 27 50) and (3582600, 5370300), are you using some 3rd part transformation tool? Can you let me know what is it? 
 2, you also sent me the .prj file, these days I’m waiting for our projection guru who might be able to get the Epsg number from that file as I still doubted if the 31467 is the right number for your data. I still have confidence for the proj4 as many customers are using it and few of them have comments about its result. Sure it is possible its bug leads to your problem but I just want to double check before I make sure :) 
 I would not reply the other post to make sure it keeps open to me. I will let you know there if I have any new results. 
  
 Thanks, 
  
 Ben 
  
  


Hi Ben,


I thought we should discuss about the problem in my new request. But your location coodinates in decimal degrees are correct (16.1159, 48.4650) within the tolerance  (but you make a number confusion: 16 deg must be 10 deg) .


With the mapsuite proj4 function I get a much bigger south shift of 10 km. So a deeper analysys by your projection guru makes sense.


I get my location coodinates in degrees from the website I gave to you and from a mapping tool of the surveying administration.


Regards Jörg






 


Joerg,


I make it right finally and the reason is very simple, your SRID number 31467 is under an Esri standard instead of the common Epsg one. So just change your code from



projection.InternalProjectionParametersString = projection.GetEpsgParameters(31467);

To



projection.InternalProjectionParametersString = projection.GetEsriParameters(31467);

It will be fine.



 


I was informed that there are couples of Epsg standards, just an Srid number doesn't make sense if we don't know which standard it is following. Both of the above 2 standards includes 31467 and unfortunately we picked up the wrong one at the very beginning.


For the same reason, you can also see other methods in projection like


Projection.GetGl27Parameters


Projection.GetNad83Parameters


…...


If you are interested on this, please have a look at the documentation in “C:\Program Files\ThinkGeo\Map Suite Web Evaluation Edition 3.0\Documentation\Projections” where you can find all the Srid definition under different standards. You can also find the tiny difference for Srid 31467 between EPSG and the ESRI one.


Thanks,


Ben