calvinmetcalf / shapefile-js

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

Does this work with just a .shp file that is not in a zip? #171

Open GinoVillalpando opened 2 years ago

GinoVillalpando commented 2 years ago

I have an <input> where a user can upload a file and I noticed whenever you upload just the .shp file then you run into the following error: image

However, using the entire zip folder works fine. Am I misunderstanding the first part in the documentation where you can use this on just the .shp file?

Here is a code snippet of the function that is using shpjs to translate to geojson:

onInputChange(file: File) {
  file.arrayBuffer().then(buffer => {
    shp(buffer).then(geojson => {
       console.log(geojson); 
    })
  })
};
calvinmetcalf commented 2 years ago

the way it's set up doesn't work with just a .shp file because we assume that any binary buffer passed is a zip file, BUT if you call shp.parseShp(shpBuffer) that should just (synchronously) return the geometries as an array.

GinoVillalpando commented 2 years ago

the way it's set up doesn't work with just a .shp file because we assume that any binary buffer passed is a zip file, BUT if you call shp.parseShp(shpBuffer) that should just (synchronously) return the geometries as an array.

Thank you for the response. I should be able to work this :)

mohammadrezaataeii commented 1 year ago

@GinoVillalpando I have the same issue could you fix it?