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

shp-kit

v0.2.4

Published

Read & write shapefiles on the modern web.

Downloads

742

Readme

SHP-KIT Logo

shp-kit is a JavaScript library under development, providing functionality to read and write shapefiles from GeoJSON. The library focuses on simplifying the conversion process between GeoJSON and shapefiles, making it easier for developers to work with spatial data.

Shapefile Types Support

The following table outlines the current support for different types of shapefiles in the library:

| Shapefile Type | Read | Write | | -------------- | ---- | ----- | | Point | ✅ | ✅ | | PolyLine | ✅ | ✅ | | Polygon | ❌ | ❌ | | MultiPoint | ❌ | ❌ | | PointZ | ✅ | ✅ | | PolyLineZ | ✅ | ✅ | | PolygonZ | ❌ | ❌ | | MultiPointZ | ❌ | ❌ | | PointM | ✅ | ✅ | | ⚠ PolyLineM | ✅ | ✅ | | ⚠ PolygonM | ❌ | ❌ | | ⚠ MultiPointM | ❌ | ❌ | | MultiPatch | ❌ | ❌ |

Please note:

  1. Types ending with M are outdated, not sufficiently tested, and not recommended for use.
  2. The API specified below may change without notice before reaching v1.0.0

Library Functions

shpWriteZip

shpWriteZip: (
  filename: string, // Shapefile name (with or without extension .zip)
  geojson: FeatureCollection, // GeoJSON feature collection
  type: "Point" | "PolyLine" | "Polygon" | "MultiPoint" | "PointZ" | "PolyLineZ" | "PolygonZ" | "MultiPointZ" | "PointM" | "PolyLineM" | "PolygonM" | "MultiPointM" | "MultiPatch", 
  options?: Partial<Options>, // See available options below
  download?: boolean, // If true, attempts to download the ZIP after generating
  wktProjectionString?: string // If you have a shapefile *.prj compatible WKT projection string, you can include it here. Note: your geojson should be in this projection already. Consider using reprojectGeoJson available below if you need to re-project your data.
) => Promise<Blob>

shpWrite

shpWrite: (
    geojson: FeatureCollection, // GeoJSON feature collection
    type: "Point" | "PolyLine" | "Polygon" | "MultiPoint" | "PointZ" | "PolyLineZ" | "PolygonZ" | "MultiPointZ" | "PointM" | "PolyLineM" | "PolygonM" | "MultiPointM" | "MultiPatch",
    options?: Partial<Options> // See available options below
) => Promise<{ // Object containing the most important files in a shapefile, objects are given as Dataviews. Use shp.buffer to do whatever you need from here
  shp: ArrayBuffer,
  shx: ArrayBuffer,
  dbf: ArrayBuffer,
}>

Write options and their defaults:

| Key | Expected type / Default Value | Description | | ------------------------------------------------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | bundlePolygons | boolean / true | If true, Polygons will be interpreted as LineStrings and exported with PolyLine like Shapefile type | | bundleMultiTypes | boolean / true | If true, MultiPolyline and MultiPolygons will be parsed as their basic counterpart | | elevationPropertyKey | string / null | If a Z-type Shapefile is chosen, by default elevation will be searched in feature's coordinates as 3rd element of coordinate array, if elevation is a property of given object, you can set the property name here | | measurePropertyKey | string / null | Shapefiles support an additional numeric measure value, as denoted by shapefile types ending with M, if a key from feature.properties: {[key]: value} is given, this will be used as the M value in the written shapefile. |

shpReadZip

shpReadZip: (
  file: File | Blob | ZipUrl, 
  options?: Partial<Options> // See available options below
  ) => Promise<FeatureCollection> // GeoJSON feature collection

shpRead

shpRead: (
  shp: File, // File or Blob
  options?: Partial<Options> // See available options below
  dbf?: File, // optional dbase file that would populate feature properties
  prj?: File | string // optional projection file, or projection string. If present, shpRead will re-project your shapefile into WGS84, alternatively feel free to use reprojectGeojson function also available in this library
) => Promise<FeatureCollection> // GeoJSON feature collection

| Key | Expected type / Default Value | Description | | ------------------------------ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | elevationPropertyKey | string / null | By default where elevation available, it will be set as 3rd element in the coordinates array, if elevationPropertyKey is set, elevation will be added to feature properties under provided key instead. | | measurePropertyKey | string / null | if measurePropertyKey is set, and measure values available, they will be added to feature properties under provided key. | | originalGeometryPropertyKey | string / null | Key under which you would like the original geometry to be saved. Useful when showing feature on a WGS84 map while showing feature coordinates on select/hover in another coordinate system |

reprojectGeoJson

reprojectGeoJson: (
  geojson: FeatureCollection, // GeoJSON feature collection
  sourceProjection: string, // Can be either PROJ.4 string or WKT string, such as you find in the *.prj file with your shapefile (if provided)
  targetProjection: string, // Can be either PROJ.4 string or WKT string, such as you find in the *.prj file with your shapefile (if provided)
  originalGeometryPropertyKey?: string // Key under which you would like the original geometry to be saved. Useful when showing feature on a WGS84 map while showing feature coordinates on select/hover in another coordinate system
) => FeatureCollection // GeoJSON feature collection