R/Directed.r

Defines functions Directed

Documented in Directed

# edgelist: result from reading a shp file, the list of edges
# direction.v: a binary vector to specify if an edge is directed or bidirected, 1 means directed, 0 otherwise
Directed<-function(edgelist, direction.v=rep(0,length(edgelist[,1])), eadf=NULL)
{
   newElist<-c()
   ne<-length(edgelist[,1])
   newEID<-0
   neweadf<-c()
   if(!is.null(eadf))
   {
      anames<-names(eadf)
   }
   for (i in 1:ne)
   {
     if (direction.v[i]==0)
     {
       newEID=newEID+1
       edge<-c(newEID, edgelist[i,2],edgelist[i,3])
       newElist<-rbind(newElist, edge) 
       neweadfi<-eadf[i,]
       neweadf<-rbind(neweadf, neweadfi)
       newEID=newEID+1
       edge<-c(newEID, edgelist[i,3],edgelist[i,2])
       newElist<-rbind(newElist, edge)
       neweadf<-rbind(neweadf, neweadfi)
     }
     else
     {
       newEID=newEID+1
       edge<-c(newEID, edgelist[i,2],edgelist[i,3])
       newElist<-rbind(newElist, edge)
       neweadfi<-eadf[i,]
       neweadf<-rbind(neweadf, neweadfi)  
     }
   }
   if(!is.null(eadf))
   {
      neweadf<-data.frame(neweadf) 
      neweadf<-cbind(newElist[,1],neweadf)
      names(neweadf)<-c("NEdgeID", anames)
   }
   rownames(neweadf)<-NULL
   rownames(newElist)<-NULL
   res<-list(newElist, neweadf)
   res 
}

Try the shp2graph package in your browser

Any scripts or data that you put into this service are public.

shp2graph documentation built on May 1, 2019, 9:45 p.m.