Skip to content

Commit 1b901a4

Browse files
committed
Update tutorial text to show that readOGR("f.shp") now works and clarify
1 parent b42052c commit 1b901a4

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

intro-spatial.Rmd

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,19 @@ R to handle a broader range of spatial data formats. If you've not already
208208

209209
```{r, message=FALSE, results='hide'}
210210
library(rgdal)
211-
lnd <- readOGR(dsn = "data", layer = "london_sport")
211+
lnd <- readOGR(dsn = "data/LondonBoroughs.shp")
212+
# lnd <- readOGR(dsn = "data", layer = "london_sport")
212213
```
213214

214-
In the second line of code above the `readOGR` function is used to load a shapefile and assign it to a new spatial object called "lnd"; short for London. `readOGR` is a *function* which accepts two *arguments*: `dsn` which stands for "data source name" and specifies the directory in which the file is stored, and `layer` which specifies the file name (note that there is no need to include the file extention .shp). The *arguments* are separated by a comma and the order in which they are specified is important. You do not have to explicitly type `dsn=` or `layer=` as R knows which order they appear, so `readOGR("data", "london_sport")` would work just as well. For clarity, it is good practice to include argument names when learning new functions so we will continue to do so.
215+
In the second line of code above the `readOGR` function is used to load a shapefile and assign it to a new spatial object called `lnd`, short for London.
215216

216-
The file we assigned to the `lnd` object contains the population of London Boroughs in 2001 and the percentage of the population participating in sporting activities.
217-
This data originates from the
217+
`readOGR` is a *function* of the **rgdal** package, the first *argument* of which `dsn`: "data source name", the file or directory of the geographic data to be loaded.
218+
Thanks to recent developments in **rgdal**, the layer no longer has to be specified (as it is in the 3 line of code which has been *commented
219+
out*).^[The
220+
third line of code is included for historical interest and to provide an opportunity to discuss R functions and their arguments (the values inside a function's brackets) in detail. Note the arguments are separated by a comma. The order in which they are specified is important. You do not have to explicitly type `dsn =` or `layer =` as R knows which order they appear. `readOGR("data", "london_sport")` would work just as well. For clarity, it is good practice to include argument names when learning new functions so we will continue to do so.
221+
]
222+
223+
`lnd` is now an object representing the population of London Boroughs in 2001 and the percentage of the population participating in sporting activities according to the
218224
[Active People Survey](http://data.london.gov.uk/datastore/package/active-people-survey-kpi-data-borough).
219225
The boundary data is from the [Ordnance Survey](http://www.ordnancesurvey.co.uk/oswebsite/opendata/).
220226

@@ -615,7 +621,7 @@ To reaffirm our starting point, let's re-load the
615621
```{r, eval=FALSE}
616622
library(rgdal) # ensure rgdal is loaded
617623
# Create new object called "lnd" from "london_sport" shapefile
618-
lnd <- readOGR(dsn = "data", "london_sport")
624+
lnd <- readOGR("data/london_sport.shp")
619625
plot(lnd) # plot the lnd object (not shown)
620626
nrow(lnd) # return the number of rows (not shown)
621627
```
@@ -826,7 +832,7 @@ with the aim of finding out about how many are found in each London borough.
826832
```{r, results='hide'}
827833
library(rgdal)
828834
# create new stations object using the "lnd-stns" shapefile.
829-
stations <- readOGR(dsn = "data", layer = "lnd-stns")
835+
stations <- readOGR(dsn = "data/lnd-stns.shp")
830836
# stations = read_shape("data/lnd-stns.shp") # from tmap
831837
proj4string(stations) # this is the full geographical detail.
832838
proj4string(lnd) # what's the coordinate reference system (CRS)

0 commit comments

Comments
 (0)