Skip to content

GeoTIFF raster values "reasonable" with raster extract but all NA velox extract #40

Description

@turbomam

I'm cross posting this from the GIS Stack Exchange: https://gis.stackexchange.com/questions/314950/all-geotiff-raster-values-na-after-converting-to-velox


I'm able to extract average tree cover values for each of the three small counties in the US State of Delaware, but I don't seem to have enough CPU or RAM to do the same thing for all counties in the US.

I'm getting my tree cover data from https://prd-tnm.s3.amazonaws.com/StagedProducts/Small-scale/data/LandCover/tree48i0100a.tif_nt00840.tar.gz. See also https://www.sciencebase.gov/catalog/item/581d0548e4b08da350d52653

library(raster)
library(tigris)

tigris.state.counties <- counties(state = 10)
tree.raster <-
  raster("tree48i0100a.tif")

polygon.trees <-
  extract(tree.raster,
          tigris.state.counties,
          fun = mean,
          na.rm = TRUE)

report <-
  cbind.data.frame(tigris.state.counties$NAME, polygon.trees)

print(report)

  tigris.state.counties$NAME polygon.trees
1                 New Castle      70.75920
2                     Sussex      68.17089
3                       Kent      67.00225


So I have set up an R environment on a 64 GB AWS instance, and I'm trying to take advantage of the velox fast extraction. But all of the values I extract are NA.

What am I doing wrong?

UPDATE: I still get NAs even if I use the small polygon option

FWIW, I was able to replicate the [velox extract tutorial][2] and even modify it to get the night light intensity in the Delaware counties.

My attempt to extract tree cover in Delaware counties with velox:

library(velox)
library(tigris)

tree.velox <- velox("tree48i0100a.tif")

tigris.state.counties <- counties(state = 10)

tree.mean.mat <-
  tree.velox$extract(
    sp = tigris.state.counties,
    fun = function(x)
      mean(x, na.rm = TRUE)
  )

report <-
  cbind.data.frame(tigris.state.counties$NAME, tree.mean.mat)

print(report)

     tigris.state.counties$NAME tree.mean.mat
591                  New Castle            NA
1150                     Sussex            NA
2861                       Kent            NA

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions