Skip to content

Commit

Permalink
added vignettes/downloading-data
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Mar 2, 2016
1 parent 258f4fa commit dde623c
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 87 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
^\.travis\.yml$
^makefile$
^vignettes/makefile$
^README\.Rmd$
^README\.md$
^README\.html$
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Title: Customisable Images of OpenStreetMap Data
Version: 0.1-1
Date: 2016-03-01
Authors@R: person("Mark", "Padgham", email = "[email protected]", role = c("aut", "cre"))
Description: Produces customisable images of OpenStreetMap data. Extracts OpenStreetMap data for specified key-value pairs (e.g. key="building") using the overpass API. Different OSM objects can be plotted in different colours using the function \code{add.osm.objects}. The function \code{group_osm_objects} enables customised highlighting of selected regions using different graphical schemes designed to contrast with surrounding backgrounds.
Description: Produces customisable images of OpenStreetMap data. Extracts OpenStreetMap data for specified key-value pairs (e.g. key="building") using the overpass API. Different OSM objects can be plotted in different colours using the function add_osm_objects(). The function group_osm_objects() enables customised highlighting of selected regions using different graphical schemes designed to contrast with surrounding backgrounds.
Depends: R (>= 3.2.3)
Imports:
ggm,
Expand Down
44 changes: 2 additions & 42 deletions R/osmplotr.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,48 +45,8 @@ NULL
#' the circular perimeter of ('Regent.St', 'Oxford.St', 'Shaftesbury')
#' }
#'
#' @examples
#' # Data were downloaded using the following code:
#' bbox <- c(-0.13,51.5,-0.12,51.51) # smaller bbox for the example
#' #bbox <- c(-0.15,51.5,-0.1,51.52) # but this one actually used
#' structures <- c ('highway', 'highway', 'building', 'building', 'building',
#' 'amenity', 'grass', 'park', 'natural', 'tree')
#' structs <- osm_structures (structures=structures, col_scheme='dark')
#' structs$value [1] <- '!primary'
#' structs$value [2] <- 'primary'
#' structs$suffix [2] <- 'HP'
#' structs$value [3] <- '!residential'
#' structs$value [4] <- 'residential'
#' structs$value [5] <- 'commercial'
#' structs$suffix [3] <- 'BNR'
#' structs$suffix [4] <- 'BR'
#' structs$suffix [5] <- 'BC'
#' london <- list ()
#' for (i in 1:(nrow (structs) - 1))
#' {
#' dat <- extract_osm_objects (key=structs$key [i], value=structs$value [i],
#' bbox=bbox)
#' fname <- paste0 ('dat_', structs$suffix [i])
#' assign (fname, dat)
#' london [[i]] <- get (fname)
#' names (london)[i] <- fname
#' rm (list=c(fname))
#' }
#' bbox <- c(-0.15,51.5,-0.1,51.52)
#' extra_pairs <- c ('name', 'Royal.Festival.Hall')
#' london$dat_RFH <- extract_osm_objects (key='building', extra_pairs=extra_pairs,
#' bbox=bbox)
#' extra_pairs <- list (c ('addr:street', 'Stamford.St'),
#' c ('addr:housenumber', '150'))
#' london$dat_ST <- extract_osm_objects (key='building', extra_pairs=extra_pairs,
#' bbox=bbox)
#' highways <- c ('Kingsway', 'Holborn', 'Farringdon.St', 'Strand',
#' 'Fleet.St', 'Aldwych')
#' #london$highways1 <- highways2polygon (highways=highways, bbox=bbox)
#' highways <- c ('Queen.s.Walk', 'Blackfriars', 'Waterloo', 'The.Cut')
#' london$highways2 <- highways2polygon (highways=highways, bbox=bbox)
#' highways <- c ('Regent.St', 'Oxford.St', 'Shaftesbury')
#' london$highways3 <- highways2polygon (highways=highways, bbox=bbox)
#' The vignette 'Downloading Data' contains the script used to generate these
#' data.
#'
#' @docType data
#' @keywords datasets
Expand Down
3 changes: 1 addition & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#LFILE = ./vignettes/making-maps
LFILE = README

all: knit open
Expand All @@ -11,4 +10,4 @@ open: $(LFILE).html
xdg-open $(LFILE).html &

clean:
rm -f vignettes/*.png
rm -f *.html
45 changes: 3 additions & 42 deletions man/london.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,9 @@ structures in a small part of central London, U.K. (bbox = -0.15, 51.5,
the circular perimeter of ('Regent.St', 'Oxford.St', 'Shaftesbury')
}
}
\examples{
# Data were downloaded using the following code:
bbox <- c(-0.13,51.5,-0.12,51.51) # smaller bbox for the example
#bbox <- c(-0.15,51.5,-0.1,51.52) # but this one actually used
structures <- c ('highway', 'highway', 'building', 'building', 'building',
'amenity', 'grass', 'park', 'natural', 'tree')
structs <- osm_structures (structures=structures, col_scheme='dark')
structs$value [1] <- '!primary'
structs$value [2] <- 'primary'
structs$suffix [2] <- 'HP'
structs$value [3] <- '!residential'
structs$value [4] <- 'residential'
structs$value [5] <- 'commercial'
structs$suffix [3] <- 'BNR'
structs$suffix [4] <- 'BR'
structs$suffix [5] <- 'BC'
london <- list ()
for (i in 1:(nrow (structs) - 1))
{
dat <- extract_osm_objects (key=structs$key [i], value=structs$value [i],
bbox=bbox)
fname <- paste0 ('dat_', structs$suffix [i])
assign (fname, dat)
london [[i]] <- get (fname)
names (london)[i] <- fname
rm (list=c(fname))
}
bbox <- c(-0.15,51.5,-0.1,51.52)
extra_pairs <- c ('name', 'Royal.Festival.Hall')
london$dat_RFH <- extract_osm_objects (key='building', extra_pairs=extra_pairs,
bbox=bbox)
extra_pairs <- list (c ('addr:street', 'Stamford.St'),
c ('addr:housenumber', '150'))
london$dat_ST <- extract_osm_objects (key='building', extra_pairs=extra_pairs,
bbox=bbox)
highways <- c ('Kingsway', 'Holborn', 'Farringdon.St', 'Strand',
'Fleet.St', 'Aldwych')
#london$highways1 <- highways2polygon (highways=highways, bbox=bbox)
highways <- c ('Queen.s.Walk', 'Blackfriars', 'Waterloo', 'The.Cut')
london$highways2 <- highways2polygon (highways=highways, bbox=bbox)
highways <- c ('Regent.St', 'Oxford.St', 'Shaftesbury')
london$highways3 <- highways2polygon (highways=highways, bbox=bbox)
\details{
The vignette 'Downloading Data' contains the script used to generate these
data.
}
\keyword{datasets}

72 changes: 72 additions & 0 deletions vignettes/downloading-data.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: "Downloading Data"
author: "Mark Padgham"
date: "`r Sys.Date()`"
#output: rmarkdown::pdf_document
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Downloading Data}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r load, include=FALSE}
setwd ("../..")
library (devtools)
load_all ("osmplotr")
setwd ("./osmplotr/vignettes")
```

This vignette demonstrates how the `london` data included with the `osmplotr`
package were generated. First customise an `osm_structures` data frame.

```{r}
bbox <- c(-0.15,51.5,-0.1,51.52)
structures <- c ('highway', 'highway', 'building', 'building', 'building',
'amenity', 'grass', 'park', 'natural', 'tree')
structs <- osm_structures (structures=structures, col_scheme='dark')
structs$value [1] <- '!primary'
structs$value [2] <- 'primary'
structs$suffix [2] <- 'HP'
structs$value [3] <- '!residential'
structs$value [4] <- 'residential'
structs$value [5] <- 'commercial'
structs$suffix [3] <- 'BNR'
structs$suffix [4] <- 'BR'
structs$suffix [5] <- 'BC'
```

Then download the corresponding data

```{r, eval=FALSE}
london <- list ()
for (i in 1:(nrow (structs) - 1))
{
dat <- extract_osm_objects (key=structs$key [i], value=structs$value [i],
bbox=bbox)
fname <- paste0 ('dat_', structs$suffix [i])
assign (fname, dat)
london [[i]] <- get (fname)
names (london)[i] <- fname
rm (list=c(fname))
}
```

And finally the additional data for specific buildings and highways

```{r, eval=FALSE}
extra_pairs <- c ('name', 'Royal.Festival.Hall')
london$dat_RFH <- extract_osm_objects (key='building', extra_pairs=extra_pairs,
bbox=bbox)
extra_pairs <- list (c ('addr:street', 'Stamford.St'),
c ('addr:housenumber', '150'))
london$dat_ST <- extract_osm_objects (key='building', extra_pairs=extra_pairs,
bbox=bbox)
highways <- c ('Kingsway', 'Holborn', 'Farringdon.St', 'Strand',
'Fleet.St', 'Aldwych')
london$highways1 <- highways2polygon (highways=highways, bbox=bbox)
highways <- c ('Queen.s.Walk', 'Blackfriars', 'Waterloo', 'The.Cut')
london$highways2 <- highways2polygon (highways=highways, bbox=bbox)
highways <- c ('Regent.St', 'Oxford.St', 'Shaftesbury')
london$highways3 <- highways2polygon (highways=highways, bbox=bbox)
```
25 changes: 25 additions & 0 deletions vignettes/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
MAPFILE = making-maps
DATFILE = downloading-data

all: maps data

maps: mapsmake mapsopen

data: datamake dataopen

mapsmake: $(MAPFILE).Rmd
echo "rmarkdown::render('$(MAPFILE).Rmd',rmarkdown::md_document(variant='markdown_github'))" | R --no-save -q
echo "rmarkdown::render('$(MAPFILE).Rmd',output_file='$(MAPFILE).html')" | R --no-save -q

datamake: $(DATFILE).Rmd
echo "rmarkdown::render('$(DATFILE).Rmd',rmarkdown::md_document(variant='markdown_github'))" | R --no-save -q
echo "rmarkdown::render('$(DATFILE).Rmd',output_file='$(DATFILE).html')" | R --no-save -q

mapsopen: $(MAPFILE).html
xdg-open $(MAPFILE).html &

dataopen: $(DATFILE).html
xdg-open $(DATFILE).html &

clean:
rm -f *.png *.html

0 comments on commit dde623c

Please sign in to comment.