Created
August 14, 2014 05:57
-
-
Save dz1984/a46c53d03d73a04f740d to your computer and use it in GitHub Desktop.
將臺北市各區 GeoJSON下來,存成 CSV 格式後,手動塞入 Fusion Table。 https://www.google.com/fusiontables/DataSource?docid=1WhhrQFN0vopgc5jJdcC4myMF5C4gsirYO436Snln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require "fs" | |
crypto = require "crypto" | |
http = require "http" | |
NEWLINE = "\n" | |
FILENAME = "output.csv" | |
API = "http://poponfire.herokuapp.com/api/taipei/" | |
ALLAREA = [ | |
"中正區", | |
"大同區", | |
"中山區", | |
"萬華區", | |
"信義區", | |
"松山區", | |
"大安區", | |
"南港區", | |
"北投區", | |
"內湖區", | |
"士林區", | |
"文山區" | |
] | |
ENCODEPROPERTIES = ['鄉鎮', '路段', '段號', '地號','分母', '分子'] | |
NEEDPROPERTIES = ENCODEPROPERTIES.concat ['面積' , '管理者'] | |
ALLAREA.forEach (area,index) -> | |
JsonUrl = API + area | |
http.get JsonUrl, (res, req) -> | |
data = ''; | |
res.on 'data', (chunk) -> | |
data += chunk | |
return | |
res.on 'end', -> | |
geoJson = JSON.parse data | |
features = geoJson.features | |
features.forEach (feature, index) -> | |
row = "" | |
properties = feature.properties | |
# appen properties | |
NEEDPROPERTIES.forEach (property,index) -> | |
row += properties[property] + "\t" | |
return | |
# append the hashid | |
encoding_str = (ENCODEPROPERTIES.map (property) -> | |
properties[property]).join('') | |
console.log encoding_str | |
shasum = crypto.createHash 'sha1' | |
id = shasum.update(encoding_str, 'utf-8').digest('hex') | |
row += id + "\t" | |
# append the feature JSON object | |
row += JSON.stringify(feature) + NEWLINE | |
fs.appendFileSync(FILENAME, row) | |
return | |
return | |
return | |
return | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment