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

gtran

v1.0.11

Published

Geographic data transformation

Downloads

26

Readme

gtran

Geospatial data I/O package making data conversion simple and manageable.

Installation

npm install gtran

Features

  • Multi-format support - Just one package.

  • Simple functions - Consistent functions for different formats, just from() and to().

  • Promised - Powered by native Promise and it is happy working with your choice of promise library (Q, bluebird, and promise).

  • GeoJson input/output - Get GeoJson from your file and save it into whatever you want.

Supported Formats

  • CSV (point data only)

  • KML

  • KMZ (write only)

  • Shapefile

  • TopoJson (write only)

Functions

gtran provides two of functions: from[format name]() and to[format name]() for each support format.

  • from[format name](fileName [, options])

    Read the geospatial data file and return a GeoJson object.

  • to[format name](geojson, fileName [,options])

    Write the GeoJson object into a file with given name and format. If the file name is not given, the function returns a data object that could be written into file.

A full list of available functions:

  • setPromiseLib(object)

    Specify the promise library. If not, the library will use the native Promise.

  • .fromCSV(fileName, options)

    options:

    • projection - Geographic coordinate columns, necessary parameter. Please check the use example.
  • .toCSV(geojson, fileName)

  • .fromKml(fileName)

  • .toKml(geojson, fileName, options)

    options:

  • .toKmz(geojson, fileName)

  • .fromShp(fileName)

  • .toShp(geojson, fileName, options)

    options:

    • esriWKT - ESRI WTK string that specifies the shapefile's spatial reference and generates .prj file. The ESRI WKT string could be found at SpatialReference.org.
  • .toTopo(geojson)

Use Example

var gtran = require('gtran');

# Specify the promise library if necessary
gtran.setPromiseLib(require('bluebird'));

# Read shapefile
gtran.fromShp('source.shp')
.then(function(object) {
    var geojson = object;
});

# Save geojson into shapefile
gtran.toShp(geojson, 'point.shp')
.then(function(fileNames) {
    console.log('SHP files have been saved at:' + fileNames.toString());
});

# Read csv file
# If the test.csv has two columns: latitude and longitude
gtran.fromCSV('source.csv', {
    mapping: { x: 'longitude', y: 'latitude' }
})
.then(function(object) {
    var geojson = object;
});

# Save geojson into a csv file
gtran.toCSV(geojson, 'point.csv')
.then(function(fileName) {
    console.log('CSV file has been saved at:' + fileName);
});