/usr/bin/mapnik-inspect is in node-mapnik 3.7.1+dfsg-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | #!/usr/bin/env node
"use strict";
var exists = require('fs').existsSync || require('path').existsSync;
var fs = require('fs');
var usage = 'usage:';
usage += '\n mapnik-inspect.js <datasource> (.vector.pbf|.mvt|.shp|.json|.geojson|.osm|.kml|.sqlite|.gml|.vrt|.csv)';
usage += '\n mapnik-inspect.js <stylesheet> (.xml)';
usage += '\n mapnik-inspect.js <projection> (.prj)';
usage += '\n mapnik-inspect.js <zipfile> (.zip)';
usage += '\n mapnik-inspect.js <svg> (.svg) (will print png image to stdout)';
var obj = process.argv[2];
if (!obj) {
console.log(usage);
process.exit(1);
}
if (!exists(obj)) {
console.log(obj + ' does not exist');
process.exit(1);
}
var mapnik = require('../');
mapnik.register_default_input_plugins();
var meta = function(ds) {
console.log('Description -->');
console.log(ds.describe());
console.log('extent: ' + ds.extent().toString());
var fs = ds.featureset();
var count = 0;
if (fs) {
var feat = fs.next();
while (feat) {
count++;
feat = fs.next();
}
}
console.log(count,'features');
};
if (/.shp$/.test(obj)) {
var opened = new mapnik.Datasource({type: 'shape', file: obj});
meta(opened);
}
else if ((/.svg$/.test(obj))) {
mapnik.Image.fromSVGBytes(fs.readFileSync(obj),function(err,img) {
if (err) {
console.error(err.message);
process.exit(1);
}
var output="/tmp/mapnik-inspect.png";
img.save(output);
console.log("Saved image to "+output);
});
}
else if ((/.vector.pbf$/.test(obj)) || (/.mvt$/.test(obj))) {
console.log(mapnik.VectorTile.info(fs.readFileSync(obj)));
}
else if ((/.csv$/.test(obj)) ||
(/.tsv$/.test(obj)) || // google refine output .tsv for tab-separated files
(/.txt$/.test(obj))) {
var opened = new mapnik.Datasource({type: 'csv', file: obj});
meta(opened);
}
else if (/.osm$/.test(obj)) {
var opened = new mapnik.Datasource({type: 'osm', file: obj});
meta(opened);
}
else if ((/.sqlite$/.test(obj)) ||
(/.sqlite3$/.test(obj)) ||
(/.db$/.test(obj))
) {
var opened = new mapnik.Datasource({type: 'sqlite', file: obj, 'table_by_index': 0});
meta(opened);
}
else if ((/.json$/.test(obj)) ||
(/.geojson$/.test(obj))) {
var opened = new mapnik.Datasource({type: 'geojson', file: obj, cache_features:false});
meta(opened);
}
else if ((/.kml$/.test(obj)) ||
(/.gml$/.test(obj)) ||
(/.dbf$/.test(obj))
) {
var opened = new mapnik.Datasource({type: 'ogr', file: obj, 'layer_by_index': 0});
meta(opened);
}
else if ((/.tif$/.test(obj)) ||
(/.tiff$/.test(obj)) ||
(/.vrt$/.test(obj)) ||
(/.geotif$/.test(obj)) ||
(/.geotiff$/.test(obj))
) {
var opened = new mapnik.Datasource({type: 'gdal', file: obj});
meta(opened);
}
else if (/.xml$/.test(obj)) {
var map = new mapnik.Map(1, 1);
map.loadSync(obj);
map.layers().forEach(function(l) {
if (l.name == 'place_label') {
var ds = l.datasource;
//console.log(l.describe(),console.log(ds.describe()),ds.featureset().next().attributes());
console.log(ds.featureset().next().attributes());
}
});
}
else if (/.prj$/.test(obj)) {
var srs = require('srs');
var string = fs.readFileSync(obj).toString();
var srs_obj = srs.parse(string);
if (!srs_obj.proj4)
srs_obj = srs.parse('ESRI::' + string);
console.log(srs_obj);
}
else if (/.zip$/.test(obj)) {
var zip = require('zipfile');
var zf = new zip.ZipFile(obj);
console.log(zf);
}
else {
console.log('Error: unsupported file, unable to inspect');
process.exit(1);
}
|