Neighbors

We use the solution from 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).

Because of strong relations we added an sea-edge (Faeroe Islands : Danmark).


Back to CIA Europe data

notes/da/eurel.txt · Last modified: 2018/04/08 13:46 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki