Skip to content

Commit

Permalink
fun commandline js tools: render.js (like nik2img.py) and inspect.js …
Browse files Browse the repository at this point in the history
…(pass it a shapefile, geojson, or mapnik xml and get back info)
  • Loading branch information
Dane Springmeyer committed Jan 15, 2011
1 parent b5823b9 commit ef7e4e9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bin/inspect.js
@@ -1,9 +1,8 @@
#!/usr/bin/env node

var sys = require('fs');
var path = require('path');

var usage = 'usage: inspect.js <datasource>';
var usage = 'usage:\n inspect.js <datasource> \n inspect.js <stylesheet>';

var ds = process.ARGV[2];
if (!ds) {
Expand All @@ -26,7 +25,12 @@ else if ((/.json$/.test(ds)) || (/.geojson$/.test(ds))) {
var opened = new mapnik.Datasource({type: 'ogr', file: ds, 'layer_by_index': 0});
console.log(opened.describe());
}
else if (/.xml$/.test(ds)) {
var map = new mapnik.Map(1,1);
map.load(ds);
console.log(map.layers());
}
else {
console.log('only currently supports shapefiles and geojson');
console.log('only currently supports shapefiles and geojson datasources or mapnik xml');
process.exit(1);
}
26 changes: 26 additions & 0 deletions bin/render.js
@@ -0,0 +1,26 @@
#!/usr/bin/env node

var sys = require('fs');
var child_process = require('child_process');

var usage = 'usage: render.js <stylesheet> <image>'

var stylesheet = process.ARGV[2];
if (!stylesheet) {
console.log(usage);
process.exit(1);
}

var image = process.ARGV[3];
if (!image) {
console.log(usage);
process.exit(1);
}

var mapnik = require("mapnik");

var map = new mapnik.Map(600,400);
map.load(stylesheet);
map.zoom_all();
map.render_to_file(image);
child_process.exec('open ' + image)

0 comments on commit ef7e4e9

Please sign in to comment.