Skip to content

Commit 934c973

Browse files
committed
spatial_point_pattern: use proj4string<- function rather than the slot *
The use of 'proj4string' in R code is confusing in times where PROJ.4 strings are obsoleted. It can be expected that a more general function name to set an object's CRS will sooner or later be promoted instead of proj4string<-, hence preparing for that already by using the function instead of the slot. I expect the proj4string slot will most probably remain in use for compatibility reasons, but explicitly naming it is better avoided in times where WKT2 strings are actually used to define a CRS.
1 parent 9d11dc3 commit 934c973

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • content/tutorials/spatial_point_pattern

content/tutorials/spatial_point_pattern/index.Rmd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ library(sp)
3737
crs_wgs84 <- CRS(SRS_string = "EPSG:4326")
3838
crs_lambert <- CRS(SRS_string = "EPSG:31370")
3939
coordinates(points) <- ~lon + lat
40-
points@proj4string <- crs_wgs84
40+
# proj4string() - still the only available function to set the CRS - may in the
41+
# future get a more general name:
42+
proj4string(points) <- crs_wgs84
4143
points_lambert <- spTransform(points, crs_lambert)
4244
```
4345

@@ -87,7 +89,7 @@ In order to visualise the result, we have to re-project the coordinates back to
8789

8890
```{r ggmap, fig.cap = "Static image of density"}
8991
coordinates(dens) <- ~lon + lat
90-
dens@proj4string <- crs_lambert
92+
proj4string(dens) <- crs_lambert
9193
dens_wgs <- spTransform(dens, crs_wgs84) %>%
9294
as.data.frame()
9395
ggmap(map) +

0 commit comments

Comments
 (0)