I cannot help you, let alone send pseudocode, as long as you do not understand 
the principle: you need to know which projection you used in making (or was 
used by the software or the maker of) your PNG map. Only then you can calculate 
from lat-lon to x-y and from there to image pixel coordinates....

--
Barend Köbben

On 19/08/2025, 13:07, "Luca Bertoncello" <lucab...@lucabert.de> wrote:

Am 19.08.2025 10:29, schrieb Kobben, Barend (UT-ITC):
> You can’t unless you know which X & Y you want/mean. It is NOT
> correct to say that y is latitude and x is longitude!! XY means you
> use a cartesian coordinate system (the map = flat rectangle) instead
> of lat & lon which are angles from the center of a spheroid or
> ellipsoid (the globe = a 3D object).
>
> We call the transformation from 3D globe to flat map a projection.
> There are endless ways of projecting. Choose one of those projections
> and do the math and then you go from lat-lons to y-es and x-es...

Can you suggest me a way?

> For a nice overview of all this see e.g.
> https://kartoweb.itc.nl/geometrics

I think, I don't have the needed mathematical knowledge to understand
that... :(

I try to explain again what I need...
I created an image, putting more tiles together. This is a PNG.
Then I try to add some markers (airports) at known coordinates. And I
need to convert this coordinates in X,Y related to my image.
I searched many procedures in Internet, but they always position the
markers at the wrong place.
I tried now a very simple procedure that assumes Earth is flat, but it
does not work correctly, too...

This is my code (PHP):

function latlngToScreenXY($lat, $lng, $minLat, $minLng, $maxLat,
$maxLng, $mapWidth, $mapHeight)
{
   $lngDelta = $maxLng - $minLng;
   $relLng = $lng - $minLng;
   $percLng = $relLng / $lngDelta;
   $x = $mapWidth * $percLng;

   $latDelta = $maxLat - $minLat;
   $relLat = $lat - $minLat;
   $percLat = $relLat / $latDelta;
   $y = $mapWidth * $percLat;

   return array('X' => $x, 'Y' => $mapHeight - $y);
}

You can see the result as attachment.
In the Map I drawed two circles: the first one at the south-west corner
of the map. This is correct.
The second one should be in the middle of the map ( ($maxLat - $minLat)
/ 2 + $minLat, ($maxLng - $minLng) / 2 + $minLng ), and you see, this is
NOT correct.
Finally I tried to add the markers for the airports of Kamenz and
Bautzen. And they are on the wrong position (both are souther than the
correct position, Kamenz is wester and Bautzen is easter, too).

Can you please send me at least a pseudocode to understand you to
convert LatLng to Y,X of an image?

Thanks
Luca Bertoncello
(lucab...@lucabert.de)

Reply via email to