====== Neighbors ======
We use the solution from [[notes:net:shape]].
Requires package ''spdep''.
> shp2Pajek <- function(pl,file="neighbors.net",name=0){
+ library(spdep); cat("shp2Pajek:",date(),"/"); flush.console()
+ nbr<-poly2nb(pl,queen=FALSE); nbq<-poly2nb(pl,queen=TRUE)
+ n <- length(nbr); L <- card(nbr)
+ xy <- coordinates(pl)
+ IDs <- as.character(if(name>0) pl[[name]] else 1:n)
+ net <- file(file,"w")
+ cat("% shp2Pajek:",date(),"\n*vertices",n,"\n",file=net)
+ for(i in 1:n) cat(i,' "',IDs[i],'" ',xy[i,1],' ',xy[i,2],' 0.5\n',sep='',file=net)
+ cat('*edgeslist :1 "rook"\n',file=net)
+ for(i in 1:n) if(L[i]>0) cat(i,nbr[[i]],"\n",file=net)
+ cat('*edgeslist :2 "queen"\n',file=net)
+ L <- card(nbq)-card(nbr)
+ for(i in 1:n) if(L[i]>0) cat(i,setdiff(nbq[[i]],nbr[[i]]),"\n",file=net)
+ cat(date(),"\n"); close(net)
+ }
> setwd("C:/Users/batagelj/Documents/papers/2018/CRoNoS/shape/Europe")
> library(maptools)
> Eu <- readShapeSpatial("Europe.shp")
> names(Eu)
[1] "NAME" "ORGN_NAME"
> shp2Pajek(Eu,name="NAME",file="Europe0.net")
The neighbors relation obtained from the shape file (black edges) forms a disconnected graph. To make it connected we have to manually add "sea borders" (blue edges). I also noticed that three countries are missing in the network: Cyprus, Vatican and
Kosovo. I added them manually (red edges for Kosovo and Vatican). Adding Kosovo cuts the edge (Serbia : Albania).
{{notes:da:pics:europenet.png}}
Because of strong relations we added an sea-edge (Faeroe Islands : Danmark).
\\
[[notes:da:ciaeu|Back to CIA Europe data]]