1 Goal


The goal of this tutorial is to read and plot topological data from .bil files. There are many free sites to get this kind of data and could be useful to learn how to deal with this filetype.


2 Data import


# In this tutorial we are going to use free elevation data obtained from: http://www.earthenv.org/DEM
# We have downloaded the tiles corresponding to the east coast of Spain
library(raster)
## Loading required package: sp
# The data is downloaded as .bil files
# A file with the same name and .hdr extension should exist in the same folder
# A .bil file is stored for different tiles of the earth
# In this case only 4 tiles are needed to create the whole Mediterranean shore of Spain

file1 <- raster(list.files(pattern = ".bil")[1])
file2 <- raster(list.files(pattern = ".bil")[2])
file3 <- raster(list.files(pattern = ".bil")[3])
file4 <- raster(list.files(pattern = ".bil")[4])

3 Merging data and plotting


# In order to plot all the tiles in the same plot we need to merge the data
# Patience, this could take a while
total_map <- merge(file1, file2, file3, file4)

# Now we can plot the shore of Spain, introducing some information in the plot
plot(total_map, main = "Mediterranean shore of Spain",
     xlab = "Longitude", ylab= "Latitude")