Philip Magyar
Philip Magyar

Reputation: 29

Map projections distorted

I am trying to build geojson shapes in godot and display them, but when trying to do so with Mercator projection, the lines become distorted and I can't find a solution to this problem. What I think I need is some kind of scaling factor that I am missing and therefor my calculation is bad, if possible it would also be good to sync up the inworld units with meters, but that can be the next step. I have the shape of a building and looking at it in leaflet with a geojson layer it looks like this:

Building shape in leaflet geojson

However, when I am using the Mercator projection from here: https://gis.stackexchange.com/questions/15269/how-to-convert-lat-long-to-meters-using-mercator-projection-in-c like this:

func latlngToMeters(lat, lng):
var sm_a = 6378137.0
lat = deg2rad(lat)
lng = deg2rad(lng)

var x = sm_a * lng
var y = sm_a * log((sin(lat) + 1) / cos(lat))

return Vector2(x, y)

Then display it I get this:

Same building shape in godot

The way I show it is that I get the first point, that is the initalize point, do the projection on it. Then I go tough every single point, the first one becomes (0, 0) then the rest are the offset from the initpoint.

As I wrote before, I think it is some scaling factor I am missing or can it be that I have misunderstood how Mercator works? Any help is appreciated! I have tried to use a c# library (DotSpatial.Projections) but they gave the same error as here.

Upvotes: 0

Views: 57

Answers (0)

Related Questions