Similar to this question I get an error from get_osm
library(maptools)
library(osmar)
url <- "http://osmar.r-forge.r-project.org/"
file <- "muenchen.osm.gz"
# download.file(sprintf("%s%s", url, file), file)
# gzip is linux only, on windows I unzipped this manually with 7zip!
# unzip("gzip -d muenchen.osm.gz")
src <- osmsource_osmosis(file = "140-muenchen.osm")
muc_bbox <- center_bbox(11.575278, 48.137222, 3000, 3000)
muc <- get_osm(x = muc_bbox, source = src)
The error is
Fehler in file(con, "r") : kann Verbindung nicht öffnen Zusätzlich: Warnmeldung: In file(con, "r") : kann Datei 'C:\Users\sqc\AppData\Local\Temp\RtmpQtndOZ\file3bc03a7b5127' nicht öffnen: No such file or directory
I ran RStudio as administrator, I installed gzip, but it still does not work. Any ideas? I am on windows.
(The example is from here)
Edit:
My path looks like C:/07 Rprogress/00 Erste Testprogramme/140-muenchen.osm.gz
but I hope this is not the problem
file.exists("muenchen.osm.gz")
[1] TRUE
> shell("7z e muenchen.osm.gz")
Der Befehl "7z" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
Warnmeldung:
In shell("7z e muenchen.osm.gz") :
'7z e muenchen.osm.gz' Ausführung mit Fehlerkode 1 fehlgeschlagen
> shell.exec("7z e muenchen.osm.gz")
Fehler in shell.exec("7z e muenchen.osm.gz") :
'7z e 140-muenchen.osm.gz' nicht gefunden
> system("7z e muenchen.osm.gz")
[1] 127
I follow the instructions from here and set
set PATH=%PATH%;C:\Program Files\7-Zip\
echo %PATH%
Edit 2:
st_layers("myfile.osm", do_count = TRUE)
Driver: OSM
Available layers:
layer_name geometry_type features fields
1 points Point 61 10
2 lines Line String 0 9
3 multilinestrings Multi Line String 0 4
4 multipolygons Multi Polygon 0 25
5 other_relations Geometry Collection 0 4
Warnmeldungen:
1: In CPL_get_layers(dsn, options, do_count) :
GDAL Error 1: Non increasing node id. Use OSM_USE_CUSTOM_INDEXING=NO
2: ...
The following code should work for reading into R the
muenchen.osm.gz
file.I'm coding now with the
sf
approach. I'm quite sure that it's possible to useosmdata
to read in R the same.osm
file but I can't make it work for the moment.The printing of the object is quite messy here in SO but it's more clear if you copy and paste the code in R.
Created on 2020-05-26 by the reprex package (v0.3.0)
You should also check the osmdata vignettes if you want to build your own queries for downloading data from Open Street Map.
References
If you want to check a few references on
sf
I would suggest reading the vignettes (see the Articles) of the package and Chapters 1 to 7 of Geocomputation with R. If you want to check how to useosmdata
to create your own queries to Open Street Map I suggest reading the vignettes. There are a few differences between the two approaches but you can read them in the vignettes.AFAIK the suggested way (see here, here and here) for reading
.osm
data into R usingsf
is 1) transform the.osm
data into.gpkg
format (you can usesf::gdal_utils
) and 2) read the .gpkg file. If you can share the .osm file I can check it from my laptop.The error that you show in the OP is mentioned here and if you can share the
.osm
file I can test reading it.