You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
215
216
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
218
224
[Active People Survey](http://data.london.gov.uk/datastore/package/active-people-survey-kpi-data-borough).
219
225
The boundary data is from the [Ordnance Survey](http://www.ordnancesurvey.co.uk/oswebsite/opendata/).
220
226
@@ -615,7 +621,7 @@ To reaffirm our starting point, let's re-load the
615
621
```{r, eval=FALSE}
616
622
library(rgdal) # ensure rgdal is loaded
617
623
# Create new object called "lnd" from "london_sport" shapefile
618
-
lnd <- readOGR(dsn = "data", "london_sport")
624
+
lnd <- readOGR("data/london_sport.shp")
619
625
plot(lnd) # plot the lnd object (not shown)
620
626
nrow(lnd) # return the number of rows (not shown)
621
627
```
@@ -826,7 +832,7 @@ with the aim of finding out about how many are found in each London borough.
826
832
```{r, results='hide'}
827
833
library(rgdal)
828
834
# create new stations object using the "lnd-stns" shapefile.
0 commit comments