

Hi all,
So, I'm getting some distorted displays and I'm hoping for some help. As an example , this is how Times Square displays. ( http://imgur.com/CQlIocE) For those who haven't been to my amazing city, these blocks are all rectangles in reality. A casual search has yielded some stuff about projections but it's all been in regard to JOSM. I'm just downloading a JSON file and processing it in Javascript with the JSON parser.
All I'm doing so far is scaling the lon/lat coordinates to the size of the display. I did a test and added the following code and as I expected it does indeed display a right triangle on top of the distorted map. showLine(73.790962, 42.252865,73.791962, 42.253865); showLine(73.790962, 42.252865,73.790962, 42.253865); showLine(73.790962, 42.253865,73.791962, 42.253865);
Is there some extra math I'm supposed to employ to display lon/lat coordinates beyond just scaling them to the dimensions of the display?
Thanks in advance, Matt _______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies


Hi Matthew,
> Is there some extra math I'm supposed to employ to display lon/lat
> coordinates beyond just scaling them to the dimensions of the display?
You do have to account for the earth's curvature.
If I understand correctly, you're scaling each degree of latitude and
longitude to a fixed distance on the page, right? That will compress
coordinates at the extreme edges, but it's still a valid map.
You can also map each linear metre on the ground to a set distance on
the page. This turns gridded cities properly rectilinear, but only works
over short distances. The earth's curvature starts to distort lengths
near the edges.
Here's a short article that gives a quick overview of the OSM tile
projection:
http://alastaira.wordpress.com/2011/01/23/thegooglemapsbingmapssphericalmercatorprojection/cheers,
Stewart
_______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies


In reply to this post by Matthew Aidekman User
Yes, there is some math. You're working with unprojected coordinates, and as noted before, you'll need to project them. The simple explanation is that the world is not flat, and a coordinate system that gives flatness to something notflat is going to look like shit.
The projection used for most online mapping services is the Mercator Projection. The biggest benefit of the Mercator Projection is that direction is preserved (northeast will always point the same way no matter where you are on the map). Because of this, 90degree angles will stay 90degree angles. Try to find the math used to project unprojected coordinates to the Mercator Projection.
On Aug 8, 2013 6:40 PM, "Matthew Aidekman User" < [hidden email]> wrote:
Hi all,
So, I'm getting some distorted displays and I'm hoping for some help. As an example , this is how Times Square displays. ( http://imgur.com/CQlIocE) For those who haven't been to my amazing city, these blocks are all rectangles in reality. A casual search has yielded some stuff about projections but it's all been in regard to JOSM. I'm just downloading a JSON file and processing it in Javascript with the JSON parser.
All I'm doing so far is scaling the lon/lat coordinates to the size of the display. I did a test and added the following code and as I expected it does indeed display a right triangle on top of the distorted map.
showLine(73.790962, 42.252865,73.791962, 42.253865); showLine(73.790962, 42.252865,73.790962, 42.253865);
showLine(73.790962, 42.253865,73.791962, 42.253865);
Is there some extra math I'm supposed to employ to display lon/lat coordinates beyond just scaling them to the dimensions of the display?
Thanks in advance, Matt _______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies
_______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies


Wait the world isn't flat?! When did that happen?!
ok… I'll google this whole "round earth" thing and get back to you. I'm still not sure if I believe you.
Matt
Yes, there is some math. You're working with unprojected coordinates, and as noted before, you'll need to project them. The simple explanation is that the world is not flat, and a coordinate system that gives flatness to something notflat is going to look like shit. The projection used for most online mapping services is the Mercator Projection. The biggest benefit of the Mercator Projection is that direction is preserved (northeast will always point the same way no matter where you are on the map). Because of this, 90degree angles will stay 90degree angles. Try to find the math used to project unprojected coordinates to the Mercator Projection.
On Aug 8, 2013 6:40 PM, "Matthew Aidekman User" < [hidden email]> wrote:
Hi all,
So, I'm getting some distorted displays and I'm hoping for some help. As an example , this is how Times Square displays. ( http://imgur.com/CQlIocE) For those who haven't been to my amazing city, these blocks are all rectangles in reality. A casual search has yielded some stuff about projections but it's all been in regard to JOSM. I'm just downloading a JSON file and processing it in Javascript with the JSON parser.
All I'm doing so far is scaling the lon/lat coordinates to the size of the display. I did a test and added the following code and as I expected it does indeed display a right triangle on top of the distorted map.
showLine(73.790962, 42.252865,73.791962, 42.253865); showLine(73.790962, 42.252865,73.790962, 42.253865);
showLine(73.790962, 42.253865,73.791962, 42.253865);
Is there some extra math I'm supposed to employ to display lon/lat coordinates beyond just scaling them to the dimensions of the display?
Thanks in advance, Matt _______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies
_______________________________________________ newbies mailing list [hidden email] http://lists.openstreetmap.org/listinfo/newbies
_______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies


In reply to this post by Matthew Aidekman User
On Aug 8, 2013, at 6:38 PM, Matthew Aidekman User wrote:
> Hi all,
>
> So, I'm getting some distorted displays and I'm hoping for some help. As an example, this is how Times Square displays. ( http://imgur.com/CQlIocE) For those who haven't been to my amazing city, these blocks are all rectangles in reality. A casual search has yielded some stuff about projections but it's all been in regard to JOSM. I'm just downloading a JSON file and processing it in Javascript with the JSON parser.
>
> All I'm doing so far is scaling the lon/lat coordinates to the size of the display. I did a test and added the following code and as I expected it does indeed display a right triangle on top of the distorted map.
>
> showLine(73.790962, 42.252865,73.791962, 42.253865);
> showLine(73.790962, 42.252865,73.790962, 42.253865);
> showLine(73.790962, 42.253865,73.791962, 42.253865);
>
>
> Is there some extra math I'm supposed to employ to display lon/lat coordinates beyond just scaling them to the dimensions of the display?
As others have pointed out, degrees of latitude are not the same as degrees of longitude. They are closest at the equator and differ increasingly as you move towards the poles.
For the correct way to project latitude, longitude into a local, flat, rectilinear plane, see here:
< http://williams.best.vwh.net/avform.htm#flat>
_______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies


In reply to this post by Matthew Aidekman User
El Vie, 9 de Agosto de 2013, 3:38, Matthew Aidekman User escribió:
> Is there some extra math I'm supposed to employ to display lon/lat
> coordinates beyond just scaling them to the dimensions of the display?
You can do it the quick&dirty way, or the right way.
The quick&dirty way is multiplying every vertical coordinate by the cosine
of the latitude (as measured in whatever point of the viewport's
vicinity). It won't work on large areas, but it's not a lot of math.
The right way is leveraging a projection library, such as proj4
( http://trac.osgeo.org/proj/). Everyone loves proj4: the majority GIS
software out there uses it to do the math underneath. e.g. if you're using
PostGIS to store the data, or Mapnik to render it, you're using proj4 to
do the math.
So you grab your data, you tell the library it's on EPSG:4326 projection,
ask for the data back in EPSG:3857, and bam! everything looks square.
And, as other people have already said, take a crash course on map
projections. I heartily recommend you start your quest at
https://en.wikipedia.org/wiki/Map_projectionCheers,

Iván Sánchez Ortega < [hidden email]>
Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
_______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies


On 130809 01:59 AM, Jim Gibson wrote:
>
> For the correct way to project latitude, longitude into a local, flat, rectilinear plane, see here:
> < http://williams.best.vwh.net/avform.htm#flat>
To add to what Jim said: there is no one correct projection that
maintains distance, angle and/or area beyond a local area. *All* maps
are distorted: you just have to choose the projection that best suits
your purpose.
(Example: I'm originally from the UK. The maps of the British Isles I'm
used to are in the Ordinance Survey grid projection. This makes the main
axis of the biggest island appear upright and ramrod straight, pulling
in Wales as a trim little belly. On almost every other projection, the
British Isles are much more laid back, with Wales looking like it's used
to having a good few pints of an evening.)
cheers,
Stewart
_______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies


Guys I'm so glad I decided to join this community. Lots of other places would not have given such a prompt and verbose response. I'll be working on this tonight and will get back to you with any results or questions.
On Aug 9, 2013, at 7:43 AM, "Stewart C. Russell" < [hidden email]> wrote:
> On 130809 01:59 AM, Jim Gibson wrote:
>>
>> For the correct way to project latitude, longitude into a local, flat, rectilinear plane, see here:
>> < http://williams.best.vwh.net/avform.htm#flat>
>
> To add to what Jim said: there is no one correct projection that
> maintains distance, angle and/or area beyond a local area. *All* maps
> are distorted: you just have to choose the projection that best suits
> your purpose.
>
> (Example: I'm originally from the UK. The maps of the British Isles I'm
> used to are in the Ordinance Survey grid projection. This makes the main
> axis of the biggest island appear upright and ramrod straight, pulling
> in Wales as a trim little belly. On almost every other projection, the
> British Isles are much more laid back, with Wales looking like it's used
> to having a good few pints of an evening.)
>
> cheers,
> Stewart
>
> _______________________________________________
> newbies mailing list
> [hidden email]
> http://lists.openstreetmap.org/listinfo/newbies_______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies


Ivan, I gave your quick and dirty way a shot, (the scope of my project is very small so quick and dirty might work) but I must be doing something wrong. Currently my display is squashed vertically and if I'm interpreting your suggestion correctly, it only has the capability of vertically squashing the image even more. You're suggesting something like this? quickProjection(x y,centerOfDisplayY){ return [x , y*cos(vertCenterOfDisplay/180*pi) ]; } Multiplying anything*cos(anything) will only squash the results. What an I missing?
Thanks for your help, matt I made that with my thumbs! On Aug 9, 2013, at 2:43 AM, "Iván Sánchez Ortega" < [hidden email]> wrote: El Vie, 9 de Agosto de 2013, 3:38, Matthew Aidekman User escribió:
Is there some extra math I'm supposed to employ to display lon/lat coordinates beyond just scaling them to the dimensions of the display?
You can do it the quick&dirty way, or the right way.
The quick&dirty way is multiplying every vertical coordinate by the cosine of the latitude (as measured in whatever point of the viewport's vicinity). It won't work on large areas, but it's not a lot of math.
The right way is leveraging a projection library, such as proj4 (http://trac.osgeo.org/proj/). Everyone loves proj4: the majority GIS software out there uses it to do the math underneath. e.g. if you're using PostGIS to store the data, or Mapnik to render it, you're using proj4 to do the math.
So you grab your data, you tell the library it's on EPSG:4326 projection, ask for the data back in EPSG:3857, and bam! everything looks square.
And, as other people have already said, take a crash course on map projections. I heartily recommend you start your quest at https://en.wikipedia.org/wiki/Map_projection
Cheers,  Iván Sánchez Ortega <[hidden email]>
Un ordenador no es un televisor ni un microondas, es una herramienta compleja.
_______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies


On Aug 9, 2013, at 8:04 PM, Matthew Aidekman User wrote:
> Ivan, I gave your quick and dirty way a shot, (the scope of my project is very small so quick and dirty might work) but I must be doing something wrong. Currently my display is squashed vertically and if I'm interpreting your suggestion correctly, it only has the capability of vertically squashing the image even more.
>
> You're suggesting something like this?
>
> quickProjection(x y,centerOfDisplayY){
> return [x , y*cos(vertCenterOfDisplay/180*pi) ];
> }
>
> Multiplying anything*cos(anything) will only squash the results.
You should multiply the horizontal distance by the cosine of the latitude.
Let's say the center of the map is at (lat0,lon0). Then to find the (x,y) displacement of a nearby (lat,lon) location from the center, calculate the following:
x = R * cos(lat0) * (lon  lon0)
y = R * (lat  lat0)
R is the radius of the earth = 6378km.
This assumes a spherical earth. There are more accurate formulae that take into account the ellipsoidal shape of the earth. However, the above may be good enough for a quickanddirty projection. See < http://williams.best.vwh.net/avform.htm#flat>
_______________________________________________
newbies mailing list
[hidden email]
http://lists.openstreetmap.org/listinfo/newbies

