consolidate raster code into a helper function