We can now use this to create a statistical model to predict population as a function of nighttime lights. We can now see that each point (point number is stored in ID) now has two values Belize_median_DNB_2014_2018 and Belize_median_POP_2010. # drop any rows where no satellite values were available (missing values are stored as NA) Pop_dnb_df = extract(dnb_pop_stack, random_points_sp, df=TRUE) # df=TRUE i.e. Random_points_sp = as(random_points, "Spatial") # extract funciton needs sp spatial object not sf Unfortunately the function extract can’t use a sf based point file, so we will need to create a copy of sp type, and then use that to do the extraction. In this step we extract the raster stack data to those random points. ![]() Ggplot()+geom_sf(data=blz)+geom_sf(data=random_points,alpha=0.1) Now let’s add the country boundary and overlay the points # visualize boundary and points # alpha controls transparency Random_points = st_sample(x = blz,size=1000 ,type = 'random') After that we will extract the pop and dnb data at those location and use them to create a model of the pop = fn(dnb). In order to do this we need to create a set of random spatial points throughout the country. We are going to want to take a random sample of out population and nighttime lights data. Print(dnb_pop_stack) # class : RasterStack The following code stacks the two images: dnb_pop_stack = stack(dnb, pop) We are essentially creating a two band raster with the first band being nighttime lights DNB and the second being the population data. Since they have the same properties but hold different data it often helps to create a ‘stack’ out of them. One important feature to note here is that both images have the same pixel resolution, same number of rows and columns and the same projection. ![]() # source : /home/mmann/Documents/Github/Belize_GEE_R_Tutorial/Example_Data/Belize_median_DNB_2014_2018.tif ![]() # source : /home/mmann/Documents/Github/Belize_GEE_R_Tutorial/Example_Data/Belize_median_POP_2010.tif pop = raster('./Example_Data/Belize_median_POP_2010.tif') We will read it in, print out a description and plot them. Example_data looks in the Example_Data folder.įirst we will import our population and nighttime lights DNB data. We just need to tell the computer where to look./ backs us out of the current working directory (which is the Tutorials folder) and then. In the following section we are going to use the raster function to import our images.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |