0

生成された Web マップにaddPolylines特定の値の等高線をオーバーレイするために使用していますが、提供されているすべてのデータをプロットしているわけではありません。最初の画像のように、値が125の少なくとも 2 つの領域が明らかですが、リーフレットで生成されたマップには 1 つの領域しか表示されません。データはここからダウンロードでき、SpatialLinesDataFrame オブジェクトを生成する再現可能なスクリプトと、次のようにマップを生成できます。leafletaddPolylines
addPolylinesleaflet

rm(list=ls())
library(leaflet)
library(maptools)

# create a vector of lon, lat, and read data
lon1 <- seq(-124.938,length=59,by=1)
lat1 <- seq(25.063,length=29,by=1)
data1 <- matrix(scan(file="AnnualPrcpValues.txt"),ncol=length(lat1),byrow = T)

## spatial pattern of precipitation
## I choose a value *125* correspond to light yellow color to plot contours on leaflet generated map
## at least two regions corresponds to this value, i.e., Pacific northwest & Southwest region] 
filled.contour(lon1,lat1,data1,color=terrain.colors)

降水パターン

## The following code calculates contour lines correspond to a value *125*
## and then converts contour lines into a SpatialLinesDataFrame object

CL=contourLines(lon1,lat1,data1,levels=c(125))
c.linesSP <- ContourLines2SLDF(CL)

c.linesSP3 本の線の座標がありますが、addPolylines1 つの領域のみの等高線をプロットします

str(coordinates(c.linesSP))

##List of 1
## $ :List of 3
##  ..$ : num [1:17, 1:2] -123 -122 -122 -122 -122 ...
##  ..$ : num [1:5, 1:2] -125 -124 -123 -124 -125 ...
##  ..$ : num [1:9, 1:2] -86.4 -86.9 -87.9 -88.9 -89.9 ...


## leaflet generated map
map1 <- leaflet() %>% addTiles() %>% 
   setView(lng = -80, lat = 40, zoom = 2)
map2<- map1 %>% addPolylines(data=c.linesSP,color="red")

## It should have three lines, but only one line is seen in the Pacific Northwest region
map2

等高線が 1 本の WebMap

## However, contour line in the southwest region is plotted when explicilty co-ordinates, i.e., [[1]] [[3]] are supplied
## 
tempdata <- coordinates(c.linesSP)[[1]][[3]]
map2 %>% addPolylines(tempdata[,1],tempdata[,2],
                         weight=1.25,color="green") %>%
   addMarkers(tempdata[,1],tempdata[,2])

等高線が 2 本ある Web マップ

addPolylines最初に提供されたすべての座標をプロットしない理由は明らかではありません。提案を大歓迎します。

4

1 に答える 1

1

経由で github から最新のリーフレットdevtools::install_github("rstudio/leaflet")バージョンに更新すると、問題が解決するはずです。sessionInfo()あなたのコードがうまく動作する私のものは次のとおりです.3行が表示されます:

R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=de_DE.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] maptools_0.8-39    sp_1.2-3           leaflet_1.0.2.9010

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.8     magrittr_1.5    devtools_1.12.0 xtable_1.8-2    lattice_0.20-34 R6_2.2.0       
 [7] httr_1.2.1      tools_3.3.2     grid_3.3.2      git2r_0.15.0    withr_1.0.2     htmltools_0.3.5
[13] crosstalk_1.0.0 yaml_2.1.14     digest_0.6.10   shiny_0.14.2    htmlwidgets_0.8 curl_2.1       
[19] memoise_1.0.0   mime_0.5        jsonlite_1.1    httpuv_1.3.3    foreign_0.8-67 
于 2016-12-20T14:54:25.303 に答える