Closed leonamjlpaula closed 4 years ago
I've never used react native so I don't know how you'd go about getting the file in but assuming you were able to get the file in as an array buffer there shouldn't be anything preventing you from using this library
also it looks like you can just download files just the same as in the browser
Thanks for your answer @calvinmetcalf ! I've use a file read lib for react native and now I can get the base64 string of the shp file and convert it to a arrayBuffer. How then should I use your lib to get a GeoJSON? Could please help me?
I tried to convert a .zip file and got this:
Error: nodebuffer is not supported by this browser
at Object.exports.checkSupport (utils.js:280)
at Object.exports.transformTo (utils.js:242)
at ZipObject.asNodeBuffer (object.js:140)
at unzip.js:10
at Array.forEach (<anonymous>)
at module.exports (unzip.js:8)
at Function.shp.parseZip (index.js:65)
at index.js:138
at tryToUnwrap (browser.js:166)
at tryCatch (browser.js:178)
looks like the unzip library we use doesn't support buffers in react native
But I just need now to convert the shp arrabuffer to GeoJSON. I won't user zip files.
But I just need now to convert the shp arrabuffer to GeoJSON. I won't user zip files.
you could pass just the .shp
to shp.parseShp
I've tried this but there is a prj parameter that expects a Buffer or string. What should I pass as prj?
if you have a .prj file that went with this .shp pass the contents as a string
@calvinmetcalf now it worked! By reading the prj file with ascii was possible to make this work! Thanks a lot for your attention and patience!
Hi again. What parameter should I use to specify a default value for cpg on parseDbf? The result of parseShp is not complete to be plotted, so I guess I should combine (using combine function) with the dbf file. I got this trying to pass a simple string 'utf-8' as ArrayBuffer:
RangeError: Failed to construct 'TextDecoder': The encoding label provided ('[object ArrayBuffer]') is invalid.
Hi again. What parameter should I use to specify a default value for cpg on parseDbf? The result of parseShp is not complete to be plotted, so I guess I should combine (using combine function) with the dbf file. I got this trying to pass a simple string 'utf-8' as ArrayBuffer:
RangeError: Failed to construct 'TextDecoder': The encoding label provided ('[object ArrayBuffer]') is invalid.
I realized that by passing null the lib uses the default decoder. The problem was that I'm using typescript and it complains about null but runs ok. Also the combine function works fine and now I can plot the GeoJSON on a MapBox Layer.
Hi @leonamjlpaula, I'm also trying to make this working in RN. I tried reading the .shp
file with RNFS but that's giving errors. I would really appreciate if you could share how you made this working!
hi @georgetk. I was able to make it work with RN but this was not easy. Send me an email leonamjlpaula@gmail.com and let's schedule a call. I will be glad to present you the solution I found.
Hi. Could you give a me a clue on how to use this lib to convert shp files to GeoJSON in a React Native App?