Using CRS() method on SpatialPointDataFrame to project coordinates

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using CRS() method on SpatialPointDataFrame to project coordinates

Rich Shepard
   I have a SpatialPointsDataFrame with geographic coordinates:

#> str(prcp_sites_ll)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
   ..@ data       :'data.frame': 58 obs. of  3 variables:
   .. ..$ name     : Factor w/ 58 levels "Blazed Alder",..: 1 2 3 4 5 6 7 8 9 10 ...
   .. ..$ elev     : num [1:58] 1112.5 159.1 162.2 45.4 57.3 ...
   .. ..$ mean_prcp: num [1:58] 0.362 0.155 0.16 0.12 0.128 ...
   ..@ coords.nrs : int [1:2] 2 3
   ..@ coords     : num [1:58, 1:2] -122 -122 -122 -123 -123 ...
   .. ..- attr(*, "dimnames")=List of 2
   .. .. ..$ : NULL
   .. .. ..$ : chr [1:2] "easting" "northing"
   ..@ bbox       : num [1:2, 1:2] -122.8 45 -121.7 45.5
   .. ..- attr(*, "dimnames")=List of 2
   .. .. ..$ : chr [1:2] "easting" "northing"
   .. .. ..$ : chr [1:2] "min" "max"
   ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
   .. .. ..@ projargs: chr NA

and I want to project this using CRS('+init=epsg:2838') to a new SPDF
called prcp_sites_lcc.

   I think the proper syntax would be:

prcp_sites_lcc <- spTransform(prcp_sites_ll,CRS('+init=epsg:2838'))

   Is this correct?

Regards,

Rich

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Using CRS() method on SpatialPointDataFrame to project coordinates

R-sig-geo mailing list
First, it looks like prcp_sites_ll does not have CRS information, because @projargs is NA. You'll need something like

  proj4string(prcp_sites_ll) <- CRS('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0')

That string may have more than is necessary; you could also try

   CRS('+init=epsg:4326')

Otherwise, your spTransform() command looks ok to me.

(have you come across spatialreference.org? I find it useful. Example
   http://spatialreference.org/ref/epsg/wgs-84/
)

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

´╗┐On 9/20/18, 7:29 AM, "R-sig-Geo on behalf of Rich Shepard" <[hidden email] on behalf of [hidden email]> wrote:

       I have a SpatialPointsDataFrame with geographic coordinates:
   
    #> str(prcp_sites_ll)
    Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
       ..@ data       :'data.frame': 58 obs. of  3 variables:
       .. ..$ name     : Factor w/ 58 levels "Blazed Alder",..: 1 2 3 4 5 6 7 8 9 10 ...
       .. ..$ elev     : num [1:58] 1112.5 159.1 162.2 45.4 57.3 ...
       .. ..$ mean_prcp: num [1:58] 0.362 0.155 0.16 0.12 0.128 ...
       ..@ coords.nrs : int [1:2] 2 3
       ..@ coords     : num [1:58, 1:2] -122 -122 -122 -123 -123 ...
       .. ..- attr(*, "dimnames")=List of 2
       .. .. ..$ : NULL
       .. .. ..$ : chr [1:2] "easting" "northing"
       ..@ bbox       : num [1:2, 1:2] -122.8 45 -121.7 45.5
       .. ..- attr(*, "dimnames")=List of 2
       .. .. ..$ : chr [1:2] "easting" "northing"
       .. .. ..$ : chr [1:2] "min" "max"
       ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
       .. .. ..@ projargs: chr NA
   
    and I want to project this using CRS('+init=epsg:2838') to a new SPDF
    called prcp_sites_lcc.
   
       I think the proper syntax would be:
   
    prcp_sites_lcc <- spTransform(prcp_sites_ll,CRS('+init=epsg:2838'))
   
       Is this correct?
   
    Regards,
   
    Rich
   
    _______________________________________________
    R-sig-Geo mailing list
    [hidden email]
    https://stat.ethz.ch/mailman/listinfo/r-sig-geo
   

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Using CRS() method on SpatialPointDataFrame to project coordinates

Rich Shepard
On Thu, 20 Sep 2018, MacQueen, Don wrote:

> First, it looks like prcp_sites_ll does not have CRS information, because
> @projargs is NA.

Don,

   I used coordinates(prcp_sites_ll) <- c('easting','northing') to transform
the original dataframe to a SpatialPointsDataFrame and thought that because lat-lon
was not projected the @projards=NA was expected. Now I have learned that ...

> You'll need something like
>  proj4string(prcp_sites_ll) <- CRS('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0')
or
>   CRS('+init=epsg:4326')

   I missed this step in my readings.

> Otherwise, your spTransform() command looks ok to me.

   Good to know.

> (have you come across spatialreference.org? I find it useful. Example
>   http://spatialreference.org/ref/epsg/wgs-84/)

   Yes. I frequently use that when working in GRASS since multiple agency
sources use different, and frequently undocumented, projectons on their
shapefiles.

Many thanks,

Rich

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo