1

I have a high-resolution (10m cell size) raster of soils data for a US state. Pixel values are the map unit key (mukey) from gSSURGO. Every soil type has a unique mukey, but a given mukey can occur in one or more counties within a state.

I am trying to merge data into this raster attribute table, but the data I'm trying to merge has unique values for each mukey in each county that mukey occurs in. Consequently, I cannot make the merge until I first add a county field into the raster attribute table.

My current approach to doing this is to raster::rasterize a polygon .shp file of the state's counties to the same resolution as the gSSURGO data. Since the cell sizes are SO small, however, this is taking in incredible amount of time. Even with 8 cores on a fast machine...

Is there another good way to do this?!

I prefer to do this with R, but can use ArcMap instead if that can do it more quickly.

Here is the R code I am using for the raster::rasterize approach in parallel. I found this approach here. With this approach I was able to process one county on each of my 8 cores in 1.5 hours. And I've got a whole country to do!

IL_soils_raster <- raster("MapunitRaster_IL_10m.tif")
us_county_polygons <- readOGR("cb_2016_us_county_500k/cb_2016_us_county_500k.shp")

IL_county_polygons <- us_county_polygons[us_county_polygons$STATEFP == 17,]
IL_county_polygons  <- spTransform(IL_county_polygons, CRS = crs(state_soils_raster))

cl <- makeCluster(detectCores())
clusterEvalQ(cl, {library(raster)})
clusterExport(cl, list("ST_counties", "st_soils"))
rParts <- parLapply(cl = cl, 
                    X = 1:nrow(IL_county_polygons[,]), 
                    fun = function(x) rasterize(IL_county_polygons[parts[[x]],], IL_soils_raster, 'COUNTYFP'))
stopCluster(cl)
ST_counties_raster <- do.call(merge, rParts)
  • can you post the code you're using please? This sounds like a familiar problem... – obrl_soil Jul 10 '17 at 22:02
  • original post updated with code above. – Kevin Jul 11 '17 at 0:47
  • Hmm ok. So after rasterising, what's your end goal? Soil attribute rasters mapped out by each soil type? Soil attributes for each soil type that vary by county? – obrl_soil Jul 11 '17 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.