Codes are taken from a book Geocomputation with R