We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Pages: 1 2 
World Map (Read 7859 times)
World Map
Dec 4th, 2009, 1:05am
 

Hi all,

I've used Google to geocode a bunch of locations, and I want to draw points on a map of the world.

I quite like the flat SVG map available at wikipedia, I cannot figure out how to load it correctly, or align my GPS points on it.

Some reading of forums, and other posts here, suggested it's not as simple as it seems.

If anyone has any useful advice, I'm all ears.
Re: World Map
Reply #1 - Dec 4th, 2009, 1:22am
 
Not only an advide... i guess this code is a really good start. Does exactly what you are looking for.

I also uploaded the png for you:

http://www.dec32.de/public/world_longlatwgs84.png
Code:


WorldMap wmap;
Point[] cities;

void setup() {

size(1000, 600);
ellipseMode(CENTER);
smooth();

wmap = new WorldMap();
cities = new Point[] {
wmap.getPoint( 48.45, 2.35), // Paris
wmap.getPoint( -34.60, - 58.38), // Buenos Aires
wmap.getPoint( 17.96, 102.62), // Vientiane
wmap.getPoint( 52.31, 13.25) // Berlin
};

}

void draw() {

wmap.drawBackground();

fill(255, 150, 0);
for (int i = 0; i < cities.length; i++) {
ellipse(cities[i].x, cities[i].y, 14, 14);
}

}

class WorldMap {

int x, y, w, h;
PImage raster;

WorldMap() {
this(0, 0, width, height);
}

WorldMap(int x, int y, int w, int h) {
if (h >= w/2) {
this.w = w;
this.h = w/2;
this.x = x;
this.y = (h - this.h)/2;
} else {
this.h = h;
this.w = 2*h;
this.x = (w - this.w)/2;
this.y = y;
}
raster = loadImage("world_longlatwgs84.png");
}

void drawBackground() {
image(raster, x, y, w, h);
}

Point getPoint(float phi, float lambda) {
return new Point(
x + ((180+lambda)/360)*w,
y + h - ((90+phi)/180)*h
);
}

}

class Point extends Point2D {
Point(float x, float y) { super(x, y); }
}

class Point2D {
float x, y;
Point2D(float x, float y) {
this.x = x; this.y = y;
}
}
Re: World Map
Reply #2 - Dec 4th, 2009, 4:11am
 
I know that code! Smiley

http://processing.org/discourse/yabb2/num_1210365949.html#4
Re: World Map
Reply #3 - Dec 4th, 2009, 6:09am
 
ah it was yours. i already posted this code in another threat http://processing.org/discourse/yabb2/num_1218822969.html
a year ago and mentioned that i forgot who made it and that i am sorry for not mentioning the author.

so thanks for this great piece of code Smiley
Re: World Map
Reply #4 - Dec 4th, 2009, 7:06am
 
I'm glad to see people using it!

It should be improved, though. The Point and Point2D thing are no longer needed and could be replaced by the built-in PVector class, among other things.

@matholio:
if you have the WGS84 lat/long decimal (GPS) coordinates, then just use the code above to map your points, it should work.
Re: World Map
Reply #5 - Dec 5th, 2009, 2:58am
 
Thank you all, I've had a few interesting hours, both with the posted code and various wikipedia tangents.  Smiley

I'd like to be able to change the colors of the map, or generate a different size, where does the WGS84 map come from?

If I wanted to use SVG, where might I obtain a wsg84 SVG?

Regards
Re: World Map
Reply #6 - Dec 5th, 2009, 3:53am
 
It's a PNG export of an SVG map from wikimedia. See the source here :
http://commons.wikimedia.org/wiki/File:BlankMap-FlatWorld6.svg
Re: World Map
Reply #7 - Dec 6th, 2009, 8:02pm
 

I rather hoped the maps on wikimedia would work, but when I substitute world_longlatwgs84.png for one from wikimedia, the point i plot no longer apear in the right places.

So the map on wikimedia is different from wgs84, I think it's a Robinson Projection.

Have I got that right?
Re: World Map
Reply #8 - Dec 7th, 2009, 4:11am
 
Sure it's a projection problem. There are many projections available and the one I used for the sketch is a flat one known as Plate Carrée. As says the description on Wikimedia, it's the easiest to work with :

Quote:
The flattened projection shown here is convenient for identifying specific locations on the map, because all lines of latitude and longitude are all evenly spaced and parallel.
Re: World Map
Reply #9 - Dec 7th, 2009, 5:25am
 
Maybe you wanna check out this new posting by Till Nagel...

http://btk.tillnagel.com/tutorials/geo-tagging-placemaker.html
Re: World Map
Reply #10 - Dec 7th, 2009, 5:59am
 
Nice post indeed!

He is using an equirectangular projection too (which is a different name for plate carrée).

Actually, that shouldn't be too hard to implement other projection types (just need to find the appropriate formula).
Re: World Map
Reply #11 - Jan 22nd, 2010, 12:47pm
 
I have an Ellipsoid that I'm using for the earth (with the texture mapped).  I have my data for long/lat.  How do I convert long/lat into an XYZ for points on the Ellipsoid?
Re: World Map
Reply #12 - Jan 22nd, 2010, 1:49pm
 
Perhaps the Vincenty's formulae might help you
Re: World Map
Reply #13 - Jan 22nd, 2010, 2:06pm
 
Yikes.. that math is beyond me.  How do I do that in Processing?

I have the X and the Y and I have my sphere lined up ok.  My Z is always 90 (radius). The X and Y positions have to be adjusted due to the curvature of the earth.  For example, Paris is too low. The x,y on a flat surface becomes too low when the image is curves toward the pole.  I'm not sure how factor the XY for the curvature.
Re: World Map
Reply #14 - Jan 23rd, 2010, 6:00am
 
Assuming that the centre of the Ellipsoid is (0,0,0), the Y axis goes thorough the north (-ve Y) and south (+ve Y) poles and therefore the X and Z axises go through the equator. (i.e. to match the coordinate system used by Processing)

Then if:
(1) radX, radY and radZ are the ellipsoid radii (on the Earth radX = radZ but radY is slightly smaller)
(2) angNS is the angle from the north pole (0-PI)
(3) angEW is the angle round the equator (0-2PI)

then the coordinates for a point on the sphere for given angles angNS & andEW are

Code:

x = radX * sin(angNS)  * cos(angEW)
y = - radY * cos(angNS;
z = radZ * sin(angNS) * sin(angEW)


You would have to map the latitude and longitude values to angNS and angEW but that should be straightforward. Matching a real - world position e.g. Paris also depends on the accuracy of the  image used to texture the ellipsoid.
Smiley
Pages: 1 2