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:


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?


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.