在网格中提取数据经度和纬度

时间:2017-03-28 23:22:59

标签: r

我在纽约的纬度和经度方面有出租车提货数据 1.我希望将数据离散化为2km的网格,并使用每个网格中的数据进行进一步的计算 2.代码应灵活,以便在需要时轻松更改网格大小 3.

样品提货数据 -

pickup_longitude    pickup_latitude
-73.9903717 40.73469543
-73.98078156    40.7299118
-73.98455048    40.67956543
-73.99346924    40.71899033
-73.96062469    40.78133011
-73.9801178 40.74304962
-73.9940567 40.71998978
-73.97942352    40.74461365
-73.94715118    40.79104614
-73.99834442    40.72389603
-74.00614929    40.74491882
-73.96932983    40.76353836
-73.9890213 40.72153854
-74.00430298    40.74224091
-73.99199677    40.71857834
-73.98516083    40.76895142
-73.97309113    40.79536057
-73.98210144    40.77469635
-73.99484253    40.71849823
-73.95303345    40.67211533
-73.98916626    40.7265892
-73.99906921    40.72017288
-73.99713898    40.74721909
-73.99741364    40.73667526

我使用过光栅包并尝试创建网格。我希望可视化网格,并运行循环以从网格中收集数据 纬度(40.757295,40.817147)和经度(-73.994057-73.929255)

  min_lat <- 40.5774
 max_lat <- 40.9176
 min_long <- -74.15
   max_long <- -73.7004

  #make raster
  size_raster <- 3/110.574 #
  nlat <- ceiling((max_lat - min_lat)/size_raster)
     r <- raster(ncol=nlat, xmn=min_long, ymn=min_lat, xmx=max_long,           ymx=max_lat)
  ncol(r) <- nlat
  nrow(r) <- nlat
  r[] <- 0
  ngrid <- nlat^2

0 个答案:

没有答案