Skip to content

Convert GeoJSON into Shapefile in pure JavaScript

License

Notifications You must be signed in to change notification settings

Datayama38/geojson2shp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

geojson2shp

Convert GeoJSON into Shapefile in pure JavaScript

Prerequisites

Usage (CLI)

With global installation

# Installation
npm install geojson2shp -g

# Conversion
cat my.geojson | geojson2shp > my-shp.zip

With npx (included in Node.js installation)

# Conversion
cat my.geojson | npx geojson2shp > my-shp.zip

Usage (Node.js)

Basic

const {convert} = require('geojson2shp')

const options = {
  layer: 'my-layer',
  targetCrs: 2154
}

// Paths
await convert('/path/to/source.geojson', '/path/to/dest-shp.zip', options)

// Streams
await convert(inputGeoJSONStream, outputZippedShapefileStream, options)

// FeatureCollection as input
const featureCollection = {type: 'FeatureCollection', features: [/* */]}
await convert(featureCollection, '/path/to/dest-shp.zip', options)

// Features as input
const features = [
  {type: 'Feature', geometry: {/* */}, properties: {}},
  {type: 'Feature', geometry: {/* */}, properties: {}}
]
await convert(features, '/path/to/dest-shp.zip', options)

// Or mix them ;)

Custom stream

const fs = require('fs')
const {createConvertStream} = require('geojson2shp')


myGeoJSONStream
  .pipe(createConvertStream({
    targetCrs: 2154,
    layer: 'my-layer'
  }))
  .pipe(fs.writeWriteStream('/path/to/my-shapefile.zip'))

License

MIT

About

Convert GeoJSON into Shapefile in pure JavaScript

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%