简单特性 – 创建具有特定属性的新点

huangapple go评论93阅读模式
英文:

simple feature - create new points with certain properties

问题

我有一个simple features,其中包含一个简单的点,我想在该点周围创建6个均匀分布且距离原始点100米新点。在R(sf)中是否容易解决这个问题,你是否有可能提供一个类似这样的实现示例?

英文:

I've a simple features with a simple point, arround this point I like to create 6 new points equal distributed and 100 meter away from the orginal point. Is this easily solvable in R (sf) and do you have perhaps an example how I could implement something like this?

答案1

得分: 1

开始时将点缓冲100米,将其转换为线串,然后对缓冲的线串进行采样:

  1. library(sf)
  2. #> 链接到 GEOS 3.8.0、GDAL 3.0.4、PROJ 6.3.1;sf_use_s2() 为 TRUE
  3. library(tidyverse)
  4. set.seed(41)
  5. point <- st_sfc(st_point(c(0, 51.5))) %>% st_set_crs(4326) # 伦敦附近的一个点
  6. buffer <- st_buffer(point, dist = 100) %>%
  7. st_cast('LINESTRING')
  8. six_points <- st_sample(buffer, size = 6, type = 'regular')
  9. #> 尽管坐标是经度/纬度,st_sample 假设它们是平面的
  10. #距离:
  11. six_points %>% st_as_sf() %>% st_cast('POINT') %>% st_distance(point)
  12. #> 单位:[m]
  13. #> [,1]
  14. #> [1,] 100.5366
  15. #> [2,] 100.2739
  16. #> [3,] 100.7187
  17. #> [4,] 100.5599
  18. #> [5,] 100.2410
  19. #> [6,] 100.6761

差不多了。如果需要厘米级精度,选择更好的坐标系会有帮助。

  1. ggplot() +
  2. geom_sf(data = point, col = 'red') +
  3. geom_sf(data = buffer) +
  4. geom_sf(data = six_points, color = 'turquoise', size = 4) +
  5. theme_void()

简单特性 – 创建具有特定属性的新点

在地图上:

  1. library(mapview)
  2. mapview(point) +
  3. buffer +
  4. six_points

简单特性 – 创建具有特定属性的新点

<sup>由 reprex 包 (v2.0.1) 于 2023-03-31 创建</sup>

英文:

Start by buffering the point by 100 meters, cast it to a linestring, and then sample the buffered linestring:

  1. library(sf)
  2. #&gt; Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
  3. library(tidyverse)
  4. set.seed(41)
  5. point &lt;- st_sfc(st_point(c(0, 51.5))) %&gt;% st_set_crs(4326) # a point around London
  6. buffer &lt;- st_buffer(point, dist = 100) %&gt;%
  7. st_cast(&#39;LINESTRING&#39;)
  8. six_points &lt;- st_sample(buffer, size = 6, type = &#39;regular&#39;)
  9. #&gt; although coordinates are longitude/latitude, st_sample assumes that they are
  10. #&gt; planar
  11. #distances:
  12. six_points %&gt;% st_as_sf() %&gt;% st_cast(&#39;POINT&#39;) %&gt;% st_distance(point)
  13. #&gt; Units: [m]
  14. #&gt; [,1]
  15. #&gt; [1,] 100.5366
  16. #&gt; [2,] 100.2739
  17. #&gt; [3,] 100.7187
  18. #&gt; [4,] 100.5599
  19. #&gt; [5,] 100.2410
  20. #&gt; [6,] 100.6761

Pretty close. Choosing a better crs would help if you need cm accuracy.

  1. ggplot() +
  2. geom_sf(data = point, col = &#39;red&#39;) +
  3. geom_sf(data = buffer) +
  4. geom_sf(data = six_points, color = &#39;turquoise&#39;, size = 4) +
  5. theme_void()

简单特性 – 创建具有特定属性的新点

On a map:

  1. library(mapview)
  2. mapview(point) +
  3. buffer +
  4. six_points

简单特性 – 创建具有特定属性的新点

<sup>Created on 2023-03-31 by the reprex package (v2.0.1)</sup>

huangapple
  • 本文由 发表于 2023年3月31日 18:43:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75897619.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定