Skip to content
Prev 19654 / 29559 Next

Problems with the Spatial Reference of a shapefile created with writePolyShape

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")
SpatialPoints:
              X       Y
  [1,] 815196.4 1152758
  [2,] 815196.0 1152759
  [3,] 815055.7 1152120
  [4,] 815055.7 1152120
  [5,] 815056.5 1152122
  [6,] 815061.6 1152131.......

Coordinate Reference System (CRS) arguments: +proj=tmerc +lon_0=-84
+lat_0=0 +x_0=500000 +k=0.9999 +datum=WGS84
unin=c("m"),unout=c("ha"),duplicates=c("random"),amount=NULL)
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>