tmieno2 / R-as-GIS-for-Economists

This repository has codes for the R as GIS for Economists book including the Rmd files for the book chapters.
https://tmieno2.github.io/R-as-GIS-for-Economists/
49 stars 17 forks source link

Error in UseMethod("st_as_sf") : no applicable method for 'st_as_sf' applied to an object of class "list" #11

Open Mukhtabdi opened 2 years ago

Mukhtabdi commented 2 years ago

Hi Dr Taro Mieno. I am enjoying the book, thanks for providing it for free.

I am practicing chapter 6.0, specifically 6.11:DATASET.

I have an error when creating a regularly-sized grids over Iowa state. I run the chunk of code below: `

I downloaded Iowa state boundaries from another website and tried to create the grid, fortunately I achieved to the grid and when I tried to plot the grid onto the raster, another issue appeared (stars_proxy object shown at 17795 by 11671 cells).

Any suggestion on how to solve this problem, please?

Mukhtabdi commented 2 years ago

I achieved to create the grid, but when I try to plot the it onto the raster, I get this error below:

Code

> tm_shape(IA_cdl_15) +
+   tm_raster(title = "Land Use ") +
+   tm_shape(IA_grids) +
+   tm_polygons(alpha = 0) +
+   tm_layout(legend.outside = TRUE)

Error

Error: Unable to warp stars. You could try with raster.warp = FALSE (argument of tm_shape)
In addition: Warning message:
In fetch(.x, ..., downsample = downsample) :
  with RasterIO defined, argument downsample is ignored
> 
tmieno2 commented 2 years ago

For creating grids, you can use the following code (the book has been updated to use this code).

 IA_grids <-
    tigris::counties(state = "IA", cb = TRUE) %>%
    #--- create regularly-sized grids ---#
    st_make_grid(n = c(50, 50)) %>%
    #--- project to the CRS of the CDL data ---#
    st_transform(terra::crs(IA_cdl_15))

I uploaded IA_cdl_15.tif in the replication data set folder (https://www.dropbox.com/sh/gkprbgp8sg5362f/AABLLEUjsGkelCK2aUxaUI72a?dl=0). Can you try the code for mapping using this file?

Mukhtabdi commented 2 years ago

Thank you for your quick response.

Could not thought that the book is updated. By the way, I got the updated version of the book. Apart from that, I tried to produce the map using the tmap code of the updated version of the book:

+   tm_raster(title = "Land Use ") +
+   tm_shape(IA_grids) +
+   tm_polygons(alpha = 0) +
+   tm_layout(legend.outside = TRUE)

But, couldn't produce the map and the problem still persist:

stars_proxy object shown at 17795 by 11671 cells.
Error: cannot allocate vector of size 792.3 Mb
In addition: Warning message:
In fetch(.x, ..., downsample = downsample) :
  with RasterIO defined, argument downsample is ignored

However, I can produce the map of the grid on the raster using plot() function.

plot(IA_cdl_15)
plot(IA_grids, add = TRUE)

thank you again

tmieno2 commented 2 years ago

It looks like you have a RAM memory issue. This or this may help.

Mukhtabdi commented 2 years ago

Thanks, I will have a look.