I am trying to export polygons that i have created for home range data but when i go to export them get this error message:
Error in writeOGR(colkud95[1, ], ".", "colonyhomerange", driver = "ESRI Shapefile") :
Spatial Polygons objects should have valid ordering comments
use rgeos::createSPComment()
# main package for this analysis
library(adehabitatHR)
library(sp)
library(rgdal)
tracks.utm <- dput(new("SpatialPointsDataFrame", data = structure(list(TripID = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1), `Breeding stage` = c(1, 1, 1, 1,
1, 1, 1, 1, 1, 1)), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame")), coords.nrs = 1:2, coords = structure(c(174.78327,
174.78326, 174.78332, 174.78323, 174.78325, 174.78277, 174.78238,
174.78238, 174.78244, 174.78278, -41.09482, -41.09491, -41.09484,
-41.09491, -41.09496, -41.09564, -41.09637, -41.09685, -41.09747,
-41.09771), .Dim = c(10L, 2L), .Dimnames = list(NULL, c("x",
"y"))), bbox = structure(c(174.78238, -41.09771, 174.78332, -41.09482
), .Dim = c(2L, 2L), .Dimnames = list(c("x", "y"), c("min", "max"
))), proj4string = new("CRS",
projargs = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs")))
# Organising variable 1 refers to Trip ID
colkud<-kernelUD(tracks.utm[,1],h="href",
grid=1000,same4all=T)
# Organising variable 2 refers to Breeding stage
colkudb<-kernelUD(tracks.utm[,2],h="href",
grid=1000,same4all=T)
kernel.area(colkud,percent=50)
kernel.area(colkudb,percent=50)
kernel.area(colkud,percent=95)
kernel.area(colkudb,percent=95)
colkud95<- getverticeshr(colkud, percent=95)
colkud50<- getverticeshr(colkud, percent=50)
colkud95b<- getverticeshr(colkudb, percent=95)
colkud50b<- getverticeshr(colkudb, percent=50)
# This is where the error occurs
writeOGR(colkud95,".",layer="colkud95",driver="ESRI Shapefile")
I haven't had any luck searching for an answer to this, my aim is to create polygons for home range and then export them as a shapefile to be used in QGIS.
HRtracks
but then switch totracks.utm
which I guess is a transformed version ofHRtracks
? If you can add the transform line and get rid of as many irrelevant lines as possible, ie anything that doesn't contribute to constructingcolkud95
, that would make this a bit cleaner, leaner, and clearer - the fewer lines of code people think they have to run, the more likely they are to help!getverticeshr
and it works, so its more likely to be something dependent on your data.HRtracks
since you never use the object and we do not have access to the data.