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

ogr2ogr-edit

v0.0.1

Published

ogr2ogr wrapper w/ multiple format support

Downloads

2

Readme

Credits

This package is a clone from the original, but with few edits to help our case. So, CTTO: Marc Harter [email protected]. And my Friend @Al-Jezawi [email protected] who made the edits

Installation

  1. [Install GDAL tools][1] (includes the ogr2ogr command line tool)

  2. Install package:

npm install ogr2ogr

Usage

ogr2ogr takes either a path, a stream, or a [GeoJSON][2] object. The result of the transformation will depend on the format returned.

// Using CommonJS modules
const ogr2ogr = require('ogr2ogr').default
// Using ECMAScript modules or Typescript
import ogr2ogr from 'ogr2ogr'

// Promise API
(async() {
  // Convert path to GeoJSON.
  let {data} = await ogr2ogr('/path/to/spatial/file')
  console.log(data)

  // Convert GeoJSON object to ESRI Shapefile stream.
  let {stream} = await ogr2ogr(data, {format: 'ESRI Shapefile'})

  // Convert ESRI Shapefile stream to KML text.
  let {text} = await ogr2ogr(stream, {format: 'KML'})
  console.log(text)
})()

// Callback API
ogr2ogr('/path/to/spatial/file').exec((err, {data}) => {
  console.log(data)
})

Formats

ogr2ogr has varying support for format input and output. Consult the particular [driver][3] you are interested in for more details. It is highly recommend to run the latest version of GDAL to get the best support. This project attempts to cast the widest net for support. Here are some notables:

| Drivers | Output | Notes | | ----------------------------------------------------- | -------- | ------------------------------------------- | | GeoJSON | data | Default format returned when none specified | | CSV, GeoRSS, GML, GMT, GPX, JML, KML, MapML, PDF, VDV | text | Drivers supporting /vsidout/ return text | | Other | stream | All other drivers return a file stream |

API

ogr2ogr(input, options?) -> Promise<output>

The input may be one of:

  • A path (string). This includes file paths and network paths including HTTP endpoints.
  • A ReadableStream.
  • A [GeoJSON][2] object.

The following options are available (none required):

  • format - Output format (default: GeoJSON)
  • timeout - Timeout before command forcibly terminated (default: 0)
  • maxBuffer - Max output size in bytes for stdout/stderr (default: 1024 * 2014 * 50)
  • options - Custom [ogr2ogr arguments][4] and [driver options][5] (e.g. ['--config', 'SHAPE_RESTORE_SHX', 'TRUE'])
  • env - Custom environmental variables (e.g. {ATTRIBUTES_SKIP: 'YES'})
  • destination - Select another output than the output object (e.g. useful for writing to databases).
  • command - Command to run (default: ogr2ogr)

The output object has the following properties:

  • cmd - The ogr2ogr command executed (useful for debugging).
  • text - Text output from [drivers][3] that support /vsistdout/ (see formats above)
  • data - Parsed [GeoJSON][2] output (used when format is GeoJSON)
  • stream - A ReadableStream of the output. Used for [drivers][3] that do not support /vsistdout/.
    • If a driver generates more than one file (like ESRI Shapefile), this will be a zip stream containing all the data.
  • extname - The file extension of the data returned.
  • details - Any text printed to STDERR. This includes any warnings reported by ogr2ogr when it ran.

ogr2ogr(input, options?).exec((err, output))

The callback API supports the same options as above but in a NodeJS style callback format.

Tips and tricks

Running ogr2ogr in a [Docker container][6]:

ogr2ogr('/home/.../path/to/spatial/file', {
  command: 'docker run -v /home/:/home --rm osgeo/gdal ogr2ogr',
})

Converting an isolated .shp file:

ogr2ogr('/path/to/file.shp', {
  options: ['--config', 'SHAPE_RESTORE_SHX', 'TRUE'],
})

Getting more debug information by using the [CPL_DEBUG][7] option. Debug info added to details on the output object.

ogr2ogr('/path/to/file.shp', {
  options: ['--config', 'CPL_DEBUG', 'TRUE'],
})

Parsing custom geometry fields in a CSV. Use [CSV driver options][8], like:

ogr2ogr('/path/to/file.csv', {
  options: ['-oo', 'GEOM_POSSIBLE_NAMES=the_geom'],
})

Re-project geometry:

ogr2ogr('/path/to/file.shp', {
  options: ['-t_srs', 'EPSG:4326'],
})