Closed michaelvaneck closed 7 years ago
yes you can pass it an array buffer
I continued working on it but even when giving it an ArrayBuffer it somehow doesn't work?
(file is just a .shp file OR a .zip with everything in it)
function readFile(file) {
$log.info('mapcontroller: reading File...');
$log.info('mapcontroller: Filetype: ' + file.type);
$log.info(file);
var reader = new FileReader();
var byteArray = undefined;
reader.onload = function (e) {
byteArray = e.target.result;
$log.info('mapcontroller: creating ArrayBuffer');
$log.info(byteArray);
}
reader.onerror = function (event) {
console.error("File could not be read! Code " + event.target.error.code);
};
//reader.readAsText(file);
reader.readAsArrayBuffer(file);
shp(byteArray).then(function (floep) {
$log.info(floep);
});
}
Add a .catch(onErrFn) to the end of the promise chain (after the .then()) to see any errors that are thrown.
On Mon, Oct 5, 2015, 5:53 AM Michael van Eck notifications@github.com wrote:
I continued working on it but even when giving it an ArrayBuffer it somehow doesn't work?
function readFile(file) { $log.info('mapcontroller: reading File...'); $log.info('mapcontroller: Filetype: ' + file.type); $log.info(file);
var reader = new FileReader(); var byteArray = undefined; reader.onload = function (e) { byteArray = e.target.result; $log.info('mapcontroller: creating ArrayBuffer'); $log.info(byteArray); } reader.onerror = function (event) { console.error("File could not be read! Code " + event.target.error.code); }; //reader.readAsText(file); reader.readAsArrayBuffer(file); shp(byteArray).then(function (floep) { $log.info(floep); }); }
— Reply to this email directly or view it on GitHub https://github.com/calvinmetcalf/shapefile-js/issues/48#issuecomment-145484007 .
Got it working, thx for the fast responses!!
@michaelvaneck @calvinmetcalf What is the fix for this ? I am having the same issue. I want to convert the shp file read by arraybuffer to geojson. The .zip works fine, but not the .shp. Any idea ?
by default you can only do .zip locally and .shp from remote urls
Is there no way to do .shp locally using shapefile-js ?
yeah you need to call shp.combine([shp.parseShp(shpArrayBuffer, projString), shp.parseDbf(dbfArrayBuffer)])
so to break that down, shp.parseShp takes an array buffer corresponding to the .shp file and an optional string corisponding to the .prj file, then shp.parseDbf take an array buffer corresponding to the .dbf file and the shp.combine takes an array of the results of those 2 functions.
So is there any way how to use this with local files? I'm using AngularJS with File API to upload my files. I'd rather process it locally then upload it to my server, return the path and then process it.
or maybe use dataUrl?