npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ginkgoch-shapefile-cli

v1.4.2

Published

This is command line tool for inspecting shapefiles.

Downloads

5

Readme

Shapefile Command Line Tool

This is a command line tool to help to inspect a specified shapefile. It provides function to inspect a specified shapefile's header, fields, records etc.

Install

# global install
npm i -g ginkgoch-shapefile-cli

# local install
npm i --save ginkgoch-shapefile-cli

Help

shapefile-cli --help

Usage: index command [options] <file>

Options:

-V, --version                  output the version number
-h, --help                     output usage information

Commands:

show-header [options] <file>       Output shapefile header information
show-fields [options] <file>       Output shapefile fields information
show-records [options] <file>      Output shapefile records information
convert-geojson [options] <file>   Convert shapefile to GeoJson
build-index [options] <fileOrDir>  Build index for shapefile
reproject [options] <file>         Re-project shapefile to a specific SRS
serve [options] <fileOrDir>             Launch a server for exploring shapefile(s) on browser

Show Header

Show header help

node index.js show-header --help

Usage: show-header [options] <file>

Options:

-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-header ~/Downloads/data/shp/USStates.shp -p
╔════════════╤═════════════════════╗
║ fileCode   │ 9994                ║
╟────────────┼─────────────────────╢
║ fileLength │ 222344              ║
╟────────────┼─────────────────────╢
║ version    │ 1000                ║
╟────────────┼─────────────────────╢
║ fileType   │ Polygon             ║
╟────────────┼─────────────────────╢
║ minx       │ -178.21502685546875 ║
╟────────────┼─────────────────────╢
║ miny       │ 18.924781799316406  ║
╟────────────┼─────────────────────╢
║ maxx       │ -66.9698486328125   ║
╟────────────┼─────────────────────╢
║ maxy       │ 71.40664672851562   ║
╚════════════╧═════════════════════╝

Show Fields

Show fields help

shapefile-cli show-fields --help

Usage: show-fields [options] <file>

Options:

-p, --pretty  output fields with a pretty table format
-h, --help    output usage information

Example - print a shapefile's fields info in 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

shapefile-cli show-records --help

Usage: show-records [options] <file>

Options:

-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.

shapefile-cli show-records ~/Downloads/data/shp/USStates.shp -g -l 10 -c STATE_NAME,RECID

╔══════════════╤═══════╤════════════════════════════════╗
║ STATE_NAME   │ RECID │ geom                           ║
╟──────────────┼───────┼────────────────────────────────╢
║ Washington   │ 1     │ [[{"x":-122.40074920654297,... ║
╟──────────────┼───────┼────────────────────────────────╢
║ Montana      │ 2     │ [[{"x":-111.4746322631836,"... ║
╟──────────────┼───────┼────────────────────────────────╢
║ Maine        │ 3     │ [[{"x":-69.77778625488281,"... ║
╟──────────────┼───────┼────────────────────────────────╢
║ North Dakota │ 4     │ [[{"x":-98.73005676269531,"... ║
╟──────────────┼───────┼────────────────────────────────╢
║ South Dakota │ 5     │ [[{"x":-102.78793334960938,... ║
╟──────────────┼───────┼────────────────────────────────╢
║ Wyoming      │ 6     │ [[{"x":-104.05310821533203,... ║
╟──────────────┼───────┼────────────────────────────────╢
║ Wisconsin    │ 7     │ [[{"x":-87.74845123291016,"... ║
╟──────────────┼───────┼────────────────────────────────╢
║ Idaho        │ 8     │ [[{"x":-117.02530670166016,... ║
╟──────────────┼───────┼────────────────────────────────╢
║ Vermont      │ 9     │ [[{"x":-73.25850677490234,"... ║
╟──────────────┼───────┼────────────────────────────────╢
║ Minnesota    │ 10    │ [[{"x":-91.73021697998047,"... ║
╚══════════════╧═══════╧════════════════════════════════╝

Reading complete. 10/51 record(s)

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

Convert shapefile to GeoJSON format help

shapefile-cli convert-geojson --help

Usage: convert-geojson [options] <file>

Options:

-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

Example - converts a shapefile to GeoJson format.

shapefile-cli convert-geojson ./tests/data/USStates.shp

Conversion complete. New file is saved at ./tests/data/USStates.json.

Build index

Build spatial index help

shapefile-cli build-index --help

Usage: build-index [options] <fileOrDir>

Options:

-w, --overwrite  Overwrite if index files exist. Default is "false"
-h, --help       output usage information

Re-projection

Re-project from current coordinate system to another help

shapefile-cli reproject --help

Usage: reproject [options] <file>

Options:

--outputSrs <outputSrs>  [Required] The target SRS. It is required
--sourceSrs <sourceSrs>  the source SRS. If .prj file doesn't exist, this option will be applied as source SRS
-o, --output <output>    the output shapefile path. Default is the source file name with "_[targetSRS]" suffix
-w, --overwrite          overwrite if index files exist. Default is "false"
-h, --help               output usage information

Launch a server

Launch a server for exploring shapefile on browser.

shapefile-cli reproject --help

Usage: serve [options] <fileOrDir>

Options:

-p, --port <port>  the server port exposed to browse, default port is 3000
-h, --help         output usage information

Take a look at a screenshot of serving a specific directory: shapefile-cli-serve

Issues

Contact [email protected] or submit an issue.