Sometimes, when we want to peek a shapefile, see what’s the shape type it is, how many records it has, or find out what properties it contains. There are some free tools to visualize it. But most of the tools are too heavy or maybe not possible to support multiple platforms such as macOS or Linux. Here is a cross platform command line tool to inspect a specified shapefile on our local machine with Ginkgoch map library. It provides functions to inspect a specified shapefile’s header, fields, records etc. You could see, it is totally free and open source. Enjoy it!
This command line tool is created by Ginkgoch Map Library which is powerful map library written by Node.js for building cross platform map software for desktop, web service and mobile applications with your own GIS data.
Install
1 2 3 4 5 6 7 8 9
# global install npm i -g ginkgoch-shapefile-cli
# local install npm i --save ginkgoch-shapefile-cli
## Help ```terminal shapefile-cli --help
Usage: index command [options] <file>
Options:
1 2
-V, --version output the version number -h, --help output usage information
Commands:
1 2 3 4
show-header [options] <file> output a specified shapefile header information show-fields [options] <file> output a specified shapefile fields information show-records [options] <file> output a specified shapefile records information convert-geojson [options] <file> Convert shapefile to GeoJson
Show Header
Show header help
1
node index.js show-header --help
Usage: show-header [options] <file>
Options:
1 2
-p, --pretty output header with pretty table format -h, --help output usage information
Example - print a shapefile’s header with pretty table format
shapefile-cli show-fields ~/Downloads/data/shp/USStates.shp -p ╔════════════╤══════╤════════╤═════════╗ ║ name │ type │ length │ decimal ║ ╟────────────┼──────┼────────┼─────────╢ ║ AREA │ N │ 12 │ 3 ║ ╟────────────┼──────┼────────┼─────────╢ ║ PERIMETER │ N │ 12 │ 3 ║ ╟────────────┼──────┼────────┼─────────╢ ║ STATE_ │ N │ 11 │ 0 ║ ╟────────────┼──────┼────────┼─────────╢ ║ STATE_ID │ N │ 11 │ 0 ║ ╟────────────┼──────┼────────┼─────────╢ ║ STATE_NAME │ C │ 25 │ NaN ║ ╟────────────┼──────┼────────┼─────────╢ ║ STATE_FIPS │ C │ 2 │ NaN ║ ╟────────────┼──────┼────────┼─────────╢ ║ SUB_REGION │ C │ 7 │ NaN ║ ╟────────────┼──────┼────────┼─────────╢ ║ STATE_ABBR │ C │ 2 │ NaN ║ ╟────────────┼──────┼────────┼─────────╢ ║ POP1990 │ N │ 9 │ 0 ║ ╟────────────┼──────┼────────┼─────────╢ ║ RECID │ N │ 9 │ 0 ║ ╚════════════╧══════╧════════╧═════════╝
Show Records
Show records help
1
shapefile-cli show-records --help
Usage: show-records [options] <file>
Options:
1 2 3 4 5
-l, --limit <n> returning records limit. accept any number. 0 means all records. default to 10 -c, --columns <items> returning columns include in the results. Multiple columns are supported by separater ",". Default to all columns -g, --geom includes geometry in the returned content -p, --pretty output records with a pretty table format -h, --help output usage information
Example - print a shpefiles’s top 10 records info with field name STATE_NAME, RECID and geometry in pretty table format.
Tips: - set option -l, --limit to 0 to read all records - use option -g, --geom to 0 to read all records with geometry - use option -p, --pretty to return data with pretty table format - use option -c, --column to return necessary fields. e.g. -c field1,field2 returns two fields
Convert to GeoJson
Show records help
1
shapefile-cli convert-geojson --help
Usage: convert-geojson [options] <file>
Options:
1 2 3
-c, --columns <items> returning columns include in the results. Multiple columns are supported by separater ",". Default to all columns -o, --output <value> output file path. If only directory is specified, the same file name will be used. Default to the same folder of the sourceShapefile -h, --help output usage information