gtran v1.0.11
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:
name - Name property of feature.
symbol - Symbol of saved features. Detail about supported style 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);
});