Description Usage Arguments Value Examples
Transforms to different projection by supplying an EPSG code. If object has no proj4string defined, old projection can be specified by argument epsg_old.
EPSG of common projections:
WGS84: 4326
Lambert Austria: 31287
1 | transform_projection(spatial_object, epsg_new, epsg_old = NULL)
|
spatial_object |
an object of class "Spatial". |
epsg_new |
an EPSG code provided as character string indicating the desired projection for the returned object. |
epsg_old |
optional, an EPSG code provided as character string specifying the projection before transformation if no proj4string is supplied with the object. |
an object of class "Spatial".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ## Not run:
#library('sp')
init_dataframe <- data.frame(Y = c(48.6476, 48.6447, 48.6709),
X = c(16.7958, 6.7962, 16.5370),
meta = c('a', 'b', 'c'))
spatpoints <- SpatialPointsDataFrame(init_dataframe[c('X', 'Y')],
init_dataframe['meta'])
## using other_projection():
spatpoints_lambert <- transform_projection(spatial_object, '31287',
epsg_old = '4326')
## using "manual approach":
# specify current projstring as WGS 84
proj4string(spatpoints) <- CRS("+init=epsg:4326")
# creator function for CRS class - set as Lambert-projection Austria
CRS.new <- CRS("+init=epsg:31287")
#transform spatialpointsto new projection
spatpoints_lambert2 <- spTransform(spatpoints, CRS.new)
#they are the same
identical(spatpoints_lambert, spatpoints_lambert2)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.