<commit_before>#!/usr/bin/env node

var exists = require('fs').existsSync || require('path').existsSync;
var fs = require('fs');

var usage = 'usage:';
usage += '\n  mapnik-inspect.js <datasource> (.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)';

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');

console.log(obj);

if (/.shp$/.test(obj)) {
    var opened = new mapnik.Datasource({type: 'shape', file: obj});
    console.log('Description -->');
    console.log(opened.describe());
    console.log('First feature --> ');
    console.log(opened.features().slice(0, 1));
}
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});
    console.log('Description -->');
    console.log(opened.describe());
    console.log('First feature --> ');
    console.log(opened.features().slice(0, 5));
}
else if (/.osm$/.test(obj)) {
    var opened = new mapnik.Datasource({type: 'osm', file: obj});
    console.log('Description -->');
    console.log(opened.describe());
    console.log('First feature --> ');
    console.log(opened.features().slice(0, 1));
}
else if ((/.sqlite$/.test(obj)) ||
         (/.sqlite3$/.test(obj)) ||
         (/.db$/.test(obj))
        ) {
    var opened = new mapnik.Datasource({type: 'sqlite', file: obj, 'table_by_index': 0});
    console.log('Description -->');
    console.log(opened.describe());
    console.log('First feature --> ');
    console.log(opened.features().slice(0, 1));
}
else if ((/.json$/.test(obj)) ||
         (/.geojson$/.test(obj))) {
    var opened = new mapnik.Datasource({type: 'geojson', file: obj});
    console.log('Description -->');
    console.log(opened.describe());
    console.log('First feature --> ');
    console.log(opened.features().slice(0, 1));
}
else if ((/.kml$/.test(obj)) ||
         (/.gml$/.test(obj)) ||
         (/.vrt$/.test(obj)) ||
         (/.dbf$/.test(obj))
        ) {
    var opened = new mapnik.Datasource({type: 'ogr', file: obj, 'layer_by_index': 0});
    console.log('Description -->');
    console.log(opened.describe());
    console.log('First feature --> ');
    console.log(opened.features().slice(0, 1));
}
else if (/.xml$/.test(obj)) {
    var map = new mapnik.Map(1, 1);
    map.loadSync(obj);<commit_msg>mapnik-inspect.js - support rasters as well<commit_after>#!/usr/bin/env node

var exists = require('fs').existsSync || require('path').existsSync;
var fs = require('fs');

var usage = 'usage:';
usage += '\n  mapnik-inspect.js <datasource> (.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)';

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');

console.log(obj);

var meta = function(ds) {
    console.log('Description -->');
    console.log(ds.describe());
    console.log('extent: ' + ds.extent().toString());
    console.log('First feature --> ');
    console.log(ds.features().slice(0, 1));
}

if (/.shp$/.test(obj)) {
    var opened = new mapnik.Datasource({type: 'shape', file: 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});
    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);
{'fraction_non_alphanumeric': 0.23642943305186973, 'fraction_numerical': 0.006031363088057901, 'mean_word_length': 2.9641434262948207, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5732812', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1798, 'n_words': 343}