Skip to content

Instantly share code, notes, and snippets.

@syedmisbah
Last active May 17, 2020 11:00
Show Gist options
  • Save syedmisbah/a26c47c1f8aaff7ceb30d1ad197c0bd0 to your computer and use it in GitHub Desktop.
Save syedmisbah/a26c47c1f8aaff7ceb30d1ad197c0bd0 to your computer and use it in GitHub Desktop.
#SetWD
setwd("C:/Users/misba/Desktop/PROCESS/")
#Load libraires
library(dplyr)
library(raster)
library(rgdal)
library(data.table)
#Read object
raster_object <- raster(tiff_file)
#Extract XY eastings and northing values and population values
population_df <- as.data.frame(raster_object, xy=TRUE)
names(population_df) <- c("X","Y","Population")
#Remove rows with 0 population to reduce size
population_df <- population_df %>% filter(Population!=0)
#Write to dataframe
fwrite(population_df, "XY_POP_DATA_FULL.csv", row.names=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment