Giter Club home page Giter Club logo

geojson2shp's Introduction

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

geojson2shp's People

Contributors

jdesboeufs avatar papb avatar yizhakbn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geojson2shp's Issues

Forward feature ID as Shapefile Feature ID?

I'm trying to maintain a feature ID from a dataset to another one, so I use the id GeoJSON attribute.

{
  "type": "Feature",
  "id": 21420
  "properties": {}
  "geometry": {}
}
Loading

I get it with the feature.fid gdal-next attribute:

while (feature = layer.features.next()) {
    const id = feature.fid
    // ...
}

But unfortunately, the feature ID advertised in the shapefile is a different one.

Is there a mechanic to use to forward this identifier?
See the various feature id in QGIS panel.

Screenshot 2021-12-06 at 20 03 06

I'm willing to use this to overlay 2 layers, and to remove features of layer B from the layer A.

how to escape zipping when saving shp file?

Hello, great lib, thank you.

Can I just save the *.shp, *.prj... files to a folder instead of zipping?

I saw

const zipFile = new ZipFile();
 const zipStream = zipFile.outputStream

in "lib/stream.js",

I want to add some lines like if(zip =false) fs.write(*.shp)

I am very confuse by the pipe line and stream, can not do it rightly.

geojson2shp completely browser-based

Can I use this library as a completely browser based script, without needing NodeJS?
Maybe browserify can help?

I am using the shpwrite.download(geojsonData) and shpwrite.zip(geojsonData, options) functions, but my web application cannot read the resulting a shapefile.

Variable Title

Bonjour :) Premièrement merci de mettre à disposition cet outil 👍 il marche parfaitement j'ai seulement une question à propos de son fonctionnement:

Le fichier généré présente les informations de la manière suivante:

layer
---Title
-----geojson property 1
-----geojson property 2

Est-il possible de changer la valeur "Title" pour mettre "id" à la place par example ?

Merci d'avance !

Feature: add encoding type option to convert method

Right now the .dbf writer accepts encoding in ctor but there is no way to pass the encoding type to him which limits the datasets you can work with.
As well it could be cool if there would be an option to create .cpg file which specify the same encoding type so it can be used with other languages.

Bugged conversion

Using this library generate a shp file, but don't represent the original file.

What I'm doing:

const {convert} = require('geojson2shp')

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

async function converter() {
	await convert('./agricultura.geojson', './dest-shp.zip', options)
}
converter();

The original file:
originalGeoJSON

The generated one:
createdSHP

If I'm missing something, please let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.