- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 nominatim
R package 从 OpenStreetMap 获取可绘制的空间(边界/多边形)数据.
nominatim::osm_search_spatial
请求似乎成功运行,但生成的数据尽管被发现为“SpatialPolygonsDataFrame”,但显示为无效,我无法使用 plot
或 tmap
。它似乎也缺少 CRS。
我不确定我是否遗漏了一两步,或者从 OSM 检索的数据是否确实有问题(似乎不太可能,但有可能)。
编辑:接收到的数据中的纬度和经度似乎有问题,因此已使用新的 reprex 编辑了此问题。事实上,看起来可能需要在 GIS 论坛上而不是在 R 中提问。
删除之前的 reprex 显示多余的步骤和结果(移至要点 here)——这就是 Eugene Chong 在他的第一个回复中的回应。
这是我新的、更集中的、显示问题的 reprex(隐藏了 OSM API key )。您可以看到多边形 @coords 从第一个点 -1,-1 跃升到第二个点的 53,53,因此绘制了对角线。
library(nominatim)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
#> Nominatim Usage Policy: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
#> MapQuest Nominatim Terms of Use: http://info.mapquest.com/terms-of-use/
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(tmap)
library(tibble)
# get OSM search results for Ashfield district (UK)
ashfield <- nominatim::osm_search_spatial("Ashfield", limit = 1, key = $my_osm_api_key)
class(ashfield)
#> [1] "list"
# extract SPDF from list
ashfield <- ashfield[[1]]
class(ashfield)
#> [1] "SpatialPolygonsDataFrame"
#> attr(,"package")
#> [1] "sp"
# Convert to an SF object and try again
ashfield_sf <- sf::st_as_sf(ashfield)
class(ashfield_sf)
#> [1] "sf" "data.frame"
# set CRS (thanks to Eugene Chong)
st_crs(ashfield_sf) <- 4326
tmap::qtm(ashfield_sf)
#> Warning: The shape ashfield_sf is invalid. See sf::st_is_valid
glimpse(ashfield@data)
#> Observations: 1
#> Variables: 15
#> $ place_id <chr> "186877616"
#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://...
#> $ osm_type <chr> "relation"
#> $ osm_id <chr> "154043"
#> $ lat <dbl> 53.08977
#> $ lon <dbl> -1.251877
#> $ display_name <chr> "Ashfield, Nottinghamshire, East Midlands, England, Un...
#> $ class <chr> "boundary"
#> $ type <chr> "administrative"
#> $ importance <dbl> 0.2116014
#> $ icon <chr> "http://ip-10-98-176-55.mq-us-east-1.ec2.aolcloud.net/...
#> $ bbox_left <fct> 53.0080617
#> $ bbox_top <fct> 53.1714343
#> $ bbox_right <fct> -1.3445928
#> $ bbox_bottom <fct> -1.1642542
head(ashfield@polygons[[1]]@Polygons[[1]]@coords)
#> [,1] [,2]
#> [1,] -1.344593 -1.344409
#> [2,] 53.063537 53.063260
#> [3,] 53.064985 53.063764
#> [4,] 53.065520 53.065521
#> [5,] 53.065553 53.065526
#> [6,] 53.065725 53.065656
ashfield_sf$geometry
#> Geometry set for 1 feature
#> geometry type: POLYGON
#> dimension: XY
#> bbox: xmin: -1.344593 ymin: -1.344593 xmax: 53.17143 ymax: 53.17142
#> epsg (SRID): 4326
#> proj4string: +proj=longlat +datum=WGS84 +no_defs
#> POLYGON ((-1.344593 -1.344409, 53.06354 53.0632...
由 reprex package 创建于 2020-02-20 (v0.3.0)
下一步:我将尝试从 nominatim 直接下载,而不是通过 R 包,看看我得到了什么。
最佳答案
使用 lwgeom
包中的 st_make_valid()
可以使警告消失:
添加 WGS84 作为 crs。
ashfield_sf <- sf::st_as_sf(ashfield)
st_crs(ashfield_sf) <- 4326
sf::st_is_valid(ashfield_sf, reason = TRUE)
[1] "Self-intersection[53.0709899483331 53.0709561246412]"
使用st_make_valid()
library(lwgeom)
ashfield_sf_2 <- st_make_valid(ashfield_sf)
sf::st_is_valid(ashfield_sf_2, reason = TRUE)
[1] "Valid Geometry"
不过,就几何本身而言,它仍然只是一条从俄罗斯延伸到非洲西海岸的线,而不是预期的 Ashfield 多边形。
至于为什么几何首先无效,我不确定,但自相交错误表明多边形在某个点与自身交叉(就像领结一样)。请参阅这篇文章,其中对有效和无效的几何图形进行了更多讨论:https://www.r-spatial.org/r/2017/03/19/invalid.html
关于r - 为什么从 OSM/Nominatim 获取的空间数据框无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60319795/
它似乎不仅仅是删除重复项,但我找不到任何关于它的好文档。 API docs目前只是说: dedupe=[0|1] No explanation yet. 我正在运行我自己的 Nominatim
只是在我自己的 Openstreetmaps 服务器上闲逛,遇到了一些问题。 1) 我按照以下说明进行操作:http://wiki.openstreetmap.org/wiki/The_Rails_P
我们目前正在安装 Nominatim API,它在排名 30(索引),已经索引了大约 4 天,有人知道有多少排名要索引吗? 最佳答案 有 30 个 0 表示最高优先级,30 表示最低。 Here is
以下脚本可以完美处理包含 2 行的文件,但是当我尝试 2500 行文件时,出现 429 个异常。所以,我将查询时间增加到 5 秒。我还填写了用户代理。尝试失败后,我连接到 VPN 以更改“新鲜”,但我
我正在使用 OpenLayers + OpenStreetMaps 开发在线 map 应用程序。 我需要帮助在 javascript(或 php)中实现一个简单的反向地理编码函数,它接收纬度和经度并返
我有 PHP 应用程序发送地址解析的 url 请求: http://nominatim.openstreetmap.org/reverse?format=xml&lat=33&lon=34&addre
您好,我是 openstreet map 和 nomintim 的新手....我在以下链接中找到了我要找的东西.....但我不确定如何实现它...我只需要得到地理编码详细信息,比如如果我们搜索一个地方
有没有办法通过 nominatim 请求获取对象所在的道路类型? 例如 http://nominatim.openstreetmap.org/reverse?format=xml&lat=52.548
我在 PHP 中有这些代码来进行反向地理编码[从纬度、经度获取地址]: $value) { if($name == "display_name") {
当我在 guide 的帮助下安装 Nominatim 时,它会自动创建一个网站。我想知道如何才能按照自己的意愿更改网站。 osm@debian:/var/www/nominatim$ ls css
我正在使用 Nominatim API 获取项目的一些本地街道的边界框和多边形点。 我发现的一个问题是,当我在网络浏览器上请求 URL 时,例如: Rua de Santa Maria 它检索此边界框
我正在尝试设置自己的 OpenStreetMap 服务器,并且遵循了 Wikipedia 中的官方教程和另一个教程。首先,我从 GIT 克隆 Nominatim,然后通过录音构建它: cd Nomin
我需要弄清楚将多个 OSM 文件加载到 Nominatim 数据库的过程。我已经完成了所有设置,并且可以毫无问题地加载单个文件。 基本上我想要做的是加载一些 GeoFabrik OSM 文件,仅适用于
我想使用 nominatim R package 从 OpenStreetMap 获取可绘制的空间(边界/多边形)数据. nominatim::osm_search_spatial 请求似乎成功运行,
我在使用传单 map 的传单控制地理编码器插件时遇到了一些真正的问题(leaflet-control-geocoder),我一定是个非常白痴,因为我只是尝试复制我在本页demo-plugin上找到的相
我在 Amazon R3 Linux 实例上设置了 PHP Nominatim API。 (15GB 内存 2VCPU 等(这是一台相当快的计算机)) 我预计它每秒大约响应多少次 API 调用? 我计
我正在开发使用谷歌地图的移动应用程序,我想用设备纬度和经度(反向地理编码)查找用户当前地址。 谷歌有一些限制,一旦我超出它就会向我收费。 现在我在看 OpenStreetMap,它可以公开使用。我可以
我已经在虚拟 qemu ubuntu 16.04 服务器上安装了 nominatiom,我可以使用 http://127.0.0.1:8080 访问 apache 的默认页面url 在主机中,但我无法
我有一个包含超过 6k 个地址条目的数据库,因此我已经安装了带有 docker 的 nominatim 服务器来进行地理编码工作。它在“localhost:8080”上的 Web 表单中正常工作。 但
我已经按照那里的 wiki.guide http://wiki.openstreetmap.org/wiki/Nominatim/Installation 在我本地的 centOS 6.6 机器上安装
我是一名优秀的程序员,十分优秀!