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

shapefile.js

v1.1.4

Published

Easily read and parse Shapefiles from the browser.

Downloads

1,017

Readme

shapefile.js

Libraries.io dependency status for latest release CodeQL Node.js CI

JavaScript Style Guide

Introduction

Easily read and parse Shapefiles from the browser. Shapefile.js allows you to load a .zip as a buffer, and parse each file individually.

What is a Shapefile?

The shapefile format is a geospatial vector data format for geographic information system (GIS) software. It is developed and regulated by Esri as a mostly open specification for data interoperability among Esri and other GIS software products. The shapefile format can spatially describe vector features: points, lines, and polygons, representing, for example, water wells, rivers, and lakes. Each item usually has attributes that describe it, such as name or temperature.

Usage

React

Install the package into your application

npm install --save shapefile.js

Import the Shapefile class from shapefile.js

import React, { useState } from 'react'
import { Shapefile } from 'shapefile.js'

function ShapefileImporter() {
  const [shapefile, setShapefile] = useState()

  return (
    <input
      type="file"
      onChange={e => {
        if (e.target.files.length > 0) {
          e.target.files[0].arrayBuffer().then(arrayBuffer => {
            // Load the .zip file to expose its contents
            Shapefile.load(arrayBuffer).then(_shapefile => {
              // Set shapefile state
              setShapefile(_shapefile)
            })
          })
        }
      }}
    />
  )
}

export default ShapefileImporter

You can parse each file in the Shapefile ZIP. Some files require additional arguments.

const shp = shapefile.parse('shp');
const shx = shapefile.parse('shx');
const dbf = shapefile.parse('dbf', {
  // Stop parsing the file when the byte position hits the field descriptors terminator
  // This allows you to quickly get the fields used in the .dbf file and ignore the remainder of the file
  properties: false
})

UMD

Add a script tag to your HTML file with your desired shapefile.js version from a CDN provider

  • UNPKG: https://unpkg.com/shapefile.js/dist/shapefile.js
  • jsDelivr: https://cdn.jsdelivr.net/npm/shapefile.js/dist/shapefile.js

You can use the minified version by simply replacing the ending .js extension with .min.js

Use the ShapefileJS UMD global variable and access the Shapefile class

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">

    <!-- Load shapefile.js library -->
    <script src="https://unpkg.com/shapefile.js/dist/shapefile.js"></script>

    <!-- Add custom JS logic -->
    <script>
      window.addEventListener('DOMContentLoaded', () => {
        const shapefileInput = document.getElementById('shapefile-input')
        shapefileInput.addEventListener('change', () => {
          if (shapefileInput.files.length > 0) {
            shapefileInput.files[0].arrayBuffer().then(arrayBuffer => {
              // Load the .zip file to expose its contents
              ShapefileJS.Shapefile.load(arrayBuffer).then(shapefile => {
                console.log(shapefile.contents)
              })
            })
          }
        })
      })
    </script>
  </head>
  <body>
    <div>
      <input id="shapefile-input" type="file" />
    </div>
  </body>

License

Distributed under the GPL-3.0 License. See LICENSE for more information.

Contact

Matthew Downs

Email: [email protected]

Project Link: https://github.com/matthewdowns/shapefile.js