Mapping cities of the world
in
Core Library Questions
•
2 years ago
Hello all,
I am working with processing to make a tool that maps populated places by gps coordinates. My data comes from the National Geospacial Intelligence Agency. Using code borrowed from other sources as well as suggestions from members of this forum (phi.lho and jeff_g), I have reached a point where I feel the sketch works pretty well. However...
I can see two major problems with the sketch so far. First, the large amount of data takes a long time to load. Second, the amount of points required to display all the populated places of the earth would exceed a few million points (difficult to do while maintaining a good frame rate).
At this point I am looking for any advice on anything from optimizing the code, to conceptually making the program better.
Thank you all for your continuing help with processing, as well as being patient with my lack of understanding.
-Ben
Here a link to a few xml files I have used to test the sketch
And here is the code (please play around with it)
- import processing.opengl.*;
- import javax.media.opengl.*;
- import javax.media.opengl.glu.*;
- import peasy.*;
- PeasyCam cam;
- PGraphicsOpenGL pgl;
- GL gl;
- GLU glu;
- XMLElement xml;
- int index;
- int glList;
- float[] LAT = new float[1];
- float[] LONG = new float[1];
- float[] coords_x = new float[1];
- float[] coords_y = new float[1];
- float[] coords_z = new float[1];
- float[] colorR = new float[1];
- int r = 3000;
- void setup() {
- size(1000, 600, OPENGL);
- glu = new GLU();
- gl=((PGraphicsOpenGL)g).gl;
- glu=((PGraphicsOpenGL)g).glu;
- pgl = (PGraphicsOpenGL) g;
- gl = pgl.gl;
- xml = new XMLElement(this, "sAmer.xml");
- int index = xml.getChildCount();
- println(index);
- coords_x = expand (coords_x,index);
- coords_y = expand (coords_y,index);
- coords_z = expand (coords_z,index);
- //colorR = expand (colorR,index);
- LAT = expand (LAT,index);
- LONG = expand (LONG,index);
- glList = gl.glGenLists(1);
- gl.glNewList(glList,GL.GL_COMPILE);
- gl.glBegin(gl.GL_POINTS);
- for (int i=0; i < index; i+=1) {
- XMLElement kid = xml.getChild(i);
- //String cityName = kid.getStringAttribute("name");
- LAT[i] = kid.getFloatAttribute("LAT");
- LONG[i] = kid.getFloatAttribute("LONG");
- //colorR[i] = norm(i,0,index);
- coords_x[i] = -r * cos(LAT[i]*PI/180) * cos(LONG[i]*PI/180);
- coords_y[i] = r * cos(LAT[i]*PI/180) * sin(LONG[i]*PI/180);
- coords_z[i] = r * sin(LAT[i]*PI/180);
- gl.glColor4f(1,1,1,.25);
- gl.glVertex3f(coords_x[i], coords_y[i], coords_z[i]);
- }
- gl.glEnd();
- gl.glEndList();
- cam = new PeasyCam(this, 0, 0, 0, (r*2.5));
- cameraSetup();
- }
- void draw () {
- frame.setTitle(str((frameRate))+"fps");
- background(50);
- pgl.beginGL();
- gl.glTranslatef(width/2, height/2, (r*2.5));
- draw_earth();
- draw_points();
- pgl.endGL();
- }
- // draw the earth as a sphere
- void draw_earth() {
- GLUquadric qobj0 = glu.gluNewQuadric();
- gl.glColor4f(.1, .1, .1, 1);
- glu.gluSphere(qobj0, (r-25), 64, 64);
- }
- // plot x y z points on the screen
- void draw_points() {
- gl.glPointSize(1.2);
- gl.glCallList(glList);
- }
- void cameraSetup() {
- cam.setWheelScale(5);
- cam.setResetOnDoubleClick(false);
- cam.lookAt(width/2, height/2, (r*2.5));
- cam.setMinimumDistance((r+75));
- cam.setMaximumDistance((r*2.5));
- cam.rotateX(3*(PI/2));
- cam.rotateY(3*(PI/2));
- float fov = PI/3;
- float cameraZ = (height/2.0) / tan(fov/2.0);
- perspective(fov, float(width)/float(height),cameraZ/200.0, cameraZ*100.0);
- }
1