Loading...
Logo
Processing Forum
I'm trying to recreate a dot density population map by plotting hundreds of thousands of geocoded points from an external csv file (with a strokeWeight( < 1)).  Anti-aliasing is an important part of making such a map to illustrate population density (high density = dark, low density = light).  I'm able to do this fine with the smooth() function, but if I wanted to color code the points by some value (using the stroke() function) Processing ignores smooth().  To show what I'm talking about:



I'm using Processing 1.5.1 on a Windows 7 64-bit machine.  I've also tried using Processing 2.0.1 for 64-bit Windows but I can't reproduce the anti-aliasing effect at all.

My code is below (modified from Brandon Martin-Anderson's original project) :
Copy code


  1. BufferedReader reader;
  2. double ll, bb, rr, tt;

  3. float A = 1000.0;

  4. GlobalMercator proj = new GlobalMercator();  //From an external file

  5. class PersonPoint {
  6.   double x, y;
  7.   String quadnode;

  8.   PersonPoint(String row) {
  9.     String[] fields = split(row, ",");
  10.     this.x = Double.parseDouble(fields[1])/A;
  11.     this.y = Double.parseDouble(fields[2])/A;
  12.     this.quadnode = fields[3];
  13.   }

  14.   void draw(PGraphics pg) {
  15.     pg.point((float)this.x, (float)this.y);
  16.   }
  17. }

  18. ArrayList people;

  19. float pointWeight(int level) {
  20.   switch(level) {
  21.   case 4: 
  22.     return 0.05333;
  23.   case 5: 
  24.     return 0.08;
  25.   case 6: 
  26.     return 0.12;
  27.   case 7: 
  28.     return 0.18;
  29.   case 8: 
  30.     return 0.27;
  31.   case 9: 
  32.     return 0.405;
  33.   case 10: 
  34.     return 0.6075;
  35.   case 11: 
  36.     return 0.91125;
  37.   case 12: 
  38.     return 1.366875;
  39.   case 13: 
  40.     return 2.0503125;
  41.   case 14: 
  42.     return 3.07546875;
  43.   case 15: 
  44.     return 4.61320312;
  45.   case 16:
  46.     return 6.9198046;
  47.   case 17:
  48.     return 10.37970;
  49.   default: 
  50.     return 0.0;
  51.   }
  52. }

  53. void setup(){
  54.   
  55.   size(512, 512, P3D);
  56.   smooth();

  57.   String[] zoomlevels = loadStrings(".../zoomlevel.txt");  //External zoomlevel file (e.g. "4","5"...etc.)

  58.   for ( int i=0; i<zoomlevels.length; i++ ) {

  59.     int level = int(zoomlevels[i]);

  60.     println( "loading..." );
  61.     reader = createReader( "data_file.csv" );
  62.     try {
  63.       String line;

  64.       String quadkey = "";
  65.       PGraphics pg = null;
  66.       PVector tms_tile = null;
  67.       
  68.       int rown = 0;

  69.       while (true) {
  70.         
  71.         line = reader.readLine();
  72.         
  73.         if (line==null || line.length()==0) {
  74.           println( "file done" );
  75.           break;
  76.         }
  77.         
  78.         rown += 1;
  79.         
  80.         if (rown % 100000 == 0) {
  81.           println( rown );
  82.         }

  83.         String[] fields = split(line, ",");
  84.         float px = float(fields[1])/A;
  85.         float py = float(fields[2])/A;
  86.         String newQuadkey = fields[3].substring(0, level);
  87.         String race_type = fields[4].substring(0, 1);

  88.         if ( !newQuadkey.equals( quadkey ) ) {
  89.           
  90.           //finish up the last tile
  91.           if (pg!=null) {
  92.             pg.endDraw();
  93.             PVector gtile = proj.GoogleTile((int)tms_tile.x, (int)tms_tile.y, level);
  94.             println( ".../tiles/"+level+"/"+int(gtile.x)+"/"+int(gtile.y)+".png" );
  95.             pg.save( ".../tiles/"+level+"/"+int(gtile.x)+"/"+int(gtile.y)+".png" );
  96.             println( "done" );
  97.           }

  98.           quadkey = newQuadkey;
  99.           
  100.           PVector google_tile = proj.QuadKeyToTileXY( newQuadkey );
  101.           tms_tile = proj.GoogleTile( (int)google_tile.x, (int)google_tile.y, level );

  102.           println( level+" "+tms_tile.x+" "+tms_tile.y );

  103.           pg = createGraphics(512, 512, P3D);
  104.           pg.beginDraw();
  105.           pg.smooth();

  106.           PVector[] bounds = proj.TileBounds( (int)tms_tile.x, (int)tms_tile.y, level );

  107.           float tile_ll = bounds[0].x/A;
  108.           float tile_bb = bounds[0].y/A;
  109.           float tile_rr = bounds[1].x/A;
  110.           float tile_tt = bounds[1].y/A;

  111.           double xscale = width/(tile_rr-tile_ll);
  112.           double yscale = width/(tile_tt-tile_bb);
  113.           float scale = min((float)xscale, (float)yscale);

  114.           pg.scale(scale, -scale);
  115.           pg.translate(-(float)tile_ll, -(float)tile_tt);

  116.           pg.strokeWeight(pointWeight(level));

  117.           pg.background(255);
  118.                     
  119.         }

  120.         // This is where I create the points            

  121.         if (race_type.equals("w")) {
  122.           pg.stroke(115,178,255);
  123.           pg.point(px, py);
  124.         }
  125.         
  126.         if (race_type.equals("b")) {
  127.           pg.stroke(159,212,0);
  128.           pg.point(px, py);
  129.         }
  130.         
  131.         if (race_type.equals("a")) {
  132.           pg.stroke(255,0,0);
  133.           pg.point(px, py);
  134.         }
  135.         
  136.         if (race_type.equals("h")) {
  137.           pg.stroke(255,170,0);
  138.           pg.point(px, py);
  139.         }
  140.         
  141.         if (race_type.equals("o")) {
  142.           pg.stroke(137,90,68);
  143.           pg.point(px, py);
  144.         }
  145.         
  146.       }

  147.       if (pg!=null) {
  148.         pg.endDraw();
  149.         PVector gtile = proj.GoogleTile((int)tms_tile.x, (int)tms_tile.y, level);
  150.         pg.save( ".../tiles/"+level+"/"+int(gtile.x)+"/"+int(gtile.y)+".png" );
  151.         println( "done" );
  152.       }
  153.     } 
  154.     catch (IOException e) {
  155.       //e.printStackTrace();
  156.     }
  157.   }
  158. }

  159. void draw() {
  160. }



Replies(4)

(Semi-)Random advice: try to remove the P3D parameters. You don't seem to use the 3D anyway (unless I missed something).
That was just a shot in the dark.  I've tried P2D and no specification also, but they didn't work.

Thanks.
Use JAVA2D which is the default anyways!
Both P2D & P3D are based on OPENGL in Processing 2+!
In Processing 1.5.1- however, only OPENGL itself was OpenGL-based!
Thanks GoToLoop.  You folks are awesome!