Book Image

Geospatial Analysis with SQL

By : Bonny P McClain
Book Image

Geospatial Analysis with SQL

By: Bonny P McClain

Overview of this book

Geospatial analysis is industry agnostic and a powerful tool for answering location questions. Combined with the power of SQL, developers and analysts worldwide rely on database integration to solve real-world spatial problems. This book introduces skills to help you detect and quantify patterns in datasets through data exploration, visualization, data engineering, and the application of analysis and spatial techniques. You will begin by exploring the fundamentals of geospatial analysis where you’ll learn about the importance of geospatial analysis and how location information enhances data exploration. Walter Tobler’s second law of geography states, “the phenomenon external to a geographic area of interest affects what goes on inside.” This quote will be the framework of the geospatial questions we will explore. You’ll then observe the framework of geospatial analysis using SQL while learning to create spatial databases and SQL queries and functions. By the end of this book, you will have an expanded toolbox of analytic skills such as PostGIS and QGIS to explore data questions and analysis of spatial information.
Table of Contents (13 chapters)
Free Chapter
Section 1: Getting Started with Geospatial Analytics
Section 2: SQL for Spatial Analytics

Spatial concepts

Understanding how spatial statements are constructed and how to customize them for your queries is an important task in learning new ways to interact with spatial datasets.


The synopsis of ST_Within includes the following:

boolean ST_Within(geometry A, geometry B);

A true and false determination is provided to determine if geometry A is entirely within geometry B.

You will need to be comfortable with SELECT statements. Consider the following code. I am interested in buildings located within protected areas. I need to SELECT the buildings and would like to identify them by their name and fid. Geopackages often use fid as their unique identifier, although it isn’t often necessary since OSM has its own identification for its features. I grabbed it here as an example. Any unique identifier will work. I ran the following query in pgAdmin.

The name, fid, and geometry (point) are displayed in the output window once you run the code. ST_AsText...