2016年7月21日 星期四

[R] 用LeafletR 畫鐵軌+火車站

# read rail shape file(ref https://gist-map.motc.gov.tw/Complex/MapTopic)
rail = toGeoJSON(data = "F:/WGS84_2.zip", name = "rail", dest = tempdir())

# change file code page to utf8
writeLines(iconv(readLines(rail), from = "big5", to = "utf8"), file(rail, encoding = "UTF-8"))

# make style based on rail path
rail.sty = styleSingle(col = "blue", lwd = 3, alpha = 0.8)

# read station point file(ref https://gist-map.motc.gov.tw/Complex/MapTopic)
railway_station = read.csv("F:/railway_station.csv", stringsAsFactors=FALSE)
station = toGeoJSON(data = railway_station, dest = tempdir(), name = "station", lat.lon = c("lat","lon"))

# change file code page to utf8
writeLines(iconv(readLines(station), from = "big5", to = "utf8"), file(station, encoding = "UTF-8"))

# make style based on station point
station.sty = styleSingle(fill = "red", fill.alpha = 1, rad = 10)

# create map
map = leaflet(data = list(rail,station), dest=tempdir(), style=list(rail.sty,station.sty), popup = "station")
map



沒有留言:

張貼留言