2

次のデータを含むファイルを取得しました。

str(dat)
List of 2
 $ x: Named num [1:28643] 2714769 2728569 NA 2728569 2740425 ...
  ..- attr(*, "names")= chr [1:28643] "h" "h" "" "h" ...
 $ y: Named num [1:28643] 925000 925000 NA 925000 925000 ...
  ..- attr(*, "names")= chr [1:28643] "h" "h" "" "h" ...
 - attr(*, "class")= chr [1:2] "bor" "list"

dat$x[1:10]
      h       h               h       h               h       h               h 
2714769 2728569      NA 2728569 2740425      NA 2740425 2751585      NA 2751585 

dat$y[1:10]
      h      h             h      h             h      h             h 
 925000 925000     NA 925000 925000     NA 925000 925000     NA 925000 

class(dat)
"bor"  "list"

table(names(dat$x))
          h 
  479 28164 

table(names(dat$y))
          h 
  479 28164 

plot(dat, type='l') は素敵なマップになります。

38 ページの「R を使用した応用空間データ分析」(Bivand、Pebesma、Gomez-Rubio; Springer 2008) で、S で使用される古い/単純な形式の行「オブジェクト」について読みましたが、これは私のファイルと類似しているようです。 . この形式は、線を「始点、終点、NA」のトリプレットとして定義します。

このフォーマットを知っていますか?どうすればそれをspオブジェクトに変換できますか?

前もって感謝します

4

1 に答える 1

1

あなたの情報に基づいて、ここに行くための1つの可能な方法があります:

データが線を表し、値が各線の終わりを示していると仮定するとNA、次のようにしてデータを空間線に変換できます。

# Creating artificial data for the example
dat <- list()
dat$x <- rnorm(1000) + rep(c(rep(0, 99), NA), 10)
dat$y <- dat$x + rnorm(1000)

# For simplicity, convert to data frame
# (this would be the first step for you to do with your data)
mydat <- data.frame(x = dat$x, y = dat$y)

# Convert each part to a line, using the NA values as breaks
mylines <- list()
last <- 1
for(i in 1:nrow(mydat)){
    if(is.na(mydat$x[i])){
        print(i)
        mylines[[as.character(i)]] <- Lines(Line(mydat[last:(i-1),]), ID = as.character(i))
        last <- i+1
    }
}

# Convert to spatial lines object
mylines <- SpatialLines(mylines)

# Plot to see if it worked
plot(mylines)
于 2012-03-14T09:55:24.767 に答える