AdehabitatHR R package issue with Writing Shape Files

549 views
Skip to first unread message

Kyle Shaney

unread,
Nov 8, 2016, 3:47:36 PM11/8/16
to GIS In Ecology Forum

Hi All,

I am trying to export a shapefile of a minimum convex polygon, but I receive the following error message:


Error: is(x, "SpatialPolygonsDataFrame") is not TRUE


I was able to successfully get my minimum convex polygon and plot it in R using the following code: 


PID208 <- read.csv(file="PID208.csv", header = TRUE, sep = ",")

head(PID208)


    Name      X       Y        X1       Y2 sex age        Receive.Time
1 PID208 391734 6744220 -148.9906 60.81855   2   3 2015.06.18 21:12:20
2 PID208 391738 6744219 -148.9905 60.81855   2   3 2015.06.18 22:50:30
3 PID208 391739 6744229 -148.9905 60.81864   2   3 2015.06.04 20:41:52
4 PID208 391748 6744229 -148.9904 60.81864   2   3 2015.06.04 20:44:27
5 PID208 391748 6744229 -148.9904 60.81864   2   3 2015.06.04 20:44:27
6 PID208 391743 6744229 -148.9904 60.81864   2   3 2015.06.04 22:07:07​


xy<- SpatialPoints(PID208 [2:3]) 
mcp(xy, percent=95)
mcp(xy, percent=95)$area 
plot(mcp(xy,percent=100))


Anybody know what I might be missing to successfully export the file for use in GIS?

Thanks!

Kyle

Thanks!

Kyle

Kyle Shaney

unread,
Nov 9, 2016, 2:46:05 PM11/9/16
to GIS In Ecology Forum
Sorry, I used the following command at the end to try and export the shape file:

writePointsShape(mcp,"208mcp.shp")

Nick van Doormaal

unread,
Nov 9, 2016, 2:46:45 PM11/9/16
to gis-in-eco...@googlegroups.com
Hi Kyle,

I think you have to save the mcp as an object first before exporting it. Also make sure to load the rgdal-package (in case you haven't)

library(rgdal)

xy<- SpatialPoints(PID208 [2:3]) 
xy.mcp <-  mcp(xy, percent=95)

writeOGR(xy.mcp, dsn = '.', layer = 'xy.mcp', driver = "ESRI Shapefile")

This will save the shapefile in the current working directory. Does this work for you?

Cheers,
Nick



--
-- ======================================================================
You received this message because you are subscribed to the "GIS In Ecology Forum" discussion group (http://www.gisinecology.com/GIS_in_Ecology_forum.htm).
 
To control how often you get emails from this group, go to http://groups.google.com/group/gis-in-ecology-forum/subscribe (you will need to log on to get to this page).
 
To post to this group, either log onto the group's home page or send an email to
gis-in-ecology-forum@googlegroups.com.
 
The rules for posting to this group can be found here: http://groups.google.com/group/gis-in-ecology-forum/browse_thread/thread/df31a0822742203f#.
 
To unsubscribe from this group, email:
gis-in-ecology-forum+unsub...@googlegroups.com
 
All information on this forum is provided on an 'as is' basis. GIS In Ecology is not responsible for checking the accuracy or suitability of any posting or response.
======================================================================
---
You received this message because you are subscribed to the Google Groups "GIS In Ecology Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gis-in-ecology-forum+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nick van Doormaal

unread,
Nov 12, 2016, 5:02:15 AM11/12/16
to gis-in-eco...@googlegroups.com
try writePolyShape(mcp, "208mcp.shp")

Cheers,
Nick

--

Jeffrey Evans

unread,
Nov 18, 2016, 5:58:06 AM11/18/16
to GIS In Ecology Forum
The issue is that "xy" is a SpatialPoints object and not SpatialPointsDataFrame, meaning that there are no associated attributes. An easy fix is to just coerce it to the correct object with a dummy attribute (eg., sequential ID's).

 xy <- SpatialPointsDataFrame(xy, data.frame(ID=1:length(xy))

The "xy" object is now a SpatialPointsDataFrame and you can use rgdal::writeOGR to write to a shapefile. Using rgdal retains projection information so, is preferable to using maptools. 

Best,
Jeff

Jeffrey S. Evans, PhD., | Senior Landscape Ecologist 

The Nature Conservancy | Global Lands Science Team

Affiliate Assistant Professor | Zoology & Physiology | University of Wyoming

Laramie, WY | jeffre...@tnc.org | (970) 672-6766

Reply all
Reply to author
Forward
0 new messages