The world’s leading publication for data science, AI, and ML professionals.

Spatial Data Science: Data Structures

A guideline for articulating spatial data

Introduction

How do we define spatial data? A formal standard follows the OGC standard on simple features with Well-Known Text (WKT). Most likely, too, this is what most people need. I do not think it is fancy, but the following official document might look scary at first.

Simple Feature Access – Part 1: Common Architectures

Appreciating the document gives us the idea of storing spatial data inside our database. This article is a short introduction to storing spatial data by understanding spatial data structures.

In this article, I will explain how we define spatial data in a WKT format and how it is structured in JSON (Javascript Object Notation). Why JSON? So I can visualise this in Ms Excel for everyone to comprehend. This is not how we store the data in database servers, but it gives the idea of how it is structured.

Well-Known Text

Well-Known Text (WKT) is a standard to define the geometry. I think the Wikipedia article explains how it works very well.

The well-known text representation of geometry – Wikipedia

Spatial data (in this case, let’s stick to simple vector features) consists of coordinates and the type. There are 3 basic types: Point, LineString, and Polygon.

  • Point is the simplest. it is a point; I think it’s self-explanatory. It consists of 1 coordinate.

  • LineString (line), is a line. Bunch of Points compose a Line. You need a minimum of 2 points to compose a line.

  • Polygon, is enclosed LineString. Any line can be converted to a polygon, it is an area.

In the WKT format, we define the type first then, followed by the coordinates that compose the spatial data; for example,

"POLYON (0 0, 1 0, 1 1, 0 1)"

this one is basically a square of 1×1. Please note that I write the WKT as a text file so we can articulate spatial data in Ms Word!

GeoJSON

There is another format, a very much more versatile one, that is the JSON format. GeoJSON is an extension of JSON format, but it is JSON. What is JSON format? JSON is a key-value pair format defined inside a curly bracket. For instance, defining the City of London,

{"city": "london", "country": "UK"}

or Paris,

{"city": "paris", "country": "france"}

and we can put any arbitrary property inside this bracket,

{"city": "berlin", "country": "germany", 
"coordinates": [52.507650, 13.410298]}

hold on a second; I just put location data here! We know that it is a point coordinate. However, we need to dictate it in the JSON data. Therefore, the conclusion,

{"city": "berlin", "country": "germany",
"location" : {
    "type" : "Point",
    "coordinates": [52.507650, 13.410298]
}}

Visualising Spatial Data Structure in Excel

In my other article, I have explained how we can see curly brackets as table rows. We will visualise the data structure in excel by employing JSON format.

Nested Table in Excel

Our previous JSON table of cities looks like the following image.

This is without the spatial data, and now the spatial data (a bunch of coordinates and the definition of which type) is stored as a JSON inside the cell.

or we can add another example of Polygon data for London

and when we visualise London’s polygon’s coordinates, it looks like the following image:

Or we can declare it in WKT format, too, which is simpler for this context.

They all translate to the same data: the cities. However, we can store spatial data in various formats, and they are all still valid.

Conclusion

spatial data is a bunch of coordinates with the defined type (point? Polygon? line?) If we can somehow:

  • define the type and
  • define the coordinates composition,

then we have spatial data. This is where WKT and GeoJSON come in. First, we define which type of geometry, and then we define the coordinates that compose the geometry. With one of the formats, we can declare the spatial property of each feature/row of data we have. They are computer parsable so that we can analyse them with computer software!


Written By

Topics:

Related Articles