-->

Antipodal error in Great Circles code

2019-07-10 02:25发布

问题:

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.