用作as.linnet对象的数据框对象 [英] data frame object to use as as.linnet object

查看:84
本文介绍了用作as.linnet对象的数据框对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个data.frame对象,可以轻松地将其转换为 spatialpointdataframe ,然后将其转换为 spatiallinesdataframe ,但是当我尝试覆盖 as.linnet 不会读取标记

I have a data.frame object which I can easily convert to a spatialpointdataframe then convert that to a spatiallinesdataframe but then when I tried to cover to a as.linnet it does not read marks

         X       Y roadID
1 177321.3 3378163      1
2 177321.4 3378168      1
3 177321.4 3378168      1
4 177321.5 3378177      1
5 177321.5 3378186      1
6 177321.5 3378195      1

然后将这个data.frame制作为SpatialPointsDataFrame

then I make this data.frame to a SpatialPointsDataFrame

coordinates(roaDF1) <- c("X","Y")
proj4string(roaDF1)=proj4string(trtrtt)

class       : SpatialPointsDataFrame 
features    : 100412 
extent      : 143516.4, 213981, 3353367, 3399153  (xmin, xmax, ymin, ymax)
crs         : +proj=utm +zone=17 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
variables   : 1
names       : roadID 
min values  :      1 
max values  :    347 

然后使用SpatialPointsDataFrame转换SpatialLinesDataFrame(在线找到此代码)

then using SpatialPointsDataFrame to convert a SpatialLinesDataFrame ( found this code online )

LineXX <- lapply(split(roaDF1, roaDF1$roadID), function(x) Lines(list(Line(coordinates(x))), x$roadID[1L]))

linesXY <- SpatialLines(LineXX)
data <- data.frame(roadID = unique(roaDF1$roadID))
rownames(data) <- data$roadID
lxy <- SpatialLinesDataFrame(linesXY, data)
proj4string(lxy)=proj4string(trtrtt)

现在lxy看起来像这样

now lxy looks like this

> lxy
class       : SpatialLinesDataFrame 
features    : 347 
extent      : 143516.4, 213981, 3353367, 3399153  (xmin, xmax, ymin, ymax)
crs         : +proj=utm +zone=17 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
variables   : 1
names       : roadID 
min values  :      1 
max values  :    347 

最后,我想将此lxy与一个linnet对象协调起来

finally I want to concert this lxy to a linnet object

> W3.orig=as.linnet(lxy)
Warning messages:
1: In spatstat::linnet(vertices = V, edges = edges, sparse = TRUE) :
  edge list should not join a vertex to itself; ignored
2: In as.linnet.SpatialLines(lxy) :
  Internal error: could not map data frame to lines

不是因为 roaDF1 具有100421功能,当我将其设置为20K时,它仍然会给出相同的错误.

it is not because roaDF1 has 100421 features when I make it 20K it still gives the same error.

有什么帮助吗?

推荐答案

之所以发生这种情况,是因为线坐标数据包含重复的顶点(即,坐标数据的两个连续行是相同的).

This is occurring because the line coordinate data include repeated vertices (i.e. two successive rows of coordinate data are identical).

有一条有关将顶点连接到自身"的警告消息,这是一个重要提示.

There is a warning message about 'joining a vertex to itself' which is an important hint.

尽管该消息说这已被忽略"(即删除了重复的顶点),但是用于处理标记的代码未能处理该问题,并给出了第二次警告并放弃了.

Although the message says that this was 'ignored' (i.e. repeated vertices were deleted), the code for handling marks has failed to handle this, and it gives the second warning and gives up.

我将为as.linnet.SpatialLines写一个修复程序来处理重复的顶点.您仍然会收到警告!

I will write a fix for as.linnet.SpatialLines to handle repeated vertices. You will still get the warning!

PS:已将maptools::as.linnet.SpatialLines的修复程序提交给maptools的维护者,我希望它会包含在下一发行版中.

PS: a fix for maptools::as.linnet.SpatialLines has been submitted to the maintainers of maptools and I expect it will be included in the next release.

这篇关于用作as.linnet对象的数据框对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆