|
1 | 1 | var fs = require('fs');
|
2 |
| -var jsonfile = require('jsonfile'); |
3 |
| -var readline = require('readline'); |
| 2 | +var jsonfile = require('jsonfile'); |
| 3 | +var readline = require('readline'); |
4 | 4 |
|
5 | 5 | var file = './cities.json';
|
6 |
| -var cities = [], i = 0, city; |
| 6 | +var cities = [], |
| 7 | + i = 0, |
| 8 | + city; |
7 | 9 |
|
8 |
| -readline.createInterface({ |
9 |
| - input: fs.createReadStream('./cities1000.txt'), |
10 |
| - output: process.stdout, |
11 |
| - terminal: false |
12 |
| -}).on('line', function(line) { |
13 |
| - city = line.split("\t"); |
14 |
| - if (i !== 0) { |
15 |
| - // geonameid : integer id of record in geonames database |
16 |
| - // name : name of geographical point (utf8) varchar(200) |
17 |
| - // asciiname : name of geographical point in plain ascii characters, varchar(200) |
18 |
| - // alternatenames : alternatenames, comma separated, ascii names automatically transliterated, convenience attribute from alternatename table, varchar(10000) |
19 |
| - // latitude : latitude in decimal degrees (wgs84) |
20 |
| - // longitude : longitude in decimal degrees (wgs84) |
21 |
| - // feature class : see http://www.geonames.org/export/codes.html, char(1) |
22 |
| - // feature code : see http://www.geonames.org/export/codes.html, varchar(10) |
23 |
| - // country code : ISO-3166 2-letter country code, 2 characters |
24 |
| - // cc2 : alternate country codes, comma separated, ISO-3166 2-letter country code, 200 characters |
25 |
| - // admin1 code : fipscode (subject to change to iso code), see exceptions below, see file admin1Codes.txt for display names of this code; varchar(20) |
26 |
| - // admin2 code : code for the second administrative division, a county in the US, see file admin2Codes.txt; varchar(80) |
27 |
| - // admin3 code : code for third level administrative division, varchar(20) |
28 |
| - // admin4 code : code for fourth level administrative division, varchar(20) |
29 |
| - // population : bigint (8 byte int) |
30 |
| - // elevation : in meters, integer |
31 |
| - // dem : digital elevation model, srtm3 or gtopo30, average elevation of 3''x3'' (ca 90mx90m) or 30''x30'' (ca 900mx900m) area in meters, integer. srtm processed by cgiar/ciat. |
32 |
| - // timezone : the iana timezone id (see file timeZone.txt) varchar(40) |
33 |
| - // modification date : date of last modification in yyyy-MM-dd format |
34 |
| - cities.push({ |
35 |
| - country: city[8], |
36 |
| - name: city[1].replace('"', '').replace('"', ''), |
37 |
| - lat: city[4], |
38 |
| - lng: city[5] |
39 |
| - }); |
40 |
| - } |
41 |
| - i++; |
42 |
| -}).on('close', function() { |
43 |
| - jsonfile.writeFile(file, cities, {spaces: 2}, function (err) { |
44 |
| - if (err) { |
45 |
| - console.error(err) |
| 10 | +readline |
| 11 | + .createInterface({ |
| 12 | + input: fs.createReadStream('./cities1000.txt'), |
| 13 | + output: process.stdout, |
| 14 | + terminal: false, |
| 15 | + }) |
| 16 | + .on('line', function (line) { |
| 17 | + city = line.split('\t'); |
| 18 | + if (i !== 0) { |
| 19 | + // geonameid : integer id of record in geonames database |
| 20 | + // name : name of geographical point (utf8) varchar(200) |
| 21 | + // asciiname : name of geographical point in plain ascii characters, varchar(200) |
| 22 | + // alternatenames : alternatenames, comma separated, ascii names automatically transliterated, convenience attribute from alternatename table, varchar(10000) |
| 23 | + // latitude : latitude in decimal degrees (wgs84) |
| 24 | + // longitude : longitude in decimal degrees (wgs84) |
| 25 | + // feature class : see http://www.geonames.org/export/codes.html, char(1) |
| 26 | + // feature code : see http://www.geonames.org/export/codes.html, varchar(10) |
| 27 | + // country code : ISO-3166 2-letter country code, 2 characters |
| 28 | + // cc2 : alternate country codes, comma separated, ISO-3166 2-letter country code, 200 characters |
| 29 | + // admin1 code : fipscode (subject to change to iso code), see exceptions below, see file admin1Codes.txt for display names of this code; varchar(20) |
| 30 | + // admin2 code : code for the second administrative division, a county in the US, see file admin2Codes.txt; varchar(80) |
| 31 | + // admin3 code : code for third level administrative division, varchar(20) |
| 32 | + // admin4 code : code for fourth level administrative division, varchar(20) |
| 33 | + // population : bigint (8 byte int) |
| 34 | + // elevation : in meters, integer |
| 35 | + // dem : digital elevation model, srtm3 or gtopo30, average elevation of 3''x3'' (ca 90mx90m) or 30''x30'' (ca 900mx900m) area in meters, integer. srtm processed by cgiar/ciat. |
| 36 | + // timezone : the iana timezone id (see file timeZone.txt) varchar(40) |
| 37 | + // modification date : date of last modification in yyyy-MM-dd format |
| 38 | + cities.push({ |
| 39 | + country: city[8], |
| 40 | + name: city[1].replace('"', '').replace('"', ''), |
| 41 | + lat: city[4], |
| 42 | + lng: city[5], |
| 43 | + }); |
46 | 44 | }
|
| 45 | + i++; |
47 | 46 | })
|
48 |
| -}); |
| 47 | + .on('close', function () { |
| 48 | + jsonfile.writeFile(file, cities, { spaces: 2 }, function (err) { |
| 49 | + if (err) { |
| 50 | + console.error(err); |
| 51 | + } |
| 52 | + }); |
| 53 | + }); |
0 commit comments