mapbox / csv2geojson

magically convert csv files to geojson files
http://mapbox.github.io/csv2geojson/
MIT License
362 stars 82 forks source link

bugs in numeric-fields feature #65

Closed heng2j closed 6 years ago

heng2j commented 6 years ago

Hi team,

I am wondering how we can use the numeric-fields option? currently when running csv2geojson on command line with out any option, all of the fields have converted into String Type. I am wondering how to convert certain fields into numeric type? like Int?

Is it something like this csv2geojson --numeric-fields [“Full_Value”,”Year”]

Thank you, Heng

heng2j commented 6 years ago

I see this recent update is not publish on npm yet. May I know when is this update is going to be publish on npm?

https://www.npmjs.com/package/csv2geojson

andrewharvey commented 6 years ago

@heng2j In the meantime you can always install from github gh-pages branch (which is the master branch) https://stackoverflow.com/questions/39732397/install-specific-branch-from-github-using-npm#39732501

heng2j commented 6 years ago

Hi @andrewharvey,

Thank you for your reply. I have used the following command for npm install and it installed successfully.

sudo npm install -g git://github.com/mapbox/csv2geojson.git#v1 --save /usr/local/bin/csv2geojson -> /usr/local/lib/node_modules/csv2geojson/csv2geojson

I spot that there may be a missing comma between line 27 and 28 on the csv2geojson/csv2geojson, that may caused the following error when I tired to run?

Here are the error messages I see.

172-16-22-150:data heng2j$ csv2geojson --numeric-fields ["Full_Value","Year"] BROOKLYN_For_Viz_Full.csv usage: csv2geojson FILE.csv 172-16-22-150:data heng2j$ csv2geojson BROOKLYN_For_Viz_Full.csv /usr/local/lib/node_modules/csv2geojson/csv2geojson:4 require('sys').puts(JSON.stringify(require('./index')(require('fs').readFileSync(process.argv[2], 'utf8')), null, 2)); ^

TypeError: require(...) is not a function at Object. (/usr/local/lib/node_modules/csv2geojson/csv2geojson:4:54) at Module._compile (module.js:662:30) at Object.Module._extensions..js (module.js:673:10) at Module.load (module.js:575:32) at tryModuleLoad (module.js:515:12) at Function.Module._load (module.js:507:3) at Function.Module.runMain (module.js:703:10) at startup (bootstrap_node.js:193:16) at bootstrap_node.js:665:3

andrewharvey commented 6 years ago

You're installing the v1 branch which was last updated 5 years ago. You'll want to install the main branch which in this repo is gh-pages https://github.com/mapbox/csv2geojson/branches

andrewharvey commented 6 years ago

I've done a new release here in github, but we still need someone from @mapbox to publish it on npm. In the meantime you can still install straight from github.

heng2j commented 6 years ago

Hi @andrewharvey,

Thank you for the quick response. I have used this command for npm install sudo npm install -g git://github.com/mapbox/csv2geojson.git --save

And I also fixed the missing comma on line 27 that. I think you may need to fix that on the repo if that is really the problem for the following error?

/usr/local/lib/node_modules/csv2geojson/csv2geojson:28 nemericFields: argv['numeric-fields'] ^^^^^^^^^^^^^

SyntaxError: Unexpected identifier at new Script (vm.js:51:7) at createScript (vm.js:138:10) at Object.runInThisContext (vm.js:199:10) at Module._compile (module.js:626:28) at Object.Module._extensions..js (module.js:673:10) at Module.load (module.js:575:32) at tryModuleLoad (module.js:515:12) at Function.Module._load (module.js:507:3) at Function.Module.runMain (module.js:703:10) at startup (bootstrap_node.js:193:16)

However when I run the following command to convert my data, the fields "Zip" and "Year" are still String instead of integers

csv2geojson --numeric-fields ["Zip","Year"] data.csv > data.geojson

andrewharvey commented 6 years ago

Thanks @heng2j, gosh I had so many things broken in #64, fixes proposed in #67.



~~~Or if you want to go ahead and use it you could install it with npm install -g git://github.com/mapbox/csv2geojson.git#fix-bin-syntax-error~~~

I've merged the PR so it should be in the gh-pages branch now. Would you mind testing that out, if all good now we can close this issue. Then fix the unit tests, then do a new patch release.
heng2j commented 6 years ago

Hi @andrewharvey , sorry I was away earlier. And I just checked the syntax bug is fixed. However, the numeric-fileds feature is still has no effects

This is the command I used: csv2geojson --numeric-fields ["Full_Value","Year"] data.csv > data.geojson

andrewharvey commented 6 years ago

--help says "comma separated list of fields to convert to numbers" so it'll be:

csv2geojson --numeric-fields "Full_Value,Year" data.csv > data.geojson
andrewharvey commented 6 years ago

I think it makes sense for the cli program to use comma separated values like ogr2ogr's -select, but thinking more, maybe the node library should take an array and the cli program should be converting that string to an array, rather than it taking place in the library...

heng2j commented 6 years ago

Hi @andrewharvey,

Thank you for the example! It is working perfectly as expected! Greatly appreciate for your help!

Thank you, Heng