Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 从传单/光泽中绘制的特征构建空间线_R_Shiny_Leaflet_Polyline - Fatal编程技术网

R 从传单/光泽中绘制的特征构建空间线

R 从传单/光泽中绘制的特征构建空间线,r,shiny,leaflet,polyline,R,Shiny,Leaflet,Polyline,我想从“传单与光泽”中的绘图事件中构建一个SpatialLine对象(根据光栅进行评估)。我正在使用传单.extras中的AddDraw工具栏 虽然转换会很简单,但显然不是,我尝试使用(和的变体): #获取绘制线的坐标 line_坐标好的,我取得了一些成功 从传单.extras中的addDrawToolbar内绘制的功能如下所示: # line feature of 3 vertices line_coords <- input$rasmap_draw_new_feature$geomet

我想从“传单与光泽”中的绘图事件中构建一个SpatialLine对象(根据光栅进行评估)。我正在使用传单.extras中的AddDraw工具栏

虽然转换会很简单,但显然不是,我尝试使用(和的变体):

#获取绘制线的坐标

line_坐标好的,我取得了一些成功

从传单.extras中的addDrawToolbar内绘制的功能如下所示:

# line feature of 3 vertices
line_coords <- input$rasmap_draw_new_feature$geometry$coordinates
print(line_coords)
[[1]]
[[1]][[1]]
[1] -3.214188

[[1]][[2]]
[1] 54.55634

[[2]]
[[2]][[1]]
[1] -3.213501

[[2]][[2]]
[1] 54.53383

[[3]]
[[3]][[1]]
[1] -3.185349

[[3]][[2]]
[1] 54.53323

class(line_coords)
"list"

# then rbind the list into a matrix, all fine
raw <- do.call(rbind,line_coords)

print(raw)
    [,1]      [,2]    
[1,] -3.214188 54.55634
[2,] -3.213501 54.53383
[3,] -3.185349 54.53323

class(raw)
[1] "matrix"
现在,我真的不知道为什么会发生这种情况,一个列表矩阵。当在标准列表上执行上述操作时,不会发生

g <- list(list(322000,512000),list(323000,512000),list(325000,514000))
co <- do.call(rbind,g)
str(co)
num [1:3, 1:2] 322000 323000 325000 512000 512000 514000

g好的,我取得了一些成功

从传单.extras中的addDrawToolbar内绘制的功能如下所示:

# line feature of 3 vertices
line_coords <- input$rasmap_draw_new_feature$geometry$coordinates
print(line_coords)
[[1]]
[[1]][[1]]
[1] -3.214188

[[1]][[2]]
[1] 54.55634

[[2]]
[[2]][[1]]
[1] -3.213501

[[2]][[2]]
[1] 54.53383

[[3]]
[[3]][[1]]
[1] -3.185349

[[3]][[2]]
[1] 54.53323

class(line_coords)
"list"

# then rbind the list into a matrix, all fine
raw <- do.call(rbind,line_coords)

print(raw)
    [,1]      [,2]    
[1,] -3.214188 54.55634
[2,] -3.213501 54.53383
[3,] -3.185349 54.53323

class(raw)
[1] "matrix"
现在,我真的不知道为什么会发生这种情况,一个列表矩阵。当在标准列表上执行上述操作时,不会发生

g <- list(list(322000,512000),list(323000,512000),list(325000,514000))
co <- do.call(rbind,g)
str(co)
num [1:3, 1:2] 322000 323000 325000 512000 512000 514000
g我认为与sf相结合可以帮助您。这里有一个小例子(这显然不是严格可复制的,因为你可以画任何你想要的东西)
editMap
返回类
sf
的简单features对象,然后可以将其转换为sp对象

library(mapedit)
library(sf)

drawn = editMap() # zoom to where you wanna draw and draw a line
head(drawn) # a sf LINESTRING object

Simple feature collection with 1 feature and 2 fields
    geometry type:  LINESTRING
    dimension:      XY
    bbox:           xmin: 3.8232 ymin: 46.4076 xmax: 9.0088 ymax: 48.8936
    epsg (SRID):    4326
    proj4string:    +proj=longlat +datum=WGS84 +no_defs
      X_leaflet_id feature_type                       geometry
    1           81     polyline LINESTRING(4.5483 46.9803, ...

drawn_sp = as(drawn, "Spatial") # to convert the LINESTRING to a SpatialLinesDataFrame object.
如果您想在自己的Shining应用程序中利用此功能,请查看@timelyportfolio提供了一个在Shining内部使用
editMap
的示例。

我认为与sf结合使用可以帮到您。这里有一个小例子(这显然不是严格可复制的,因为你可以画任何你想要的东西)
editMap
返回类
sf
的简单features对象,然后可以将其转换为sp对象

library(mapedit)
library(sf)

drawn = editMap() # zoom to where you wanna draw and draw a line
head(drawn) # a sf LINESTRING object

Simple feature collection with 1 feature and 2 fields
    geometry type:  LINESTRING
    dimension:      XY
    bbox:           xmin: 3.8232 ymin: 46.4076 xmax: 9.0088 ymax: 48.8936
    epsg (SRID):    4326
    proj4string:    +proj=longlat +datum=WGS84 +no_defs
      X_leaflet_id feature_type                       geometry
    1           81     polyline LINESTRING(4.5483 46.9803, ...

drawn_sp = as(drawn, "Spatial") # to convert the LINESTRING to a SpatialLinesDataFrame object.

如果您想在自己的Shining应用程序中利用此功能,请查看@timelyportfolio在何处提供了在Shining内部使用
editMap
的示例。

传单.extras作者。返回到闪亮事件的对象是JavaScript端的GeoJSON,我认为它作为列表出现在R端。如果你想要一个空间对象,那么考虑GojJSON/GeJSONIO PKGS将列表转换成SP/SF格式。
Tim关于使用mapedit的建议也是一个很好的建议。mapedit是专门为帮助交互式GIS操作而开发的,就像您正在尝试执行的操作一样。spool.extras为其提供了底层基础,但mapedit提供了更丰富的用户体验。

这里是spool.extras的作者。返回到闪亮事件的对象是JavaScript端的GeoJSON,我认为它作为列表出现在R端。如果你想要一个空间对象,那么考虑GojJSON/GeJSONIO PKGS将列表转换成SP/SF格式。
Tim关于使用mapedit的建议也是一个很好的建议。mapedit是专门为帮助交互式GIS操作而开发的,就像您正在尝试执行的操作一样。传单.extras提供了它的底层基础,但mapedit提供了更丰富的用户体验。

蒂姆,我需要看看你用绘图工具开发了什么。蒂姆,我需要看看你用绘图工具开发了什么geojson注意,
sf::st_read
也可以阅读这些geojson列表。这就是我们在mapedit中使用的内容。感谢您的回答,我将开始研究geojson包以转换为sp格式。我很高兴我用原始的R代码来管理它,但是值得尝试geojson和mapedit。助教!在geojson注释中,
sf::st_read
也可以读取这些geojson列表。这就是我们在mapedit中使用的内容。感谢您的回答,我将开始研究geojson包以转换为sp格式。我很高兴我用原始的R代码来管理它,但是值得尝试geojson和mapedit。助教!
raw <- apply(raw, 2,as.numeric)
str(raw)
num [1:3, 1:2] -3.19 -3.2 -3.17 54.54 54.52 54.51
library(mapedit)
library(sf)

drawn = editMap() # zoom to where you wanna draw and draw a line
head(drawn) # a sf LINESTRING object

Simple feature collection with 1 feature and 2 fields
    geometry type:  LINESTRING
    dimension:      XY
    bbox:           xmin: 3.8232 ymin: 46.4076 xmax: 9.0088 ymax: 48.8936
    epsg (SRID):    4326
    proj4string:    +proj=longlat +datum=WGS84 +no_defs
      X_leaflet_id feature_type                       geometry
    1           81     polyline LINESTRING(4.5483 46.9803, ...

drawn_sp = as(drawn, "Spatial") # to convert the LINESTRING to a SpatialLinesDataFrame object.