calvinmetcalf / shapefile-js

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

nodebuffer is not supported by this platform #198

Closed immanewel closed 9 months ago

immanewel commented 10 months ago

I am getting the above error when trying to read an uploaded shapefile in an angular project,

onFileSelected(event: Event) { const inputElement = event.target as HTMLInputElement; const file = inputElement?.files?.[0];

const fileReaderJson: FileReader = new FileReader();
if (!file) return;

fileReaderJson.onloadend = (x) => {
  parseZip(x?.target?.result as ArrayBuffer)
    .then((geojson) => {
      alert(geojson);
    })
    .catch((err) => alert(err));
};
fileReaderJson.readAsArrayBuffer(file);

}

the complete source code at the codesandbox url

https://codesandbox.io/p/sandbox/angular-shapefile-reading-s8d4qh?file=%2Fsrc%2Fapp%2Fapp.component.ts%3A11%2C11-11%2C15

antoniovlx commented 10 months ago

Adding to polyfills.ts solved the issue:

global.Buffer = global.Buffer || require('buffer').Buffer;

immanewel commented 9 months ago

Thanks, I had to use combine, parseDbf, parseShp to achieve this.