R package for downloading OpenStreetMap data
1test_that ("elevation", {
2
3 # elevation can't actually be tested, because it only works with a full SRTM
4 # elevation file, so this test doesn't actually do anything.
5 qry <- opq (bbox = c (-0.116, 51.516, -0.115, 51.517)) |>
6 add_osm_feature (key = "highway")
7
8 f <- file.path (tempdir (), "junk.osm")
9 doc <- with_mock_dir ("mock_elevation", {
10 osmdata_xml (qry, file = f)
11 })
12
13 expect_silent (x <- osmdata_sc (qry, doc = f))
14 expect_true (file.exists (f))
15
16 xml <- xml2::read_xml (f)
17 expect_s3_class (xml, "xml_document")
18
19 # elev_file = "/data/data/elevation/srtm_36_02.zip"
20 # x <- osm_elevation (x, elev_file = elev_file)
21})
22
23# elevation.R has two helper fns:
24# 1. check_bbox()
25# 2. get_file_index()
26test_that ("misc elevation fns", {
27
28 bbox <- c (-0.116, 51.516, -0.115, 51.517)
29 # 2nd param of check_bbox() is a raster object to which sp::bbox can be
30 # directly applied; faked here with a simple matrix:
31 bbox_mat <- t (matrix (bbox, ncol = 2))
32
33 qry <- opq (bbox = bbox)
34 dat <- list (meta = list (bbox = qry$bbox))
35 # 'sp' will soon issue a message here about depending on legacy packages.
36 # Expectation may be restored once sp-dependency has been removed (#273).
37 # expect_silent (
38 check_bbox (dat, bbox_mat)
39 # )
40
41 ti <- get_tile_index (qry$bbox)
42 expect_s3_class (ti, "data.frame")
43 expect_length (ti, 2L)
44 expect_identical (names (ti), c ("xi", "yi"))
45 expect_type (ti$xi, "integer")
46 expect_type (ti$yi, "integer")
47})