0

Given:

  • an image of a map section that I cut from GOOGLE MAPS

  • coordinates of the 4 corners of the image (lat/long).

    • leftTopLat = 47.536
    • leftTopLon = 21.5203
    • rightTopLat = 47.554
    • rightTopLon = 21.5495
    • leftBottomLat = 47.528437
    • leftBottomLon = 21.530410
    • rightBottomLat = 47.546455
    • rightBottomLon = 21.559721
  • coordinates of a point to be displayed (targetLat/targetLon)

    • targetLat = 47.541223
    • targetLon = 21.53998275

The problem is that the map section is not parallel to the equator, it is rotated by 42 degrees, so the warmed-up code no longer works properly.

   double leftTopLat = 47.535974;
   double leftTopLon = 21.520250;
   double rightTopLat = 47.553975;
   double rightTopLon = 21.549528;
   double leftBottomLat = 47.528437;
   double leftBottomLon = 21.530410;
   double rightBottomLat = 47.546455;
   double rightBottomLon = 21.559721;
   
   // center point
   double targetLat = 47.54121025;
   double targetLon = 21.53997725;

   double mapWidth = 2518; // px
   double mapHeight = 1060; // px
        
   double xPercent = (targetLon - leftTopLon) / (rightTopLon - leftTopLon);
   double yPercent = (targetLat - leftTopLat) / (leftBottomLat - leftTopLat);

   System.out.println(xPercent); // 0.6738784246575766 but it should be around 0.5
   System.out.println(yPercent); // -0.6889131297096822  but it should be around 0.5 or -0.5  

   float xOnScreen = (float) (xPercent * mapWidth);
   float yOnScreen = (float) (yPercent * mapHeight) * (-1);
   System.out.println(xOnScreen + " " + yOnScreen); 

How can I solve it so that it works correctly?

4
  • You can correct the height and width in pixel, taking into account the rotation. Then your formula work again. Do some sketches and you will understand better Commented May 8, 2024 at 8:44
  • We are not only talking about Cartesian plane coordinates, other things must also be taken into account. The "rectangle" is not parallel to any axis. Commented May 16, 2024 at 8:22
  • Why not using Cartesian coordinates? UTM uses it for regions of 15 degrees with good approximations (your coordinates are not near pole). You can work with ellipsoids, but you risk to have as much errors because numerical imprecision (and not using the correct numerical methods not to lose precisions). And also ellipsoid is not precise (there are also new versions but usual recommendation is not to use them but for specific applications. And also ellipsoid is not a geoid, and we have no good model of it (and it depends if you are sending laser beams, or constructing a canal). Commented May 16, 2024 at 9:12
  • Just try with online tools (which should use precise ellipsoids, etc.) and a sketch with Cartesian, and check if the error is acceptable For most users the error is hidden by truncating distances/coordinates. Commented May 16, 2024 at 9:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.