movedata=read.csv("/Users/mohsen/aa.csv",TRUE,",") #head(movedata) movedata <- movedata[with(movedata,order(movedata$X20_C_PK,movedata$X7_date_time)),] coordinates(movedata) <- c("lon","lat") proj4string(movedata) <- CRS("+proj=longlat +datum=WGS84") ####3 utm <- spTransform(movedata, CRS("+proj=utm +zone=15 ellps=WGS84")) utm_locs <- data.frame(as(utm, "SpatialPoints")) colnames(utm_locs) <- c("UTM_W", "UTM_N") head(utm_locs) #### date_time <- as.POSIXct(strptime(as.character(movedata$X7_date_time),"%m/%d/%Y %H:%M", tz="GMT")) month<- as.numeric(format(date_time,"%m")) year<-as.numeric(format(date_time, "%Y")) time <- strftime(date_time, format = "%H:%M") ##3 #final_move <- data.frame(ID=as.factor(movedata$X20_C_PK),UTM_W=movedata$X5_Easting, UTM_N= movedata$X6_Northing, month, year,time, timestamp=date_time) final_move <- data.frame(ID=as.factor(movedata$X20_C_PK),UTM_W=utm_locs$UTM_W, UTM_N=utm_locs$UTM_N, month, year,time, timestamp=date_time) head(final_move) coordinates(final_move) <- c("UTM_W","UTM_N") projection(final_move)<- CRS("+proj=utm +zone=15 ellps=WGS84") #####MCP##### ge_hr_mcp <- mcp.area(final_move[,1],percent = 100, unout = c("km2"), plot=F) colnames(ge_hr_mcp) <- c("mcp_114328","mcp_117408") hr_mcp_poly <- mcp(final_move[,1], percent = 100) hr_mcp_latlong <- spTransform(hr_mcp_poly,CRS("+proj=longlat +datum=WGS84")) ge_hr_mcp write.table(ge_hr_mcp,file = "final_mcp100.csv", sep = ",") ######KDE######### x<-seq(min(final_move$UTM_W-1000), max(final_move$UTM_W+1000), by=30) y<-seq(min(final_move$UTM_N-1000), max(final_move$UTM_N+1000), by=30) xy<-expand.grid(x=x, y=y) coordinates(xy) <- ~x+y gridded(xy) <- TRUE ge_hr_kde_UD <- kernelUD(final_move[,1], h="href", grid = xy) ver <- getverticeshr(ge_hr_kde_UD, percent = 90) ver plot(ver) writeOGR(obj = ver, dsn = "moooooh", layer = "kde90_96_C4", driver = "ESRI Shapefile") write.table(ver,file = "kde90_96_C2.csv", sep = ",") ge_hr_kde <- kernel.area(ge_hr_kde_UD, percent = c(50,95), unout = c("km2")) colnames(ge_hr_kde) <- c("kde1", "kde2") hr_kde_poly <- getverticeshr(ge_hr_kde_UD, percent = 50) hr_kde_latlong <- spTransform(hr_kde_poly,CRS("+proj=longlat +datum=WGS84")) data.frame(ge_hr_mcp,ge_hr_kde) #ge_hr_mcp <- mcp.area(movedata[,22],percent = 95, unout = "km2", plot=F ) #mcp1 <- mcp(movedata[,22], percent = 95) write.table(ge_hr_kde,file = "final_kde2.csv", sep = ",") write.table(ge_hr_kde,file = "final_kde2.csv", sep = ",") #mcppoly = mcp(movedata[,22], percent = 95, unin = "m", unout = "m2") #write.table(mcppoly,file = "mcppoly.csv", sep = ",") #movedata[1,1] #plot(movedata[,1])