Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haoliangyu/gtran
GeoJSON conversion with ease and consistency
https://github.com/haoliangyu/gtran
conversion csv geojson kml kmz shapefile topojson
Last synced: 3 months ago
JSON representation
GeoJSON conversion with ease and consistency
- Host: GitHub
- URL: https://github.com/haoliangyu/gtran
- Owner: haoliangyu
- License: mit
- Created: 2015-10-01T14:57:19.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-06-20T19:42:48.000Z (over 6 years ago)
- Last Synced: 2024-04-26T08:20:42.940Z (9 months ago)
- Topics: conversion, csv, geojson, kml, kmz, shapefile, topojson
- Language: JavaScript
- Homepage:
- Size: 45.9 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gtran
Geospatial data I/O package making data conversion simple and manageable.
## Installation
``` javascript
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:
* name - Name property of feature.
* symbol - Symbol of saved features. [Detail about supported style options](https://github.com/haoliangyu/gtran-kml).
* **.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](http://spatialreference.org/).
* **.toTopo(geojson)**
## Use Example
``` javascript
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);
});
```