Closed mtennekes closed 3 years ago
Hi @mtennekes and thanks for your questions. We completely rewrote the package in July and I think that we fixed most of your questions.
Regarding terminology, what is the difference between key and attribute? It is confusing.
OSM describe physical data using tags
. A tag
is a pair of two items: a key
(e.g. highway) and a value
(e.g. primary). The term attribute
is used in the osmconf.ini
file by GDAL to describe which tags should be explicitly read, while all other tags are appended in the other_tags
field. See here for more details. For this reason, that argument is now called extra_tags
.
For example:
# packages
suppressPackageStartupMessages(library(osmextract))
names(oe_get("Isle of Wight"))
#> [1] "osm_id" "name" "highway" "waterway" "aerialway"
#> [6] "barrier" "man_made" "z_order" "other_tags" "geometry"
names(oe_get("Isle of Wight", extra_tags = c("oneway", "maxspeed", "lit", "junction")))
#> [1] "osm_id" "name" "highway" "waterway" "aerialway"
#> [6] "barrier" "man_made" "oneway" "maxspeed" "lit"
#> [11] "junction" "z_order" "other_tags" "geometry"
Created on 2020-10-28 by the reprex package (v0.3.0)
I agree that the previous terminology was slightly unclear, but I think that it should be understandable now.
Why are not all available keys/attributes included in ini_new.ini? E.g. waterways is not included as an attribute of the layers multipolygons, while some waterways values are polygons (e.g. riverbanks)
I'm not sure that I understand your question, but we decided not to include all available keys since there are too many tags and I think that the best approach is to manually select which keys you are interested in. For example, the following code can be used to extract all keys stored in a .pbf
file:
# packages
suppressPackageStartupMessages(library(osmextract))
# data
iow <- oe_get("Isle of Wight")
#> Warning: st_crs<- : replacing crs does not reproject data; use st_transform for
#> that
head(oe_get_keys(iow), 10)
#> [1] "lit" "lanes" "surface" "maxspeed" "ref"
#> [6] "sidewalk" "incline" "oneway" "prow_ref" "designation"
Created on 2020-10-28 by the reprex package (v0.3.0)
Later, they can be added using the same syntax as before.
The argument attributes can be used in get_geofabrik. The default values, from make_additional_attributes(layer) seem arbitrary. Why this selection?
The default value now is NULL
!
One suggestion would be to include the key into the attributes. For instance this does not work:
I think that this is not relevant anymore, and the same is for the next questions. I'm working now on testing the differences between osmextract and the data in mapcruzin.com
Reprex for the "finding"
# packages
suppressPackageStartupMessages({
library(osmextract)
library(osmdata)
library(sf)
library(tmap)
})
tmap_mode("view")
#> tmap mode set to interactive viewing
osmextract
approach
ile_multipoly_osmext <- oe_get(
place = "Ile-de-France",
quiet = FALSE,
layer = "multipolygons",
extra_tags = "waterway",
query = "SELECT * from \"multipolygons\" WHERE waterway = \"riverbank\""
)
#> The input place was matched with: Ile-de-France
#> The chosen file was already detected in the download directory. Skip downloading.
#> The corresponding gpkg file was already detected. Skip vectortranslate operations.
#> Reading layer `multipolygons' from data source `C:\Users\Utente\Documents\osm_data\geofabrik_ile-de-france-latest.gpkg' using driver `GPKG'
#> Simple feature collection with 105 features and 26 fields
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: 1.559279 ymin: 48.10158 xmax: 3.458908 ymax: 49.12312
#> geographic CRS: WGS 84
tm_shape(ile_multipoly_osmext) +
tm_polygons(col = "waterway")
osmdata
approach
ile_osmdata <- opq("Ile-de-France") %>%
add_osm_feature(key = "waterway", value = "riverbank") %>%
osmdata_sf()
Print result
ile_osmdata
#> Object of class 'osmdata' with:
#> $bbox : 48.1201456,1.4462445,49.241431,3.5592208
#> $overpass_call : The call submitted to the overpass API
#> $meta : metadata including timestamp and version numbers
#> $osm_points : 'sf' Simple Features Collection with 178818 points
#> $osm_lines : 'sf' Simple Features Collection with 171 linestrings
#> $osm_polygons : 'sf' Simple Features Collection with 2353 polygons
#> $osm_multilines : NULL
#> $osm_multipolygons : 'sf' Simple Features Collection with 121 multipolygons
ile_multipoly_osmdata <- unname_osmdata_sf(ile_osmdata)$osm_multipolygons
Plot result
tm_shape(ile_multipoly_osmdata) +
tm_polygons(col = "waterway")
It looks more or less the same as before. The only differences are caused by riverbanks that are close to the boundary of Ile-de-france
area and they are included in the bbox of osmdata
but not in the polygon used by osmextract
:
tm_shape(
ile_multipoly_osmdata[
! ile_multipoly_osmdata$osm_id %in% ile_multipoly_osmext$osm_id,
]
) +
tm_polygons()
Use mapcruzin data. Download and unzip
download.file(
"https://mapcruzin.com/download-shapefile/france-waterways-shape.zip",
"france-waterways-shape.zip"
)
unzip("france-waterways-shape.zip", exdir = tempdir())
Read-in data
ile_multipoly_mapcruzin <- sf::st_read(tempdir(), stringsAsFactors = FALSE)
#> Reading layer `waterways' from data source `C:\Users\Utente\AppData\Local\Temp\Rtmpc1fKIQ' using driver `ESRI Shapefile'
#> Simple feature collection with 9963 features and 4 fields
#> geometry type: LINESTRING
#> dimension: XY
#> bbox: xmin: -5.107661 ymin: 41.37122 xmax: 9.548755 ymax: 51.04924
#> geographic CRS: WGS 84
It's LINESTRING
instead of POLYGON
/MULTIPOLYGON
. Filter Ile-de-France
area
ile_multipoly_mapcruzin <- ile_multipoly_mapcruzin[
st_geometry(geofabrik_zones)[geofabrik_zones$name == "Ile-de-France"] %>%
st_set_crs(4326),
]
#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
Check results. Tbh I don't know how to compare the two approaches:
table(ile_multipoly_mapcruzin$type)
#>
#> aqueduc aqueduct canal canal; river dam dock
#> 6 6 67 1 2 2
#> drain La Seine lock_gate river stream weir
#> 34 1 14 160 355 14
mapview::mapview(ile_multipoly_mapcruzin, zcol = "type")
They look quite different, for example
tm_shape(ile_multipoly_mapcruzin) +
tm_lines() +
tm_view(set.view = c(2.31799, 48.91706, 11))
tm_shape(ile_multipoly_osmext) +
tm_polygons() +
tm_view(set.view = c(2.31799, 48.91706, 11))
Created on 2020-10-28 by the reprex package (v0.3.0)
TLDR: The results obtained with osmextract and osmdata are more or less the same so I think that we are getting the right data. I don't know how to compare with mapcruzin data.
I think this issue can now be closed.
Questions:
ini_new.ini
? E.g.waterways
is not included as an attribute of the layersmultipolygons
, while some waterways values are polygons (e.g.riverbanks
)attributes
can be used inget_geofabrik
. The default values, frommake_additional_attributes(layer)
seem arbitrary. Why this selection?One suggestion would be to include the
key
into theattributes
. For instance this does not work:while this works:
On a side note, it doesn't seem to collect all riverbanks. I downloaded a shapefile from https://mapcruzin.com/free-france-arcgis-maps-shapefiles.htm which is also extracted from OSM, but which does contain all riverbanks.
Strangely, for key/attribute
waterways
it is the other way round:Works:
Does not work:
A select all query does not work. It doesn't throw an error, but returns an empty sf object: