我正在尝试在落入某个区域的传单地图上绘制端口的位置。这 30 个奇怪的区域是使用mapedit
包作为sf
POLYGON 创建的。一个这样的地区WestCoastIndiax
(印度西海岸)的代码如下:
structure(list(X_leaflet_id = 629L, feature_type = "polygon",
geometry = structure(list(structure(list(structure(c(-298.1964,
-298.4601, -298.3722, -297.6855, -293.9062, -293.4009, -292.8296,
-292.1265, -291.7529, -289.3359, -288.1934, -289.248, -289.0723,
-287.7539, -284.8535, -286.04, -283.0957, -282.3157, -282.4255,
-282.9529, -283.4253, -284.0295, -284.9634, -285.8643, -286.7651,
-286.7432, -286.875, -286.9519, -288.2922, -288.6328, -290.05,
-291.8958, -292.8955, -293.4009, -294.6863, -298.1964, 25.6861,
24.8565, 24.682, 24.8765, 25.1453, 24.5671, 23.8256, 23.5237,
22.6343, 19.6012, 20.0559, 12.5975, 7.1881, -1.1425, -0.791,
8.4941, 8.0484, 7.8416, 8.2441, 9.2973, 10.4338, 11.62, 14.094,
16.1197, 19.3215, 20.0456, 21.8411, 22.6748, 23.433, 24.4572,
24.7768, 25.0657, 25.3043, 25.8592, 26.116, 25.6861), .Dim = c(36L,
2L))), class = c("XY", "POLYGON", "sfg"))), class = c("sfc_POLYGON",
"sfc"), precision = 0, bbox = structure(c(xmin = -298.4601,
ymin = -1.1425, xmax = -282.3157, ymax = 26.116), class = "bbox"), crs = structure(list(
epsg = 4326L, proj4string = "+proj=longlat +datum=WGS84 +no_defs"), class = "crs"), n_empty = 0L)), row.names = 1L, sf_column = "geometry", agr = structure(c(X_leaflet_id = NA_integer_,
feature_type = NA_integer_), class = "factor", .Label = c("constant",
"aggregate", "identity")), class = c("sf", "data.frame"))
该区域在 中正确绘制leaflet
。
leaflet() %>% addTiles() %>% addPolygons(data=WestCoastIndiax)
st_within()
然后我试图通过使用包中的函数来查看特定位置是否属于这些区域sf
。确实属于该地区的孟买市的一个例子是:
st_within(st_point(c(72.49,18.54)),WestCoastIndiax)
返回:
Sparse geometry binary predicate list of length 1, where the predicate was `within'
1: (empty)
当我尝试绘制孟买的多边形和坐标时,这就是我得到的:
leaflet() %>% addTiles() %>% addPolygons(data=WestCoastIndiax) %>% addMarkers(lng = 72.49, lat = 18.54)
我看了看这个并收集到我需要正确crs
然后将其再次转换为 4326。但是,我不知道这 30 个奇怪几何图形的坐标参考系应该是什么。我试过这个:
st_crs(WestCoastIndiax) <- "+init=epsg:3857 +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"
WestCoastIndiax <- st_transform(WestCoastIndiax, 4326)
虽然现在bbox
单位发生了变化,但它们不正确:
Geometry set for 1 feature
geometry type: POLYGON
dimension: XY
bbox: xmin: -0.002681113 ymin: -1.026325e-05 xmax: -0.002536085 ymax: 0.000234604
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
POLYGON ((-0.002678744 0.0002307422, -0.0026811...
请在这里提供一些帮助。