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

@lbdudc/gp-shapefile-reader

v1.1.3

Published

Shapefile reader for Node.js, reads a folder and returns a JSON with the data of the shapefiles

Downloads

162

Readme

Shapefile Reader

GitHub license Node.js Version npm version

Description

The library offers comprehensive functionalities to process shapefiles, parsing them into a structured JSON format. By invoking the provided methods, users can easily navigate through the geographical and attribute data associated with each shapefile contained within a designated folder.

Installation

Install the package via npm:

npm install @lbdudc/gp-shapefile-reader

Usage

This library simplifies the reading and processing of shapefiles. To utilize its functionalities:

  1. Input: Refer to the "Input" section to understand the supported file formats and their requirements.

  2. Initialization: Create an instance of the Processor class, configuring it with the desired options.

  3. Path Specification: Provide the path to the folder containing the shapefiles to the Processor instance.

  4. Output: Check the "Output" section for details on the generated output structure and file formats.

Once initialized and provided with the necessary inputs, the Processor will generate a comprehensive JSON representation. This representation includes both geographical and attribute data associated with each shapefile.

import Processor from "@lbdudc/gp-shapefile-reader";

// Define the path to the folder containing the shapefiles
const inputPath = "./examples/shpfiles";
const outputPath = "./examples"; // By default, the output path is the same as the inputPath appended with '/output'

// Create a new Processor instance with customizable options
const processor = new Processor({
  encoding: "utf-8", // Set the file encoding: 'auto' (default), 'ascii', 'utf8', 'utf-8', 'latin1', 'binary', 'base64', 'hex'
  geographicInfo: false, // Include geographic information in the output (default: true)
  outputPath: outputPath, // Optional: designate a specific folder for processed shapefiles
});

// Process the folder containing the shapefiles
processor.processFolder(inputPath).then((content) => {
  // Returns an array of objects, each representing a shapefile
  // Refer to the Output JSON section for more information
  console.log(content);
});

Overview

Input

This library supports processing geographic data stored in Shapefile format. It accepts:

  • Individual files with extensions: .shp, .cpg, .dbf, .prj, .qpj, .shx.
  • Compressed data with Shapefile information in a .zip file.

The library efficiently handles these inputs for easy manipulation and analysis of geographic data.

Note: Ensure associated files share the same base name for the shapefile. Failure to do so may result in processing errors or incomplete data.

Output

The output folder will contain the Shapefiles zipped by their respective names.

Example

Suppose you have a set of Shapefile files named:

  • example.shp
  • example.cpg
  • example.dbf
  • example.prj
  • example.qpj
  • example.shx

When processed using this library, the output folder will include a zip file named example.zip, containing all these associated files.

Output JSON

The object returned by the processFolder method is an array of objects, one for each shapefile. Each object contains the following properties:

[
  {
    "name": "01_shapefile",
    "fileName": "01_shapefile.shp",
    "schema": [
      {
        "name": "name",
        "type": "Number || String || Boolean || Geometry ...",
        "length": "Number"
      }
    ],
    "geographicInfo": {
      "done": false,
      "value": {
        "type": "Feature",
        "properties": {
          "GEOID": 516864,
          "FASE": "2000"
        },
        "geometry": {
          "type": "MultiPoint",
          "coordinates": [[568244.3307745245, 4782578.271440068]]
        }
      }
    }
  }
]

Examples

Explore additional examples in the examples folder:

npm run example

Dependencies

  • jschardet: 3.0.0
  • jszip: ^3.10.1
  • shapefile: ^0.6.6

Dev Dependencies

  • @vitest/coverage-istanbul: ^0.32.2
  • vitest: ^0.32.0

Author

Victor Lamas Email: [email protected]

License

This project is licensed under the MIT License - see the LICENSE.md file for details