Accessing Google Open Buildings in R

Google has published a huge data set with buildings, found at https://sites.research.google/open-buildings/. The data is available in WKT in CSV files, so it needs some basic processing for visualization. Could I use R to manage the whole process in one go?

This script will:

  • Download a small sample of the data (southern tip of Spain)
  • Unpack the .gz file
  • Read the data
  • Convert WKT geometries to sf objects
  • View the buildings on a map

# Load libraries
library(mapview)
library(R.utils)   # For unpacking .gz files
library(sf)

# Set working directory
setwd("C:\\Eget\\R\\")

# Download file from https://sites.research.google/open-buildings/
url = "https://storage.googleapis.com/open-buildings-data/v3/polygons_s2_level_4_gzip/0d1_buildings.csv.gz"
destfile = "0d1_buildings.csv.gz"
download.file(url, destfile)

# Unpack .gz file
R.utils::gunzip("0d1_buildings.csv.gz")

# Read the unpacked file
csv = read.csv("0d1_buildings.csv", sep=',')

# WKT -> sf object
buildings <- st_as_sf(csv, wkt = "geometry", crs = 4326)

# View result on map
mapview(buildings)

The result? Based on a quick review, my impression is “Not bad, not extraordinary”. Most buildings seem to be found, but the shapes don´t always match, and obviously, it is hard to enrich the building data with attribute data using only satellite imagery.

Polygons seem OK

Polygons ready for a review

Leave a Reply

Your email address will not be published. Required fields are marked *

Please reload

Please Wait