You can use the raster
and sf
R packages to do this.
# Install packages (uncomment)
#install.package("raster")
#install.package("sf")
# Load packages
library(raster)
library(sf)
# Read raster data in GeoTIFF format
r <- raster::stack("C:/folder/my_raster.tif")
# Convert RasterStack object into data.frame with XY coordinates
r_df <- as.data.frame(r, xy=TRUE)
# Export data.frame to CSV
write.csv(r_df, "F:/folder/my_raster.csv")
# Read vector data in ESRI Shapefile format
# The geometry column contains the shape of your entities
s <- sf::st_read("C:/folder/my_shape.shp")
# Convert sf object into data.frame
s_df <- data.frame(s)
# Export data.frame to CSV
write.csv(s, "F:/folder/my_shape.csv")
You can use head(r_df)
and head(s_df)
to see the head of your data.