When you are ready to process it all, change l by pols and remove that subseting at the end. Pols.join <- left_join(pols,df,by='OBJECTID') # join mean raster value to polygons and show in map # stimated time for 295 features in pols -> +- 74 min # optional -> subset randomly your pols to check if this works and estimate how it will take for the whole process # Function to extract mean raster values in polygons (using parallel processing) Unzip(zipfile = "popden.zip", exdir = 'popden') Here is the code (yours and the function): # rm(list = ls()) #uncomment to clean all environment Join the created ame with the original polygons by the ID.Create a ame with two columns: a selected ID field (specified in the function) and the mean value for the polygon (r_mean).Mean of the values (getting rid of the NaN).In resume, this is what the function does: I just tried with some of your polygons but, as you can see in the last part of the code, in my pc it will take more than an hour to extract all the mean values for all the polygons (in a ryzen 7 3700x using all the cores.). Here I propose a function that works in parallel and speeds up this extraction process. To second suggestion, I updated r_v$extract to run r_v$extract(ken_con_sf, fun=function(x)). It's a little better, but still seems off to me. #rb <- as.numeric(quantile(rdf$den, prob = seq(0, 1, length = 11))) # very slow so commenting out and giving values Here's my new attempt to set breaks and visualize. Ken_con_den_mean <- r_v$extract(ken_con_sf, correctly pointed out that my initial raster plot is not blank. The second problem probably flows from the first: I am not able to extract any data. A national census is a great starting point to map the residents of one nation, but each national census has its own methodology, timing, and aggregation their counts to different (and changing) geographies. The first problem is that the raster plot is blank (but the legend appears). United States population density map by minor civil divisions : 1940, Bureau of the Census, 1942. What I do below is grab the tif, use the raster package to load the file, and extract and average the density values by constituency (an administrative unit) with a shapefile I load. It comes from an effort by Facebook to create population density maps from satellite imagery. The population data source is interesting. I don't do much GIS work, so I'm likely making a rookie mistake here. I get NaN values, but I think my problem is further upstream at the raster level. I'm trying to extract population density data from a raster by shapefile.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |