R/import.shape.R

Defines functions import.shape

Documented in import.shape

import.shape <-
function(filename, path=NULL, species.col, ID.col, area.col, dispersal, class.landscape=FALSE)
  {
    pathfile <- paste(path, filename,sep="")
    #sf <- readShapePoly(pathfile)
    sf <- terra::vect(pathfile)#NEW
    #df1 <- sf@data
    df1 <- as.data.frame(sf)#NEW
    #ctr <- gCentroid(sf, byid=TRUE)
    ctr <- terra::centroids(sf)
    ctr<-as.data.frame(terra::crds(ctr))#NEW
    ID <- df1[, ID.col]
    area <- df1[, area.col]
    if(is.character(species.col)) species <- df1[, species.col]
    if(is.character(species.col)) df3 <- cbind(ID, ctr, area, species)
    else df3 <- cbind(ID,ctr,area)
    mapsize <- max(c(max(ctr$x)-min(ctr$x),max(ctr$y)-min(ctr$y)))
    if (class.landscape==FALSE) return(convert.graph(dframe=df3,mapsize,dispersal))
    if (class.landscape==TRUE) return(remove.species(convert.graph(dframe=df3,mapsize,dispersal)))
  }

Try the MetaLandSim package in your browser

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

MetaLandSim documentation built on Jan. 13, 2023, 1:11 a.m.