Comparing version 1.2.1 to 1.2.2
52
cli.js
#!/usr/bin/env node | ||
var geojsonStream = require('geojson-stream'), | ||
es = require('event-stream'), | ||
reproject = require('./'), | ||
@@ -37,16 +38,26 @@ proj4 = require('proj4'), | ||
if ((fromCrs && toCrs) || (!argv.from && !argv.to)) { | ||
((argv._[0] && fs.createReadStream(argv._[0])) || process.stdin).pipe(geojsonStream.parse()) | ||
.on('header', openData) | ||
.on('footer', openData) | ||
.on('data', openData) | ||
.on('error', function (err) { | ||
console.error(err); | ||
}); | ||
var inputStream = ((argv._[0] && fs.createReadStream(argv._[0])) || process.stdin) | ||
var parser = geojsonStream.parse() | ||
.on('header', handleHeader) | ||
var transformStream = es.mapSync(transform) | ||
var outputStream = geojsonStream.stringify() | ||
inputStream.pipe(parser) | ||
parser.pipe(transformStream) | ||
transformStream.pipe(outputStream) | ||
outputStream.pipe(process.stdout) | ||
} | ||
} | ||
function openData(geojson) { | ||
// geojson-stream will break a FeaturesCollection's features into chunks that are fed to openData; | ||
// single geometries or GeometryCollection will be fed to as "header", so | ||
// we have to handle them here. | ||
function handleHeader(geojson) { | ||
if (geojson && geojson.type !== 'FeatureCollection') { | ||
// If top type isn't FeatureCollection, just transform the whole object in one pass and be done with it; | ||
// if we don't do this, geojson-stream will still output a FeatureCollection header, so the output | ||
// GeoJSON's structure will not match the input's. | ||
process.stdout.write(JSON.stringify(transform(geojson))); | ||
process.exit(0); | ||
} | ||
} | ||
function transform(geojson) { | ||
if (geojson) { | ||
@@ -62,13 +73,9 @@ var isGeomCol = geojson.type === 'GeometryCollection' && geojson.geometries; | ||
geojson = reproject.reproject(geojson, fromCrs, toCrs, crss); | ||
return reproject.reproject(geojson, fromCrs, toCrs, crss); | ||
} | ||
} | ||
outputJson(geojson); | ||
return geojson | ||
} | ||
function outputJson(json) { | ||
console.log(JSON.stringify(json, null, 2)); | ||
} | ||
function loadJson(f) { | ||
@@ -98,2 +105,13 @@ var data; | ||
if (!crss[crsName]) { | ||
var proj; | ||
try { | ||
proj = proj4(crsName); | ||
} catch (e) { | ||
// Ok, go on with proj unset. | ||
} | ||
if (proj) { | ||
return cb(proj); | ||
} | ||
if (useSpatialReference) { | ||
@@ -100,0 +118,0 @@ var crsPath = crsName.toLowerCase().replace(':', '/'); |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ 'use strict'; |
{ | ||
"name": "reproject", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Reproject GeoJSON from one projection/CRS to another", | ||
@@ -23,2 +23,3 @@ "repository": "git@github.com:perliedman/reproject.git", | ||
"concat-stream": "^1.5.1", | ||
"event-stream": "^3.3.4", | ||
"geojson-stream": "0.0.1", | ||
@@ -25,0 +26,0 @@ "minimist": "^1.2.0", |
@@ -0,0 +0,0 @@ reproject [![Build status](https://travis-ci.org/perliedman/reproject.png)](https://travis-ci.org/perliedman/reproject) [![NPM version](https://badge.fury.io/js/reproject.png)](http://badge.fury.io/js/reproject) |
@@ -0,0 +0,0 @@ 'use strict'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30272
729
5
10
+ Addedevent-stream@^3.3.4
+ Addedduplexer@0.1.2(transitive)
+ Addedevent-stream@3.3.5(transitive)
+ Addedfrom@0.1.7(transitive)
+ Addedmap-stream@0.0.7(transitive)
+ Addedpause-stream@0.0.11(transitive)
+ Addedsplit@1.0.1(transitive)
+ Addedstream-combiner@0.2.2(transitive)