Shapefile Reader for Node.js is Open Source
- 2018-08-08
- Ginkgoch
ginkgoch-shapefile-reader
is a Node.js library to help to read shapefiles from your disk.
A shapefile is a simple, nontopological format for storing the geometric location and attribute information of geographic features. Geographic features in a shapefile can be represented by points, lines, or polygons (areas). The workspace containing shapefiles may also contain dBASE tables, which can store additional attributes that can be joined to a shapefile’s features.
Install
1 | npm i ginkgoch-shapefile-reader |
Test
1 | npm test |
Sample
Loops all records and print the vertices
1 | async function loopUSStates(callback) { |
Gets specific record by id
Gets records by id with all fields.
1 | async function getRecordById(id) { |
Gets records by id with none fields. Specify the fields to fetch from DBF to ignore reading unnecessary field values.
1 | async function getRecordById(id) { |
Gets matched features one time - Update v1.0.16
If you don’t like to use iteractor way, here is a normal way to get all features back.
1 | async function getAllRecords() { |
We also provide the filters that you could control the returned value. Here is the default filter structure.
from
{Number} means the start index of the records. Default value is 0. e.g. { from: 20 } means the returned feature is start from position 20.limit
{Number} means the features count includes in the returned features. Default value is Number.MAX_SAVE_INTEGERenvelope
{Envelope} means the returned features must intersect with the given envelope; default value is undefined, which means no envelope check.fields
{Array.<>} means the properties that returned with the features.
Let’s take a look at a demo. Says I want to paging my features. My page size is 10. I want to return all the features from my second page with only properties whose names are RECID and STATE_NAME. Here is the code.
1 | async function getAllRecords() { |