calvinmetcalf / shapefile-js

Convert a Shapefile to GeoJSON. Not many caveats.
http://calvinmetcalf.github.io/shapefile-js/
715 stars 228 forks source link

Can't run the example promise #128

Closed epilurzu closed 2 years ago

epilurzu commented 4 years ago

I apologize in advance; I'm a novice when it comes to js, so I could be making trivial mistakes.

I have done this steps:

  1. Put some shapefile files in my main folder;
  2. Ran in the same folder the npm install shpjs --save command from the terminal;
  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.

I tried to look for the meaning of this error message, but I didn't understand how to handle it.

calvinmetcalf commented 4 years ago

by default it tries to load the file over http, and it apparently interprets "shapefile" as "http://localhost:80/shapefile" so you should either spin up a server to host it (and then point to the correct port as you probably don't want to run it as root, so something like shp("http://localhost:5000/shapefile") if you were to run a local sever with npx serve or you could zip it and load the zipfile from the filesystem with the node fs module and just pass in the buffer.

epilurzu commented 4 years ago

I ran a local server using npx server as you suggested, but there are still some issues.

Me too, as in issue #108, I am trying to convert large files (about 1.1 GB the shapefile, 762 MB once zipped).

The terminal printed some information, with this error:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

I found on the internet a way to increase the heap limit up to 8 GB by executing command node --max-old-space-size=8192 .\test.js, but after 20 minutes of computation the terminal still gave me the same output in the end.

Is there a size limit for the shapefile? Is there any difference in giving to the algorithm the zip file or the shapefile?

anonymouskeyboard47 commented 3 years ago

Hi,

I downloaded the entire project and opened the index.html file. No data is showing up on the screen but Leaflet is displayed with the minimize and maximize tools showing.

Is there something else I should install?