Hi David,
Could the problem be that the function locoh.a does not actually create a single convex hull, but a multitude. So you have to select the locoh with the percentage you want by looking at
as.data.frame(locoh)
This will give you a long list, and you select the row which comes closest to your preferred percentage value, e.g., 90% or 95%. And when you plot, you need to specify that row.
I just tried with my own data, and it worked, using spplot.
library(maptools)
library(adehabitatHS)
library(mapproj)
library(rgdal)
library(rgeos)
minX<-min(Helen_sp$X)
maxX<-max(Helen_sp$X)
minY<-min(Helen_sp$Y)
maxY<-max(Helen_sp$Y)
dista<-sqrt(((maxX-minX)^2)+((maxY-minY)^2))
dista # should be an approximation of a for LoCoH
habitat <- readShapeSpatial("clean")
proj4string(habitat) <- CRS("+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs")
nn_a <- LoCoH.a(Helen_sp, a=401, unin="m", unout="ha")
plot(nn_a, border=NA)
as.data.frame(nn_a) # line 115 is the first with >90% (91.5)
# The area is given as 17204. Since unout is set to "ha" this cannot be true (should be about 1.7 ha).
# To get just the locations and the locoh:
plot(Helen_sp, pch=16, col="blue")
plot(nn_a[115,], border="red", add=T) # 91.5%
# To plot on my map
code<-c("orange", "pink", "lightblue", "blue", "green3", "green", "darkseagreen", "grey", "darkgreen") # a list of suitable colours for the map
spplot(habitat, zcol="HABITAT", col.regions=code, sp.layout=list("sp.polygons", nn_a[115,], lwd=4, col="green"))
Hope this helps,
Muchos saludos,
Maren
Maren Huck
Dep. of Biological and Forensic Sciences
University of Derby
Kedleston Road
Derby DE22 1GB
U.K.
Tel: +44-(0)1332-59 2354
-----Original Message-----
From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of David Villalobos
Sent: 30 October 2013 16:42
To: Manuel Sp?nola
Cc: r-sig-geo at r-project.org
Subject: [POSSIBLE SPAM] Re: [R-sig-Geo] Problems with the Spatial Reference of a shapefile created with writePolyShape
Hi Manuel
Thank you, I tryed your solution and it works partially
xysp <- SpatialPoints(xy)
proj4string(xysp) <- CRS("+proj=tmerc +lon_0=-84 +lat_0=0 +x_0=500000
+k=0.9999 +datum=WGS84")
Object of class SpatialPolygonsDataFrame
Coordinates:
min max
x 815048.9 815365.8
y 1152113.3 1152759.5
Is projected: TRUE
proj4string :
[+proj=tmerc +lon_0=-84 +lat_0=0 +x_0=500000 +k=0.9999 +datum=WGS84] Data attributes:
area percent
Min. : 789.5 Min. : 54.17
1st Qu.: 789.5 1st Qu.: 54.17
Median : 834.9 Median : 60.83
Mean : 6311.2 Mean : 69.13
3rd Qu.: 8263.5 3rd Qu.: 85.83
Max. :31699.1 Max. :100.00
BUT, when I create the shapefile > writePolyShape(locoh, "Locohraul") the same problem appear in AarGis 10.0: "UnKnown Spatial Reference: object missing spatial reference information, this can be drawn, but can't be projected."
Then, the object is draw, but not projected. The map of my study area and the shapefile of my LoCoH.a analysis doesn't match.
Any idea? Thank you
2013/10/30 Manuel Sp?nola <mspinola10 at gmail.com>
Hi David,
You don?t have the CRS.
Try this:
proj4string(xysp) <- CRS("+proj=tmerc +lon_0=-84 +lat_0=0 +x_0=500000
+k=0.9999 +datum=WGS84")
Best,
Manuel Sp?nola
2013/10/30 David Villalobos <avi3187 at gmail.com>
Dear list,
Maybe a silly problem, but I need help to solve it.
At this moment I am working with the R package "adehabitatHR",
specifically with the LoCoH.a (Adaptative LoCoh). I am calculating
the home range of a neotropical bat (Ectophylla alba:
Phyllostomidae). My commands are the followings:
xy<-read.table("clipboard", header=T)
head(xy)
X Y
1 815802.7 1151723
2 815816.2 1151717
3 815816.1 1151811
4 816053.5 1151723
5 816027.1 1151698
6 816096.1 1151687
xysp
SpatialPoints:
X Y
[1,] 815802.7 1151723
[2,] 815816.2 1151717
[3,] 815816.1 1151811
[4,] 816053.5 1151723
[5,] 816027.1 1151698.........
Coordinate Reference System (CRS) arguments: NA
locoh<- LoCoH.a(xysp, a=1419,
unin=c("m"),unout=c("ha"),duplicates=c("random"),amount=NULL)
plot(locoh)
plot(xysp,add=T)
locohhr<- MCHu2hrsize(locoh, percent=seq(10, 100, by=5))
locohhr
df
10 2935.613
15 2935.613
20 2935.613
25 2935.613........
At this point everything right, and now my purpose is to create a
"shapefile" using the object "locoh" (Class =
SpatialPolygonsDataFrame) with this command:
writePolyShape(locohhr, "LocohI")
Here, the real problem: I want to use the shapefile created on a map
of my study area (in Costa Rica). I have the map in the local
Projected Coordinate System:
Projected Coordinate System: Proyeccion_CRTM05
Projection: Transverse_Mercator
False_Easting: 500000.00000000
False_Northing: 0.00000000
Central_Meridian: -84.00000000
Scale_Factor: 0.99990000
Latitude_Of_Origin: 0.00000000
Linear Unit: Meter
Geographic Coordinate System: GCS_WGS_1984
Datum: D_WGS_1984
Prime Meridian: Greenwich
Angular Unit: Degree
The first step is to read the shapefile in ArcMap 10. When I try to
read the shapefile of my LoCoH.a analysis, I can't do it good because
the following message appear: "UnKnown Spatial Reference: object
missing spatial reference information, this can be drawn, but can't
be projected."
Then, the object is draw, but not projected. The map of my study area
and the shapefile of my LoCoH.a analysis doesn't match.
I want to solve this problem with spatial reference information of my
shapefile(LoCoH.a). I suspect that the way to do it is related with
one part of the command writePolyShape(locoh, "LocohI"), maybe the
part: "proj4string=CRS(as.character(NA)".
Please any help is welcome. I will be very appreciated.
Since now, THANK YOU.
--
Saludos
David Villalobos Chaves
Maestr?a Acad?mica en Biolog?a
Universidad de Costa Rica
[[alternative HTML version deleted]]
--
*Manuel Sp?nola, Ph.D.*
Instituto Internacional en Conservaci?n y Manejo de Vida Silvestre
Universidad Nacional Apartado 1350-3000 Heredia COSTA RICA
mspinola at una.ac.cr mspinola10 at gmail.com
Tel?fono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de
r?o<https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>
Saludos
David Villalobos Chaves
Maestr?a Acad?mica en Biolog?a
Universidad de Costa Rica
[[alternative HTML version deleted]]
_____________________________________________________________________
The University of Derby has a published policy regarding email and reserves the right to monitor email traffic. If you believe this email was sent to you in error, please notify the sender and delete this email. Please direct any concerns to Infosec at derby.ac.uk.