geo-xform

1.3.0 • Public • Published

GeoXForm

A library for transforming large streams of geojson into csv, kml, shapefile and other formats

npm travis

Example

  • Get GeoJSON from the web -> transform into csv -> write to disk
const GeoXForm = require('geo-xform')
const request = require('request')
const fs = require('fs')
const id = '593b88391b614123890f54a1db8fbf55_0'
request.get(`http://opendata.arcgis.com/datasets/${id}.geojson`)
.pipe(GeoXForm.createStream('csv'))
.pipe(fs.createWriteStream('./trees.csv'))
.on('finish', () => console.log('File written to trees.csv'))
 

Set up

Install GDAL

  • With Homebrew on OSX: brew install gdal
  • On Ubuntu: sudo apt-get install gdal-bin

Install node dependencies

  • (sudo) npm install

Development

Transpile to ES5

  • npm run compile

Test

  • npm test

API

createStream(format, options)

Create a stream that takes in geojson of arbitrary size and returns data in the selected format

  • Format: the requested output format e.g. csv, zip (shapefile), kml
  • Options:
{
      path: string // disk location to write temp files (optional)
      name: string // sets the name file parts (shapefile only)
      metadata: string // and xml string to write to file (shapefile only)
      srs: string // the spatial reference system for projecting transformed data (shapefile only)
}

GeoJSON.createStream(options)

Create a stream that takes in individual features and returns a feature collection

  • Input: A stream of individual GeoJSON features as strings or objects
  • Options:
{
    json: boolean // flags whether the input is JSON or string
}

VRT.createStream(options)

Create a steam that takes in geojson and outputs an OGR Virtual Layer

  • Options:
{
    size: integer // number of features to write into each GeoJSON part, defaults to 5000
    path: string // output path to write the VRT XML and GeoJSON parts
}

OGR.createStream(format, options)

Create a stream that takes in a layer and outputs transformed data

  • Format: the requested output format e.g. csv, zip (shapefile), kml
  • Options:
{
      geometry: string // on of ['point', 'line', 'polygon']
      fields: array // the names of fields in a given dataset (csv only)
      name: string // sets the name file parts (shapefile only)
      metadata: string // and xml string to write to file (shapefile only)
      srs: string // the spatial reference system for projecting transformed data (shapefile only)
}

Package Sidebar

Install

npm i geo-xform

Weekly Downloads

4

Version

1.3.0

License

Apache-2.0

Last publish

Collaborators

  • dmfenton