我正在使用 mapview 包构建地图。但是,当我使用 st_sample 并生成点时,有些点没有被映射。另外,st_buffer合并了一些区域(它们应该是分开的)。
library(sf)
library(mapview)
library(magrittr)
set.seed(145)
chemins.32188 = st_zm(chemins2) %>% st_transform(crs = 32188)
rd.pts.sentiers <- st_sample(x = chemins.32188, size = 10)
buff.pt = st_buffer(x = rd.pts.sentiers,
dist = units::set_units(x = 100,
value = "m"))
mapviewOptions(fgb = FALSE)
mapview(chemins.32188) +
mapview(rd.pts.sentiers) +
mapview(buff.pt)
当我使用绘图时,它可以工作......但缓冲区仍然被合并。
plot(chemins.32188$geom)
plot(buff.pt, add= TRUE, col = scales::alpha("blue", .5))
plot(rd.pts.sentiers, add= TRUE, pch = 19, col = "red")
这是数据
chemins2 = structure(list(Name = "Path Measure", description = NA_character_,
timestamp = structure(NA_real_, class = c("POSIXct", "POSIXt"
)), begin = structure(NA_real_, class = c("POSIXct", "POSIXt"
)), end = structure(NA_real_, class = c("POSIXct", "POSIXt"
)), altitudeMode = NA_character_, tessellate = -1L, extrude = 0L,
visibility = -1L, drawOrder = NA_integer_, icon = NA_character_,
sentier = NA_character_, layer = "path Parc — Path Measure",
path = "~/Desktop/path Parc.kml|layername=Path Measure|geometrytype=LineString25D|uniqueGeometryType=yes",
geom = structure(list(structure(list(structure(c(299434.130314458,
300531.43655987, 299434.130314458, 5046816.92873926, 5047257.53966348,
5046816.92873926), dim = 3:2), structure(c(299434.130314458,
300401.157828111, 299434.130314458, 5046816.92873926, 5046249.12770288,
5046816.92873926), dim = 3:2)), class = c("XY", "MULTILINESTRING",
"sfg"))), n_empty = 0L, crs = structure(list(input = "EPSG:32188",
wkt = "PROJCRS[\"NAD83 / MTM zone 8\",\n BASEGEOGCRS[\"NAD83\",\n DATUM[\"North American Datum 1983\",\n ELLIPSOID[\"GRS 1980\",6378137,298.257222101,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n ID[\"EPSG\",4269]],\n CONVERSION[\"MTM zone 8\",\n METHOD[\"Transverse Mercator\",\n ID[\"EPSG\",9807]],\n PARAMETER[\"Latitude of natural origin\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8801]],\n PARAMETER[\"Longitude of natural origin\",-73.5,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8802]],\n PARAMETER[\"Scale factor at natural origin\",0.9999,\n SCALEUNIT[\"unity\",1],\n ID[\"EPSG\",8805]],\n PARAMETER[\"False easting\",304800,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8806]],\n PARAMETER[\"False northing\",0,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8807]]],\n CS[Cartesian,2],\n AXIS[\"easting (E(X))\",east,\n ORDER[1],\n LENGTHUNIT[\"metre\",1]],\n AXIS[\"northing (N(Y))\",north,\n ORDER[2],\n LENGTHUNIT[\"metre\",1]],\n USAGE[\n SCOPE[\"Engineering survey, topographic mapping.\"],\n AREA[\"Canada - Quebec between 75°W and 72°W.; Canada - Ontario - east of 75°W.\"],\n BBOX[44.98,-75,62.53,-72]],\n ID[\"EPSG\",32188]]"), class = "crs"), class = c("sfc_MULTILINESTRING",
"sfc"), precision = 0, bbox = structure(c(xmin = 299434.130314458,
ymin = 5046249.12770288, xmax = 300531.43655987, ymax = 5047257.53966348
), class = "bbox"))), row.names = 1L, sf_column = "geom", agr = structure(c(Name = NA_integer_,
description = NA_integer_, timestamp = NA_integer_, begin = NA_integer_,
end = NA_integer_, altitudeMode = NA_integer_, tessellate = NA_integer_,
extrude = NA_integer_, visibility = NA_integer_, drawOrder = NA_integer_,
icon = NA_integer_, sentier = NA_integer_, layer = NA_integer_,
path = NA_integer_), class = "factor", levels = c("constant",
"aggregate", "identity")), class = c("sf", "data.frame"))
在你的 reprex 中,你有
MULTILINESTRING
2LINESTRING
s,st_sample()
返回 2MULTIPOINT
s,并且对于该特定种子,第一个恰好是空的(即所有点都来自同一个 sub-LINESTRING
):显然
mapview
(或leaflet
) 对空(点)几何图形不太满意,您还应该收到以下警告mapview()
:当您从 中创建缓冲区时
MULTIPOINT rd.pts.sentiers
,每个要素都将是MULTIPOLYGON
,因此单个要素内的重叠将导致多边形合并。要修复此问题,您可能需要
POINT
在创建缓冲区之前检查样本中是否有空几何图形并将样本转换为 s:创建于 2024-04-23,使用reprex v2.1.0