How to fix distortions in rendered OpenStreetMap maps?

I use OpenStreetMap in order to generate maps and add some cool stuff in it. Actually I have good results but I seem to have a problem with reporting a good image ratio when I create my generated file.

I put OpenStreetMap data in a PostgreSQL and I use PostGis to work with it in the EPSG:4326 projection. Everything is fine except this ratio problem.

Actually I've tried almost every things (except the good one indeed)... that's why I'm looking for your help. I think I forgot something.

In my program I use the min lon & min lat (as origin of the selection) ans max lon & max lat (as selection max coordinates)... basically I though a correct ratio would have been given by something like that (using N as size factor):

``````N = 10000
x_size = maxlon - minlon
y_size = maxlat - minlat
file_width = x_size * N
file_height = y_size * N
``````

The most intriguing part is that this computation works for some parts of the world. In my examples below, the three cities use this ratio computation, but even if Montreal and Lyon don't work, Stockholm seems to work pretty well... The two others seem stretched.

I think it's a noob problem... something silly enough to be barly invisible after hours of work on it. So I think you will find my problem easily.

Thank you.

-

Degrees of longitude get smaller as you move away from the equator, eventually going to 0 at the poles; degrees of latitude don't suffer the same fate (looking at the latitude and longitude lines on a globe will make this clearer).

Projecting your data to a coordinate system should solve the problem, because feet and meters don't change in size as you move north and south.

-
so what you say is it's only luck if my map of Stockholm looks right? :) Thank you for your answer, but I don't understand the second part of it :( do you know where I can find some examples on the Internet? Thank you very much. –  Rootosaurus Aug 25 '11 at 7:42
I think you talk about 900913... am I right? –  Rootosaurus Aug 25 '11 at 13:21
900913 = Google projection (look at the resemblance in number and name) –  Mapperz Aug 25 '11 at 13:36
@Mapperz Yeah, yeah... but it seems that 900913 uses a coordinate system based on meters... no? –  Rootosaurus Aug 25 '11 at 15:18
@mattwigway thank you very much it works perfectly using 900913 projection. –  Rootosaurus Aug 25 '11 at 19:16