0

I'm trying to implement a function, which takes a pair of longitude and latitude values and calculates a position on a map. It's a map of Germany as an svg svg. So when I google the longitude and latitude values of Berlin, I want it to show me the position of Berlin on the map.

So I'm having the coordinate-system of the map, it's origin beeing in the top-left corner. Than I'm having the longitude and latitude coordinate system (see image1) which, has its origin to the bottom-left.

My Idea was as follows: Flip all latitude values, so that the ll-coordinate-system is flipped on the x-axis. Then subtract the longitude and (negative) latitude from the origin of my map, to align both coordinate systems. Then calculate a transformation Matrix by knowing the longitude and latitude coordinates of to points on my map and solving the linear equation system. My problem: The Matrix calculates coordinates on the map, which are off by 24 or so. So it seems to work somehow, but it's not that precise. It seems there are some errors on the way or my measurements were off. It was really tricky to measure the anchor points. Is there an easier way to do the calculation?

A visualisation of my idea to align the coordinate-systems: sample

जलजनक
  • 3,072
  • 2
  • 24
  • 30
Ecko
  • 5
  • 2
  • "off by 24" doesn't tell us much. In any case, which projection has your map? Put a map with longitude and latitude lines, and probably you will see they are not parallel. I just just use proj4 to convert lat/long into x,y. (and get the x,y of the 2 diagonal edges). Then simple map (no flipping) is used. But you need to find the projection of the image (one which put into x,y coordinates). – Giacomo Catenazzi Apr 04 '22 at 08:19
  • Thanks for the Answer. Since the svg map aligns pretty well with google maps, I assume It's using the same projection. They use a variant of the Mercator Projection (see https://setcompass.com/GoogleMapsProjection.htm). I'm not sure how to proceed. Let's assume I want to find the Position of Berlin on my Map. I google the long/lat coords, then transform them with the projection matrix of google maps? Sorry, I'm fairly new to that subject. – Ecko Apr 05 '22 at 12:23
  • If it is a Mercator (Google use "Web Mercator" the grid should already be Cartesian), so may theory is wrong. But in such case, you can check a possible duplicate: https://stackoverflow.com/questions/2103924/mercator-longitude-and-latitude-calculations-to-x-and-y-on-a-cropped-map-of-the – Giacomo Catenazzi Apr 05 '22 at 13:02

0 Answers0