R raster / rasterize creating GeoTIFF with Null Value "grid lines"

I am attempting the seemingly simple task of converting a .csv with lat, lon and population values into a .tif (raster).

Here's my R code:

    geoName <- read.csv("/pathToData/geoName.csv")
    geoName_raster <- raster(xmn=min(geoName$longitude), xmx=max(geoName$longitude), ymn=min(geoName$latitude), ymx=max(geoName$latitude), res=0.0027, crs="+proj=longlat +datum=WGS84")
    geoName_rasterize <- rasterize(geoName[, c('longitude', 'latitude')], geoName_raster, geoName[, 'population'], fun=sum)
    writeRaster(geoName_rasterize, "/pathToData/geoName_rasterize.tif")

The .csv is formatted like this:

    longitude,latitude,population
    -73.274688427539,19.817098050328,100.001
    -72.697905721098,19.82226569178,200.002
    -73.153838375345,19.799009402678,300.003
    -72.71163913536,19.873934311831,400.004
    -72.887420723946,19.863602053517,500.005
    -73.288421351258,19.850685573779,400.004
    -72.752838665811,19.79384121785,300.003
    -72.939605787255,19.871351380997,200.002
    -73.126372968453,19.713707358991,100.001

The output has bands of null values which appear to be influenced by the res value: the bands are further apart as res approaches 0.

  • The .tif with narrow bands below is with no res specified
    no  option
  • The .tif with wide bands is with res = 0.0027 (which is the approximate width in degrees of a Bing tile at z17 which is the resolution of the population data set)
    res = 0.0027

I've read a few different R documentation pages outlining resolution, but I don't really understand its function.

My questions: what is res doing and how do I replace these bands with the data which belongs in those pixels?

Be gentle: I'm very new to R.

1 Like

What package are you using? I guess res is just the accuracy of the conversion of long lat to geographic location. So with higher 'res you're getting some rounding error. Maybe the option is there to speed up the conversion if you need to. Just make res smaller?

Looks like the raster package?


https://www.neonscience.org/raster-res-extent-pixels-r

Or could it be rounding error in the input data?

1 Like

@woodward - Thanks for responding. You're correct, I'm using:

  • raster package
  • raster function in that package with res option
  • rasterize function in that package
  • writeRaster function in that package

If you hit the link above for res you'll see the explanation is thin. I have experimented with using smaller values, but that just lessens the problem, not eliminate it.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.