如何使用osmar提取osm数据
类似于我从如何使用osmar提取osm数据,r,windows,osmar,R,Windows,Osmar,类似于我从get\u 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! # unzi
get\u 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)
我按照来自和集合的说明进行操作
编辑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: ...
下面的代码应该可以读入R
muenchen.osm.gz
文件
#包
图书馆(sf)
#>链接到GEOS 3.8.0、GDAL 3.0.4、项目6.3.1
选项(宽度=120)
#下载muenchen.osm.gz文件
下载文件(
url=”http://osmar.r-forge.r-project.org/muenchen.osm.gz",
destfile=“muenchen.osm.gz”,
mode=“wb”
)
#使用7zip解压。您也可以手动执行此操作。
shell(“7z e muenchen.osm.gz”)
我现在用sf
方法编码。我很确定可以使用osmdata
在R中读取相同的.osm
文件,但目前我无法使其工作
#1。列出所有图层
st_层(“muenchen.osm”,do_count=TRUE)
#>司机:OSM
#>可用层:
#>图层\名称几何图形\类型要素字段
#>1分37583分10
#>2行行字符串56325 9
#>3多行字符串多行字符串96 4
#>4多多边形多多边形32328 25
#>5其他_关系几何集合337 4
# 2. 读取行层(或任何其他层)
明晨你好!我不知道如何用osmar修复该错误,但如果您愿意,我可以提供等效代码,用于使用sf或osmdata包读取相同的.osm数据。@agila欢迎任何解决方案:-)您能想象一下,为什么shell命令都不起作用吗?我需要手动操作…你是说shell(“7z e muenchen.osm.gz”)
?你在使用windows吗?是的,对不起-输入错误。。。我更正了我的编辑。是的,我在Windows上。我认为您应该只在Windows路径中添加“7z”。我按照指示解决了一个奇怪的问题。谢谢。如果这是一个新问题-它仍然不起作用。。。
set PATH=%PATH%;C:\Program Files\7-Zip\
echo %PATH%
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: ...