I need js code to convert shapefile files to geojson and vice versa, and I'm having trouble to find valid tools.
I found Calvin Metcalf's repository, which should allow me to convert shapefile files to geojson, but I can't run it. Actually, I'm a novice when it comes to js, so I hope I'm making trivial mistakes.
To test it, I have:
npm install shpjs --save command from the terminal (as indicated in the README of the repository); var shp = require('shpjs');
shp("shapefile").then(function(geojson){
console.log(geojson);
}).catch( (reason) => {
console.log('Handle rejected promise ('+reason+') here.');
});
node test.js command from the terminal.This is the output: Handle rejected promise (Error: connect ECONNREFUSED 127.0.0.1:80) here.
So, something is wrong.
I tried to look for the meaning of this error message, but I didn't understand how to handle it.
Have I made some mistakes? If not, are there any other js tools that allow me to perform conversion of these files, maybe in both directions?
EDIT
Calvin Metcalf himself answers the question in issue #128 of the repo, but I'm still having some trouble because the files I'm trying to convert are actually gigantic. So, last question still stands.
Are there any other js tools (or js friendly) that can allow me to perform a conversion from shapefile to geojson and vice versa?
I recommend using ogr2ogr library it worked for me to convert a folder that contains .dbf .shp .shx to a proper geojson object. the library also gives you other functionalities like geojson to shp or shp to KML but I only tried shp to geojson and it worked: https://github.com/wavded/ogr2ogr
hope it helps and good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With