Created
October 1, 2014 20:30
-
-
Save springmeyer/3e51067c2112d889d8d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
index 0a0eac1..cfc2908 100644 | |
--- a/index.js | |
+++ b/index.js | |
@@ -72,15 +72,21 @@ module.exports = function (inStream) { | |
var after = '\n]}\n' | |
var started = false | |
outStream.push(before) | |
+ var from = gdal.SpatialReference.fromEPSG(3857); | |
+ var to = gdal.SpatialReference.fromEPSG(4326); | |
+ | |
+ var ct = new gdal.CoordinateTransformation(from, to); | |
for (var i = 0; i < layers; i++) { | |
var layer = shp.layers.get(i) | |
var features = layer.features.count(); | |
for (var j = 0; j < features; j++) { | |
var feature = layer.features.get(j); | |
- var geom = feature.getGeometry().toJSON(); | |
+ var geom = feature.getGeometry();; | |
var fields = feature.fields.toJSON(); | |
- var featStr = '{"type": "Feature", "properties": ' + JSON.stringify(fields) + ',"geometry": ' + geom + '}'; | |
+ geom.transform(ct); | |
+ var geojson = geom.toJSON(); | |
+ var featStr = '{"type": "Feature", "properties": ' + JSON.stringify(fields) + ',"geometry": ' + geojson + '}'; | |
if (started) featStr = ',\n' + featStr; | |
started = true; | |
outStream.push(featStr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment