Archive for October, 2006

Stefan Kühn, a cartographer at the University Trier, Germany, has extracted all the geo coordinates embedded in articles on Wikipedia. The WikiProject Geographical coordinates is a Wikipedia project for ensuring standardized geocoding of locations in its articles.

Google Earth fans bent on instant gratification can simply download a KMZ file and start surfing. But more importantly, coders and infoviz geeks can get a comma-separated text file (CSV) with coordinates, titles and Wikipedia categories for all points.

Link: Geocoordinates from Wikipedia for Google Earth

1 Comment »

PHP function that returns file size of a given file as a string indicating size in kilobytes or megabytes, depending on whether the file is bigger than one megabyte.

function filesizeFormatted($filename) {
  $val=filesize($filename)/1024;

  if($val>1024) return "".number_format($val/1024,1,"."," ")." MB";
  else return "".number_format($val,1,"."," ")." kb";
}

1 Comment »

Creating PDFs in Processing and post-processing them in Adobe Illustrator, I frequently find myself wanting to do things like adjust global transparency levels, colors etc. So far that’s been frustrated by the rather poor color adjustment options built into Illustrator, but today I finally got impatient enough to look into a scripting solution.

Illustrator has had Javascript support since CS 1, exposing the document object model to anyone with a bit of scripting savvy. Adobe is good about publishing technical documents, perhaps a holdover from the days when they relied on PostScript to build their empire. So anyone can go to the online scripting documentation and download a complete PDF with a description of the Illustrator API.

As might be expected, coding Javascript is not without its troubles, and I found myself having dotcom flashbacks to the days when I would do client-side scripting. In particular, debugging is always been a pain with Javascript, especially when one is not intimate with the DOM and API. Fortunately, the ExtendScript Toolkit provided by Adobe functions both as a IDE and a debugger. Still, I find myself wanting a few nice details, like the possibility of displaying a progress bar when a script is executing.

To give you an idea of the oddities of coding for Illustrator, I am posting a script that allows the user to input a multiplier, which is then used to adjust the opacity of all path items in the active document. This covers for the lack of such a function in Illustrator proper. To be honest I was surprised at the speed with which I was able to accomplish my goal. I would seriously consider this as a way to do brute-force post-processing of vector files.

That said, I doubt it will ever be as fun and quirky as Scriptographer

Source code - OpacityAdj.js

Read the rest of this entry »

No Comments »

I know I mentioned putting together a image tiling Processing library, but so far I haven’t had time. To start at the wrong end, here’s the image stitching code for putting together the tiles once they’ve been generated. Hopefully that will be of use to some people.

Note that you might run into memory problems if you use huge tiles. Processing 0119 has a new “Set maximum memory” preference that easily takes care of this problem (see File > Preferences).

See the Processing forums for some sample code creating tiles, posted by user “surelyyoujest”.

Update: I’ve put together a proper class for this tiling technique. Have a look at aTileSaver.pde.

Source code - ImageStitcher.pde

Read the rest of this entry »

1 Comment »

This is a simple variant to the built-in saveStrings() method in Processing. It allows you to write strings to a GZIP compressed file instead of a plain text file. Very useful when writing text-based data files that add up to a few megabytes.

Source code - saveStringsGZIP.pde
// saveStringsGZIP.pde
// Marius Watz - http://workshop.evolutionzone.com
//
// Code for saving an array of strings to a GZIP compressed file.
// Based on Processing's built-in saveStrings() method.

// Java classes needed for file I/O.
import java.io.*;
import java.util.zip.GZIPOutputStream;

void setup() {
  String [] s=new String[2000];
  for(int i=0; i< s.length; i++) s[i]=nf(i,50);
  saveStringsGZIP("test.txt",s);
}

// Based on code from processing.core.PApplet, by the Processing team.
public void saveStringsGZIP(String filename, String strings[]) {
  try {
    String location = savePath(filename+".gz");
    GZIPOutputStream fos =
      new GZIPOutputStream(new FileOutputStream(location));
    PrintWriter writer =
      new PrintWriter(new OutputStreamWriter(fos));
    for (int i = 0; i < strings.length; i++)
      if(strings[i]!=null) writer.println(strings[i]);
    writer.flush();
    fos.close();
  } catch (IOException e) {
    e.printStackTrace();
    throw new RuntimeException("saveStringsGZIP() failed: "
      + e.getMessage());
  }
}

No Comments »

  • GeoPress is a WordPress plugin that allows easy embedding of geotags and maps in blog posts. Read more about it on O'Reilly Radar
  • MySQLicious mirrors del.icio.us bookmarks into a MySQL database. Set it up as a cron job and you will have an always-updated, on-site database.
  • Processing 0117 is out, rapidly replacing 0116, which Ben posted only yesterday.
  • New Processing libraries have been posted on the official overview, including one for genetic algorithms.
  • If you didn’t see it, I posted 3 posts about the Further Processing exhibition over on Generator.x: #1, #2, #3. Or you can just look at the Flickr photoset if you prefer.

No Comments »