Error in writeOGR when trying to export spatial polygons as shapefile in R

1.5k Views Asked by At

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()
dput(HRtracks[1:10, ])
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"))

#main package for this analysis
library(adehabitatHR)  
library(sp)
library(readxl)
library(rgdal)

HRtracks<-read_excel("allinterpolatedtracks.xlsx") 
coordinates(HRtracks)<-c("x","y") 
proj4string(HRtracks)<- CRS("+init=epsg:3857")
#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)
colkud95b<- getverticeshr(colkudb, percent=95)
colkud50b<- getverticeshr(colkudb, percent=50)
colkud50<- getverticeshr(colkud, 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.

1

There are 1 best solutions below

0
On

Installing the rgeos package also solved it for me.