#!/usr/bin/env node var api = require('../'), Node = api.Node, trace = api.trace, Utils = api.Utils, opts = Node.options({binary:"s", aliases:"s:shapes"}), argv = opts._; if (argv.length != 1) stop("Usage: $ shpinfo file.shp"); var info = Node.getFileInfo(argv[0]); if (!info.exists) stop("File not found: " + info.file); var reader = new api.ShpReader(info.path), hasParts = reader.hasParts(), hasM = reader.hasM(), hasZ = reader.hasZ(), hasBounds = reader.hasBounds(), shapes = [], messages = []; trace("Type", reader.type(), "shapefile"); if (opts.s) { reader.forEachShape(function(shp) { var msgs = ["[" + shp.id + "]"]; if (shp.isNull) { msgs.push("[null]"); } else { if (hasParts) { msgs.push(msg("parts", shp.partCount)); } msgs.push(msg("points", shp.pointCount)); } if (hasZ) { msgs.push(msg('Z', "+")); } if (hasM) { msgs.push(msg("M", shp.hasM() ? "+" : "-")); } shapes.push(shp); messages.push(msgs); printMsg(msgs); }); } var counts = reader.getCounts(); trace("totals:", msg("shapes", counts.shapeCount), msg("parts", counts.partCount), msg("points", counts.pointCount), msg("null shapes", counts.nullCount)); function printMsg(arr) { trace(arr.join(' ')); } function stop(msg) { console.log(msg); process.exit(1); } function msg(label, val) { var msg = ""; if (label) msg += label; if (val !== undefined) { if (label) msg += " "; msg += "[" + val + "]"; } return msg; }