R Tutorial: Common types of spatial data

Learn the four spatial data types: points mark house locations, lines connect ordered points like streams, polygons enclose areas like city wards, and rasters are grids predicting house prices. Examples use a Corvallis, Oregon house-sales dataset.
Chapters
The house sales data you have been working with is an example of point data. With point data, our location of points. In our case, a house location and each point has some associated data. In our case, price and house attributes. While point data is common, there are some other types of spatial data that you'll come across. Line data, polygon data and raster data. When the data is associated with a collection of points in a line, we call it line data. To describe the line, we need multiple points and we assume that they are connected with straight lines. The data isn't associated with any single point, but with a whole collection of points. For example, our lines might describe streams, and for each stream we know its name and length. Polygon data occurs when the data is associated with an area. To describe the area, we take a collection of points and join them with lines to enclose a polygon. The data is associated with the enclosed area. For example, a farmer might have polygons that describe as fields. Each polygon might have a name, an area and a crop. Finally, raster data, also called grid data, is a little different. A regular grid is specified by an origin and steps in the X and Y axes. Data is associated with every cell in the grid. This commonly occurs in remote sensing where a satellite is used to image the earth. For example, for each cell in our grid, we might have the type of vegetation it contains, its elevation and slope. To get a feel for these other types of spatial data, in the final exercises for the chapter, you'll work with some polygon and raster data related to the house sales data. In Corvallis, we have wards, areas that define roughly equal numbers of people that are each represented by a councillor on the city council. These wards are described by polygons and provide a useful geographical breakdown of the city. To provide a higher level summary of house sales, the ward sales data frame describes the ward polygons and some summaries at the ward level, like average sales price and number of sales. Polygons are described by a collection of points in this data frame. Each point is a row. Since it takes many rows to describe the shape of a single ward, you can see the summary data is repeated many times. The columns group and order are there to help with two tricky parts of drawing polygons. The first tricky part of drawing polygons is that order matters. The same set of points joined in two different orders, which will result in two different polygons. The second tricky part, a single area, might need multiple polygons to describe it. For example, one of our wards might have two pieces divided by a river or a hole like a lake that is excluded. As an example of raster data, you'll work with output from a model that predicts the price of a three bedroom, two full bathroom, 1,400 square foot dwelling in average condition. This will help us explore which areas are more expensive than others for the same house. In the PREDS dataframe, each row is a cell in a spatial grid over Corvallis. The lawn and LAT columns specify the coordinates at the center of the cell and the predicted price column, the sales price predicted at this location.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







