Skip to content

Instantly share code, notes, and snippets.

@lwu
lwu / README
Created August 12, 2008 05:18
example code demonstrating Mapnik C++ API
This code snippet, modifed from Mpanik's rundemo.cpp (r727, license LGPL),
renders the State of California using USGS state boundaries data.
Here's a play-by-play (via https://lists.berlios.de/pipermail/mapnik-devel/2008-August/000679.html)
rundemo.cpp renders a map of Ontario/Quebec, and instead I wanted to draw a
map of California and its surrounding states.
I grabbed the data from the USGS in the form of "statesp020" (google it, or
browse through nationalatlas.gov) and first wanted to modify rundemo.py
128.12.16.0/255 Stanford.Res.Mirrielees
128.12.21.0/255 Stanford.Res.Manzanita.Lantana
128.12.22.0/255 Stanford.Res.Manzanita.KimballRF
128.12.23.0/255 Stanford.Res.Manzanita.Kimball
128.12.42.0/255 Stanford.Res.Fraternity.KappaAlphaTheta
128.12.43.0/255 Stanford.Res.Sorority.DeltaDeltaDelta
128.12.45.0/255 Stanford.Res.Wilbur.Soto
128.12.47.0/255 Stanford.Res.Wilbur.Otero
128.12.48.0/255 Stanford.Res.Wilbur.Okada
128.12.49.0/255 Stanford.Res.Wilbur.Junipero
@lwu
lwu / .emacs.lisp
Created August 15, 2008 00:42
my .emacs cfg
;; lwu .emacs 2008 (CarbonEmacs)
;; paths and directories
(add-to-list 'load-path "~/src/elisp")
(custom-set-variables)
(custom-set-faces)
; (require 'tramp)
(setq tramp-default-method "ssh")
// This class implements a simple way of displaying point-based data in Mapnik
// (It has yet to be tested as Mapnik r729's memory_featureset is commented out now.)
//
class point_datasource : public mapnik::memory_datasource {
public:
point_datasource() : feat_id(0) {}
void add_point(double x, double y, const char* key, const char* value);
int type() const { return mapnik::datasource::Raster; }
private:
@lwu
lwu / debug_shoes.rb
Created August 26, 2008 03:20
DebugShoes, a quick sketch of a class that adds informative debug interactions to a Shoes app
# Shoes got you down? DebugShoes won't fail silently on ya...
#
class DebugShoes < Shoes
def self.app(*args, &blk)
super(*args) do
begin
self.instance_eval(&blk)
rescue => e
error(e) # log the error and inform the user!
@err_bar = flow :width => 1.0, :height => 32, :top => self.height-32, :left => 0 do
My first Shoes app! Shoes is a "Tiny Toolkit" for informal graphics and windowing:
http://code.whytheluckystiff.net/shoes/
I wanted to be able to easily edit Mapnik stylesheets, hit render, and see the result
right away. While this isn't a great solution -- the prototype shells out to a C++ binary to
re-render the map -- it works for the time being.
A screenshot of the resulting application can be seen here:
http://farm4.static.flickr.com/3095/2801694916_1a051349b4_b.jpg
(http://flickr.com/photos/wu_135/2801694916/sizes/l/)
@lwu
lwu / README
Created September 4, 2008 02:21
This Python code snippet demonstrates basic use of the proposed "PointDatasource"
object exposed by the Mapnik patch attached here: http://trac.mapnik.org/ticket/113
To run this code, you will need to grab a copy of Mapnik from trunk, apply this patch,
and also download the style.xml file below.
@lwu
lwu / shapefly.rb
Created February 4, 2009 01:04
Get the shapefile for a query string using Yahoo/Flickr webservices
#!/usr/bin/env ruby
%w[open-uri hpricot].each {|lib| require lib }
YAHOO_APP_ID = "[yourappidhere]"
FLICKR_KEY = "[yourapikeyhere]"
raise "alarms" if YAHOO_APP_ID =~ /here/
raise "no query arg specified" if ARGV.empty?
# command line query => Y! where query => Flickr getInfo query => wget shapefile => ogr2ogr to KML
@lwu
lwu / osm_bbox.rb
Created February 4, 2009 19:16
Download the OSM XML that contains a given KML (bounding box)
#!/usr/bin/env ruby
%w[open-uri hpricot].each {|lib| require lib }
# get KML bbox and grab OSM XML
raise "no query arg specified" if ARGV.empty?
kml_filename = ARGV[0]
doc = Hpricot(open(kml_filename))
coords = (doc/"coordinates")[0].inner_html.split.map { |x| x.split(',').map {|s| s.to_f } }
longs = coords.transpose[0]
@lwu
lwu / ZlibCompressor.mxml
Created March 12, 2009 05:18
Want to load compressed JSON files from ActionScript 3? Use this Ruby script (or AIR application) to create the compressed files
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
title="ZlibCompressor"
nativeDragDrop="onDrop(event)"
nativeDragEnter="onDragIn(event)"
>
<mx:Script>
<![CDATA[