Antipodal error in Great Circles code

瘦欲@ 提交于 2020-01-04 15:30:29

问题


I'm trying to build something like this http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/ but with my own data in csv files. The code runs well if I use the same csv files as the author, but with mine , this is what I get

Code

library(maps) 
library(geosphere) 


map("world") 

xlim <- c(-180.00, 180.00) 

ylim <- c(-90.00, 90.00) 

map("world", col = "#f2f2f2", fill = TRUE, bg = "white", lwd = 0.05,xlim = xlim, ylim = ylim) 

airports <- read.csv("/Users/shabnam/Desktop/airports.csv", as.is=TRUE, header=TRUE) 
flights <- read.csv("/Users/shabnam/Desktop/flights.csv", as.is=TRUE, header=TRUE) 

 pal <- colorRampPalette(c("#545454", "white"))colors <- pal(100) 
map("world", col="#303030", fill=TRUE, bg="black", lwd=0.05, xlim=xlim, ylim=ylim) 


fsub <- flights[flights$airline == "AA",] 


fsub <- fsub[order(fsub$cnt),] 

maxcnt <- max(fsub$cnt) 

for (j in 1:length(fsub$airline)) 
{ 
air1 <- airports[airports$iata == fsub[j,]$airport1,] 

air2 <- airports[airports$iata == fsub[j,]$airport2,] 

inter <- gcIntermediate(c(air1[1,]$long, air1[1,]$lat), c(air2[1,]$long, air2[1,]$lat), n=100, addStartEnd=TRUE) 

colindex <- round( (fsub[j,]$cnt / maxcnt) * length(colors) ) 

lines(inter, col=colors[colindex], lwd=0.8) 
} 


Error in if (antipodal(p1, p2)) { : missing value where TRUE/FALSE needed 

I've tried everything, adding breakAtDateLine, sp and sepNA but to no use.

Would really appreciate any help, this is the first time I'm experimenting with R.

来源:https://stackoverflow.com/questions/13549080/antipodal-error-in-great-circles-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!