[R-sig-Geo] Problems with the Spatial Reference of a shapefile created with writePolyShape

Roger Bivand Roger.Bivand at nhh.no
Wed Oct 30 19:43:54 CET 2013


On Wed, 30 Oct 2013, David Villalobos wrote:

> 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")
>
>> xysp
> 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
>
>> locoh<- LoCoH.a(xysp, a=657,
> unin=c("m"),unout=c("ha"),duplicates=c("random"),amount=NULL)
>
>> summary(locoh)
> 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."

Never use the shapefile functions in the maptools (or shapefiles) packages 
if you have access to rgdal. In rgdal, writeOGR() for the "ESRI Shapefile" 
driver, the *.prj file is written correctly and will be recognised by 
ArcGIS. The functions in maptools will be withdrawn very soon, this case 
showing that removing them is in everyone's interests. The description of 
maptools will be modified to suit.

Roger

>
> 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]]
>>>
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>>
>>
>>
>> --
>> *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/>
>>
>
>
>
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list