3

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:

  1. Put files that are part of the shapefile in the main folder;
  2. Ran in the same folder the npm install shpjs --save command from the terminal (as indicated in the README of the repository);
  3. Created the test.js file as follow:
    var shp = require('shpjs');

    shp("shapefile").then(function(geojson){
        console.log(geojson);
    }).catch( (reason) => {
        console.log('Handle rejected promise ('+reason+') here.');
    });
  1. Ran the 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?

epilurzu
  • 147
  • 8

1 Answers1

1

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!

Ali Bayatpour
  • 348
  • 3
  • 8