【问题标题】:R - Best Way to Perform Geospatial CalculationsR - 执行地理空间计算的最佳方法
【发布时间】:2018-08-03 20:08:23
【问题描述】:

我正在从事一个项目,我从 API 中提取犯罪数据,并从本质上计算每个预定义网格单元的犯罪密度。我现在通过将 lat 和 lon 放入 data.frame 中,然后计算点中心半径内的点数来做到这一点。由于预定义网格中有数千个点和数千个犯罪点,因此计算量很大。

我想知道是否有更好的方法来计算犯罪密度;我听说光栅可能很有价值?

一些样本数据:

# Create a predefined grid of coordinates
predef.grid <- data.frame(lat = seq(from = 2.0, to = 4.0, by = 0.1),lon = seq(from = 19.0, to = 21.0, by = 0.1))
predef.grid <- expand.grid(predef.grid)

# Create random sample of crime incidents
crime.incidents <- data.frame(lat = rnorm(10, 4),lon = rnorm(10,20))
crime.incidents <- expand.grid(mydata)

# Need to count number of crimes within radius of every point in predef.grid

谢谢!

【问题讨论】:

    标签: r mapping r-raster rgeo-shapefile


    【解决方案1】:
    # Need to count number of crimes within radius of every point in   
    library(raster)
    library(sp)
    
    # predfined raster
    predef.grid <- raster(xmn=2,  # xmin
                      ymn=4,  # ymin
                      xmx=19, # xmax
                      ymx=21, # ymax
                      res=1,  # spatial resolution
                      vals = 1) # cell value
    plot(predef.grid)
    
    # Create random sample of crime incidents
    # points should be a Spatial object of some form, point, etc.
    crime.incidents <- spsample(x = as(extent(predef.grid), 'SpatialPolygons'),
                            n =  100, 
                            type = 'random')
    
    # plot points over grid
    points(crime.incidents, pch = 20)
    
    # count points per cell
    density <- rasterize(crime.incidents, predef.grid, fun='count')
    
    # plot the density 
    plot(density)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-19
      • 2012-12-10
      • 1970-01-01
      • 2014-09-26
      • 2012-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多