[R-sig-Geo] rbind of SpatialPolygonDataFrame objects is different with or without rgdal package

MacQueen, Don macqueen1 at llnl.gov
Mon Oct 10 20:35:14 CEST 2011


It appears that when I rbind() a pair of SpatialPolygonDataFrame objects
when the rgdal package has been loaded the resulting projection string
gets an embedded space character, whereas without rgdal it does not. The
space character breaks further use of rbind(). I don't think it matters
which one is first in the search path (I've tried it both ways).



Here's an example.

I have three simple spatial polygon data frame objects; each consists of a
single polygon. They have the same projection. I can send them as an
attachment if requested.

## in a new R session (objects created in an earlier session):

> require(sp)
Loading required package: sp

> proj4string(ex1.sp) == proj4string(ex2.sp)
[1] TRUE

> proj4string(ex1.sp) == proj4string(ex3.sp)
[1] TRUE

> tmp1 <- rbind(ex1.sp, spChFIDs(ex2.sp,'ex2'))

> proj4string(ex1.sp) == proj4string(tmp1)
[1] TRUE

> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] sp_0.9-88

loaded via a namespace (and not attached):
[1] grid_2.13.1     lattice_0.19-30


> require(rgdal)
Loading required package: rgdal
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.8.0, released 2011/01/12
Path to GDAL shared files:
/Library/Frameworks/R.framework/Versions/2.13/Resources/library/rgdal/gdal
Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009, [PJ_VERSION: 470]
Path to PROJ.4 shared files:
/Library/Frameworks/R.framework/Versions/2.13/Resources/library/rgdal/proj



> tmp2 <- rbind(ex1.sp, spChFIDs(ex2.sp,'ex2'))

> proj4string(ex1.sp) == proj4string(tmp2)
[1] FALSE

> proj4string(ex1.sp)
[1] "+proj=lcc +lat_1=38.43333333333333 +lat_2=37.06666666666667
+lat_0=36.5 +lon_0=-120.5 +x_0=2000000.0001016 +y_0=500000.0001016001
+ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs"

## note the leading space character
> proj4string(tmp2)
[1] " +proj=lcc +lat_1=38.43333333333333 +lat_2=37.06666666666667
+lat_0=36.5 +lon_0=-120.5 +x_0=2000000.0001016 +y_0=500000.0001016001
+ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs
+towgs84=0,0,0"

> tmp3 <- rbind(tmp2, spChFIDs(ex3.sp,'ex3'))
Error in checkCRSequal(dots) : coordinate reference systems differ


> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rgdal_0.7-1 sp_0.9-88

loaded via a namespace (and not attached):
[1] grid_2.13.1     lattice_0.19-30
> 



> str(ex1.sp)
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
  ..@ data       :'data.frame': 1 obs. of  1 variable:
  .. ..$ name: Factor w/ 1 level "example1": 1
  ..@ polygons   :List of 1
  .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
  .. .. .. ..@ Polygons :List of 1
  .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
  .. .. .. .. .. .. ..@ labpt  : num [1:2] 6223669 2081123
  .. .. .. .. .. .. ..@ area   : num 20287432
  .. .. .. .. .. .. ..@ hole   : logi FALSE
  .. .. .. .. .. .. ..@ ringDir: int 1
  .. .. .. .. .. .. ..@ coords : num [1:8, 1:2] 6221449 6226373 6225988
6223664 6223594 ...
  .. .. .. ..@ plotOrder: int 1
  .. .. .. ..@ labpt    : num [1:2] 6223669 2081123
  .. .. .. ..@ ID       : chr "1"
  .. .. .. ..@ area     : num 20287432
  ..@ plotOrder  : int 1
  ..@ bbox       : num [1:2, 1:2] 6220680 2078695 6226373 2083511
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "x" "y"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
  .. .. ..@ projargs: chr "+proj=lcc +lat_1=38.43333333333333
+lat_2=37.06666666666667 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000.0001016
+y_0=500000.00010160"| __truncated__





-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062



More information about the R-sig-Geo mailing list