Download as pdf or txt
Download as pdf or txt
You are on page 1of 68

Geospatial Analysis with SQL: A

hands-on guide to performing


geospatial analysis by unlocking the
syntax of spatial SQL Mcclain
Visit to download the full and correct content document:
https://ebookmass.com/product/geospatial-analysis-with-sql-a-hands-on-guide-to-perf
orming-geospatial-analysis-by-unlocking-the-syntax-of-spatial-sql-mcclain/
Geospatial Analysis with SQL

A hands-on guide to performing geospatial analysis by


unlocking the syntax of spatial SQL

Bonny P McClain

BIRMINGHAM—MUMBAI
Geospatial Analysis with SQL
Copyright © 2023 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted
in any form or by any means, without the prior written permission of the publisher, except in the case
of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express
or implied. Neither the author(s), nor Packt Publishing or its dealers and distributors, will be held
liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and
products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot
guarantee the accuracy of this information.

Group Product Manager: Reshma Raman


Publishing Product Manager: Heramb Bhavsar
Content Development Editor: Priyanka Soam
Technical Editor: Rahul Limbachiya
Copy Editor: Safis Editing
Project Coordinator: Farheen Fathima
Proofreader: Safis Editing
Indexer: Hemangini Bari
Production Designer: Alishon Mendonca
Marketing Coordinator: Nivedita Singh

First published: January 2023

Production reference: 4210923

Published by Packt Publishing Ltd.


Grosvenor House
11 St Paul's Square
Birmingham
B3 1RB, UK.

ISBN: 978-1-83508-314-7

www.packtpub.com
To my geospatial colleagues from around the world: thank you for the warm welcome into this vibrant
community—always learning, always curious.

To my husband Steve, and boys Harrison and Ryland—your ongoing support means the oblate
spheroid to me!
Contributors

About the author


Bonny P McClain applies advanced data analytics, including data engineering and geo-enrichment, to
discussions of poverty, race, and gender. Racism, class exploitation, sexism, nationalism, and heterosexism
all contribute to social inequality. Bonny redefines how we measure these attributes and how we can
more accurately identify amenable interventions. Spatial data hosts a variety of physical and cultural
features that reveal distribution patterns and help analysts and data professionals understand the
underlying drivers of these patterns.
Bonny is a popular conference keynote and workshop leader. Her professional goals include exploring
large datasets and curating empathetic answers to larger questions, making a big world seem smaller.
About the reviewers
Kate Mai is a GIS solutions architect who has been in the IT industry for the past 10 years. Her main
focuses are web map application product design and development, geospatial data integration and
management, and system optimization. She is also interested in what the next big thing may be in
the IoT, AI, and GIS.
Thanks to Lily, my puppy. Without her, the review process would’ve been done three times faster.

Lakshmanan Venkatesan is a principal consultant at a leading IT services company based out of


Houston, Texas. During his career, he has led and contributed to the development of location intelligence
software and platforms. He has led digital transformation programs for a large oil company for the past
four years. His technical expertise includes advanced web-based mapping application development,
scripting, model design, system integration, and DevOps/SRE. Research, teaching, and mentoring
are also among his interests.

Emmanuel Jolaiya is a software engineer with a background in remote sensing and GIS from the Federal
University of Technology, Akure, Nigeria. He has consulted for several leading world organizations,
including the World Bank, and currently, he consults for Integration Environment and Energy, a
German-based organization, on the Nigeria Energy Support Programme (NESP), where he uses
geospatial technology to support electrification planning. He is a 2020 YouthMappers Research Fellow
and Esri Young Scholar. As a young innovator, he is currently building Spatial node, a platform where
geospatial professionals can showcase their works and discover opportunities. His current interests
include Docker, spatial SQL, DevOps, and mobile and web GIS.
Table of Contents

Preface xi

Section 1: Getting Started with


Geospatial Analytics
1
Introducing the Fundamentals of Geospatial Analytics 3
Technical requirements 4 Exploring SQL 11
Spatial databases 4 SELECT statements 12
SRIDs 5 WHERE statements 12
CREATE statements 22
Understanding geospatial data types 7
Raster models 10 Summary 25

2
Conceptual Framework for SQL Spatial Data Science – Geometry
Versus Geography 27
Technical requirements 28 Introducing query-based syntax 44
Creating a spatial database 28 Analyzing spatial relationships 45
Options for databases with spatial functions 31 Detecting patterns, anomalies, and
Exploring databases with psql 34 testing hypotheses 47
Importing data 36 Summary 49
Fundamentals of a query-based syntax 39
Changing column names 39
Identifying tables 42
viii Table of Contents

3
Analyzing and Understanding Spatial Algorithms 51
Technical Requirements 51 Reasoning and key decisions about spatial
concepts59
Developing knowledge about
geographic space 52 Exploring pattern detection tools 61
Connecting to databases and Executing SQL queries in QGIS 67
executing SQL queries 53
Summary69

4
An Overview of Spatial Statistics 71
Technical requirements 71 Running queries in QGIS 83
Creating spatial vectors with SQL 72 Building prediction models 91
Renaming table columns – US census 78 Summary97
What do the census table codes mean? 78

Section 2: SQL for Spatial Analytics


5
Using SQL Functions – Spatial and Non-Spatial 101
Technical requirements 101 ST_Within109
Preparing data 102 CREATE VIEW 110
ST_Buffer116
Creating a dataset using the Open Street Map
plugin102 Creating functions in SQL 118
Null values in PostgreSQL 108 Mining areas in Brazil 122
Spatial concepts 109 Summary127
Table of Contents ix

6
Building SQL Queries Visually in a Graphical Query Builder 129
Technical requirements 129 Understanding census-designated places 136
Conditional queries 130 The SQL Query Builder 140

SQL data queries using the graphical Exploring census data in the SQL
query builder 131 Query Builder 144
Aggregation and sorting queries 136 Summary152

7
Exploring PostGIS for Geographic Analysis 153
Technical requirements 154 Importing additional data – power
Configuring and authenticating plants165
PostGIS in QGIS 154 Additional data queries – IS NOT
Loading data into PostGIS 155 NULL167
Importing data into PostGIS 158 Differentiating polygons in OSM data171
Discovering the PgAdmin dashboard 159 Spatial queries 172
Executing SQL queries in pgAdmin 161 Exploring ST_Contains and multi-table joins 173

Summary177

8
Integrating SQL with QGIS 179
Technical Requirements 179 The GEE data catalog plugin 192
Understanding the SQL query Landscape Change Monitoring
builder in QGIS 180 System197
Comparing polygons between two large raster2pgsql198
datasets183 Terminal raster import 198
Raster data 187 Summary205
Installing plugins 189
x Table of Contents

Index207

Other Books You May Enjoy 214


Preface
This book is for learners interested in using SQL and open source platforms for detecting and quantifying
patterns in datasets through data exploration, visualization, data engineering, and the application of
analysis and spatial techniques.
At its core, geospatial technology provides an opportunity to explore location intelligence and how it
informs the data we collect. First, the reader will see the relevance of geographic information systems
(GIS) and geospatial analytics, revealing the fundamental foundation and capabilities of spatial SQL.
Information and instruction will be formatted as case studies that highlight open source data and
analysis across big ideas that you can distill into workable solutions. These vignettes will correlate
with an examination of publicly available datasets selected to demonstrate the power of storytelling
with geospatial insights.
Open source GIS, combined with PostgreSQL database access and plugins that expand QGIS functionality,
have made QGIS integration an important tool for analyzing spatial information.

Who is this book for?


This book is for anyone currently working with data (or hoping to someday) who would like to increase
their efficiency in analysis and discovery by bringing query and spatial analysis to where their data
lives—the database or data warehouse.
Geospatial analysis serves a range of learners across a wide spectrum of skill sets and industries.
This book is mindful of expert data scientists who are just being introduced to geospatial skills, as
well as the geospatial expert discovering SQL and analysis for the first time.

What this book covers


Chapter 1, Introducing the Fundamentals of Geospatial Analytics, introduces the foundational aspects
of spatial databases and data types. This chapter also introduces learners to structured query
language (SQL).
Chapter 2, Conceptual Framework for SQL Spatial Data Science – Geometry Versus Geography, explains
how to create a spatial database to enable you to import datasets and begin analysis. You will also
learn the fundamentals of writing query-based syntax.
xii Preface

Chapter 3, Analyzing and Understanding Spatial Algorithms, shows you how to connect databases
created in pgAdmin to QGIS, where you will learn how to join tables and visualize the output by
selecting layers and viewing them on the QGIS canvas.
Chapter 4, An Overview of Spatial Statistics, covers working with spatial vectors and running SQL
queries while introducing you to US Census datasets.
Chapter 5, Using SQL Functions – Spatial and Non-Spatial, demonstrates how to use spatial statistics
in PostGIS to explore land use characteristics and population data. You will learn how to write a user-
defined function and run the query.
Chapter 6, Building SQL Queries Visually in a Graphical Query Builder, contains examples of how to
access a graphical query builder and begin building more complex frameworks by taking a deeper
dive and bringing together skills learned earlier.
Chapter 7, Exploring PostGIS for Geographic Analysis, looks at pgAdmin more closely to customize
workflows by running SQL queries in pgAdmin and visualizing the output within the geometry viewer.
Chapter 8, Integrating SQL with QGIS, moves spatial queries back to QGIS as you work with DB
Manager and are introduced to raster data and functions.

To get the most out of this book


To work with the datasets presented in this book, you will need to download QGIS (I suggest the
long-term-release (LTR) version, as it is the most stable), pgAdmin, and PostgreSQL.

Software/hardware covered in the book Operating system requirements


QGIS Windows, macOS, or Linux
pgAdmin

PostgreSQL

If you are using the digital version of this book, we advise you to type the code yourself or access
the code from the book’s GitHub repository (a link is available in the next section). Doing so will
help you avoid any potential errors related to the copying and pasting of code.

Download the example code files


You can download the example code files for this book from GitHub at https://github.com/
PacktPublishing/Geospatial-Analysis-with-SQL. If there’s an update to the code,
it will be updated in the GitHub repository.
Preface xiii

Conventions used
There are several text conventions used throughout this book.
Code in text: Indicates code words in the text, folder names, filenames, file extensions, pathnames,
dummy URLs, user input, and Twitter handles. Here is an example: “To explore the mining areas in
Brazil, we can use the ST_Area function.”
A block of code is set as follows:

SELECT row_number() over () AS _uid_,* FROM (SELECT * FROM


getprotecteda('10160475')
) AS _subq_1_

When we wish to draw your attention to a particular part of a code block, the relevant lines or items
are set in bold: “The synopsis of ST_Within includes the following:”

boolean ST_Within(geometry A, geometry B);

Any command-line input or output is written as follows:

Query returned successfully in 129 msec

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words
in menus or dialog boxes appear in bold. Here is an example: “In pgAdmin, we can observe these
results in Geometry Viewer.”

Tips or important notes


Appear like this.

Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at customercare@
packtpub.com and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen.
If you have found a mistake in this book, we would be grateful if you would report this to us. Please
visit www.packtpub.com/support/errata and fill in the form.
xiv Preface

Piracy: If you come across any illegal copies of our works in any form on the internet, we would
be grateful if you would provide us with the location address or website name. Please contact us at
[email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you
are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts


Once you’ve read Geospatial Analysis with SQL., we’d love to hear your thoughts! Please click here
to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we’re delivering
excellent quality content.
Preface xv

Download a free PDF copy of this book


Thanks for purchasing this book!
Do you like to read on the go but are unable to carry your print books everywhere?
Is your eBook purchase not compatible with the device of your choice?
Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.
Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical
books directly into your application.
The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content
in your inbox daily
Follow these simple steps to get the benefits:

1. Scan the QR code or visit the link below

https://packt.link/free-ebook/9781835083147

2. Submit your proof of purchase


3. That’s it! We’ll send your free PDF and other benefits to your email directly
Section 1:
Getting Started with
Geospatial Analytics

Readers will learn how spatial SQL increases efficiency in working with geospatial databases. Also,
prior to analyzing geospatial data, the reader will learn about the frameworks and the distinction
between geometry and geography. This is the primary difference between SQL and spatial SQL.
They will learn about spatial algorithms and will begin integrating GIS functions into a modern SQL
computing environment.
This section has the following chapters:

• Chapter 1, Introducing the Fundamentals of Geospatial Analytics


• Chapter 2, Conceptual Framework for SQL Spatial Data Science – Geometry Versus Geography
• Chapter 3, Analyzing and Understanding Spatial Algorithms
• Chapter 4, An Overview of Spatial Statistics
1
Introducing the Fundamentals
of Geospatial Analytics
Understanding where something happened is often the key to understanding why it occurred in the first
place. A flood wipes out a village in a remote country 1,000 miles away. If you are thinking geospatially,
you are curious about climate forecasting, the demographics of the population, the nature of the soil,
the topography of the land, and building footprints or structures. The ability to point to a spot on a map
is only a small part of data collection. When you begin to think about roads and distances to impacted
villages requiring disaster relief, you would be limited by point-to-point Cartesian geometry. This chapter
will help you to understand why.
The process of detecting and quantifying patterns in datasets requires data exploration, visualization,
data engineering, and the application of analysis and spatial techniques. At its core, geospatial technology
provides an opportunity to explore location intelligence and how it informs the data we collect.
Geospatial information is location data that allows the assessment of geographically linked activities
and locations on the Earth’s surface. Often called the science of “where,” geospatial analysis can provide
insight into events occurring within geographic areas such as flooding but also patterns in the spread of
wildfires and urban heat islands (increased temperatures in cities compared to rural areas).
Collecting and analyzing geographic information may also include non-spatial data providing
opportunities to alter the appearance of a map, based on non-spatial attributes associated with a
location. Attributes in geographic information systems (GIS) refer to data values that describe spatial
entities. For example, perhaps an attribute table stores information not only on the building polygon
footprint but also indicates that the building is a school or residence.
On your map, you may be interested in viewing wastewater treatment plants or buildings complying
with green energy requirements within a city or neighborhood boundary. Although this information
is non-spatial, you can view and label information associated with specific locations. You are able to
direct map applications to render a map layer based on a wide variety of features.
4 Introducing the Fundamentals of Geospatial Analytics

As you learn how to query your data with Structured Query Language (SQL), the advantages will
include flexibility in accessing and analyzing your data. This chapter will introduce SQL and expand
upon concepts throughout the remaining chapters.
Before we explore the syntax of SQL, let’s introduce or review a few concepts unique to geospatial data.
In this chapter, we will cover Installation: pgadmin, postgreSQL, QGIS and will cover the following topics:

• Spatial databases
• Spatial reference identifiers (SRIDs)
• Understanding geospatial data types
• Exploring SQL

First, let’s become familiar with a few characteristics of geospatial data. You will set up working
environments later in the chapter.

Technical requirements
The following are the technical requirements for this chapter:

• PostgreSQL installation for your operating system (macOS, Windows, or Linux)


• PostGIS extension
• pgAdmin
• QGIS
• GitHub link at https://github.com/PacktPublishing/Geospatial-Analysis-
with-SQL

Spatial databases
Geospatial data is vast and often resides in databases or data warehouses. Data stored in a filesystem
is only accessible through your local computer and is limited to the speed and efficiency of your
work space. Collecting and analyzing geographic information within storage systems of relationally
structured data increases efficiency.
Spatial databases are optimized for storing and retrieving your data. Data stored in databases are
accessed through client software. The client is a computer or hostname (where the database is located).
Next, the server listens for requests on a port. There are a variety of ports, but with PostgreSQL,
the default is 5432—but more on that later. The final pieces of information are about security and
accessibility. You will select a username and password to access the database. Now, the client has all
SRIDs 5

it needs to access the database. The data within a database is formatted as tables and resides with the
host either locally or in an external server linked to a port that listens for requests. This book will
focus on local instances with a mention or two about other options in later chapters.
SQL is a standardization for interacting with databases that abides by American National Standards
Institute (ANSI) data standards. Additionally, SQL has also been adopted as the international standard
by the International Organization for Standardization (ISO), the International Electrotechnical
Commission (IEC), and the Federal Information Processing Standard (FIPS).

SRIDs
Each spatial instance or location has an SRID due to the earth being a non-standard ellipsoid. We
talk about the surface of the earth, but what does this mean exactly? Do we plunge to the depths of
the ocean floor or the highest mountains? The surface of the earth varies depending on where you
are on the surface of the earth.
Spatial reference systems (SRS) allow you to compare different maps. If they are superimposable,
they have the identical SRS. The European Petroleum Survey Group (EPSG) is the most popular.
Figure 1.1 visually demonstrates the discrepancy in mapping distances on the surface of the earth.
Rotational forces at the poles flatten the earth, creating bulging at the equator. This phenomenon
complicates the accurate calculation of the distance between two points located at different latitudes
and longitudes on the Earth’s surface. The coordinate system helps to standardize spatial instances:

Figure 1.1 – Ellipsoid shape of the earth


6 Introducing the Fundamentals of Geospatial Analytics

When working with location data, the use of reference ellipsoids helps to specify point coordinates
such as latitude and longitude, for example. The Global Positioning System (GPS) is based on the
World Geodetic System (WGS 84). You will notice different IDs based on the types of datasets you
are working with—EPSG 4326 is for WGS 84. WGS 84 is the most used worldwide. A spatial column
within a dataset can contain objects with different SRIDs, however, only spatial instances with the
same SRID can be used when performing operations with SQL Server spatial data methods. Luckily,
PostgreSQL will raise an exception when an incompatibility is detected.
SRIDs are stored in a Postgres table visible in the public schema named spatial_ref_sys. You
can discover all of the SRIDs available within PostGIS (the spatial extension for PostgreSQL) with
the following SQL query:

SELECT * FROM spatial_ref_sys

If you look down the column in Figure 1.2, you will notice EPSG 4326 but also a sample of other
SRIDs available:

Figure 1.2 – PostGIS SRID

Figure 1.3 shows the SRID for data in the NYC database. These are two distinct datasets, but you can
see how variation in SRID might be a problem if you would like to combine data from one table with
data in another. When working with a graphical user interface (GUI) such as QGIS, for example,
SRIDs are often automatically recognized.
Understanding geospatial data types 7

Figure 1.3 – SRID for NYC database

You can check the geometry and SRID of the tables in your database by executing the command in the
query that follows. Don’t worry if this is your first time writing SQL queries—these early statements
are simply for context. The dataset included here is a standard practice dataset, but imagine if you
wanted to combine this data with another dataset in a real-world project:

SELECT * FROM geometry_columns;

Next to the srid column in Figure 1.3, you can see geometry types. The next section will introduce
you to the different geometries.

Understanding geospatial data types


To understand how to work with geospatial data and the functions available to answer data questions,
we will explore different data types. Geospatial geometries are represented by polygons, points, and
lines that indicate features and attributes such as census blocks, subway station locations, and roadways.
They are vector models as they are representative of real-world areas (polygons), locations (points),
or linear data such as transportation networks or drainage networks (lines).
Collectively, we call these different geometries vector data. Think of two-dimensional space as x- and
y-coordinates when thinking about a specific geometry. Geography represents data on a round-earth
coordinate system as latitude and longitude. I tend to use geometry as the convention across the board
but will clarify when relevant. You will see actual data in this chapter, but it is simply illustrative. In
later chapters, you will use a data resource, but until then, if you would like to explore, the data in
this chapter can be found at NYC Open Data: https://opendata.cityofnewyork.us/.
8 Introducing the Fundamentals of Geospatial Analytics

Figure 1.4 displays the output of a query below written to explore the geometry of our data. In spatial
queries, geometry is simply another data type in addition to the types we might be familiar with—
integer, string, or float. This becomes important when exploring non-spatial data such as demographics.
When performing analyses, the data type is relevant as only integer and floating numbers can be used
with mathematical functions. Not to worry—there are options to transform numerical properties
into integers when needed. You are also able to identify where your table is located (schema) and the
name of your geometry column (you will need this information when referring to the geometry in
a table). Additional information visible includes the dimensions (two dimensions), the SRID values,
and the data type.

Figure 1.4 – Discovering the geometric types in your data

In the type column in Figure 1.4, we see three unique types: MULTIPOLYGON, POINT, and
MULTILINESTRING. Geospatial data is most often represented by two primary categories: vector
data and raster data.
Roadways are visible in Figure 1.5 as lines or multiline strings. These are a collection of Line-
String geometries:
Understanding geospatial data types 9

Figure 1.5 – NYC boroughs with shapes and lines

Figure 1.6 displays the five NYC boroughs with neighborhoods shown as polygons. The points
represent subway stations. These are a few examples of how vector geometries are displayed. Most of
these features are customizable, as we will see when exploring layer options and symbology in QGIS.
10 Introducing the Fundamentals of Geospatial Analytics

Figure 1.6 – Map of NYC visualizing points, lines, and polygons

Another data type we will be exploring later is raster data. Although PostGIS has raster extensions
and functions available, you will need to visualize the output in QGIS. For now, let’s understand the
characteristics of raster data.

Raster models
Raster data is organized as a collection or grid. Each cell contains a value. Bands are collected as
boolean or numerical values coordinating per pixel. Briefly, multidimensional arrays of pixels or picture
elements in images are basic units of programmable information. What is measured is actually the
intensity of the pixel within a band. The data is in the bands. The intensity varies depending on the
relative reflected light energy for that element of the image. Raster data is often considered continuous
data. Unlike the points, lines, and polygons of vector data, raster data represents the slope of a surface,
elevation, precipitation, or temperature, for example. Analyzing raster data requires advanced analytics
that will be introduced in Chapter 8, Integrating SQL with QGIS. Figure 1.7 is displaying Cape Town,
South Africa as a digital elevation model(DEM). The darker areas represent lower elevations:
Exploring SQL 11

Figure 1.7 – Raster image of Shuttle Radar Topography Mission (SRTM)


elevation and digital topography over Cape Town, South Africa

The complex composition in Figure 1.7 is representative of raster images and the detailed gradations
visible in land use, scanned maps or photographs, and satellite imagery. Raster data is often used as
a basemap for feature layers, as you will see in QGIS.
Let's use a few simple SQL queries to understand geographical data. PostgreSQL is the open source
relational database management system (RDBMS) you will explore in addition to PostGIS—the spatial
extension—and QGIS, an open source GIS application. You may be familiar with commercial offerings
such as Oracle, SQL Server, or SQLite. Open source PostgreSQL has the PostGIS spatial extension,
which easily transforms data for different projections and works with a wide variety of geometries.

Exploring SQL
Let’s get a feel for the capabilities and advantages of working with datasets in a spatial database. SQL
is described as a declarative programming language. If you have experience in a coding environment,
this might be a fairly big departure.
12 Introducing the Fundamentals of Geospatial Analytics

In a declarative programming language, you write what you want to do, and the program figures it
out. SQL is a query language that sends queries to manipulate and retrieve data from the database. In
an object-oriented programming (OOP) language such as Python, for example, you need to specify
system calls incorporating libraries and various packages. Although Python’s syntax is readable, a
familiarity with built-in data structures, powerful libraries, frameworks, and a relative commitment
to scripting expertise is required. PostgreSQL includes extensions to write procedures in additional
programming languages such as Python and R, for example, but the focus here is on SQL and spatial SQL.
In Figure 1.8, you will see a simple SQL statement. Statements have clauses, (SELECT, FROM, or
WHERE), expressions, and predicates. Although capitalization is a common practice to assist in
readability, SQL is not case-sensitive.
First, let’s examine the statement in more detail. The data is from the Department of Environmental
Protection (DEP) publicly available data (https://data.cityofnewyork.us/City-
Government/DEP-s-Citywide-Parcel-Based-Impervious-Area-GIS-St/
uex9-rfq8). The objective is to examine NYC-wide parcel-based impervious surfaces. In geospatial
analysis, the structure and characteristics of land use, land cover, and surfaces are often explored.
Impervious surfaces describe hard surfaces—primarily man-made—that prevent rainwater from
reaching groundwater or flowing into waterways and contribute to increased surface temperatures
in urban cities. Asphalt parking lots, concrete, and compacted soil in urbanized development are
familiar examples.

SELECT statements
Entering SELECT * FROM public."table name" in the code displays all of the columns
in the table. The asterisk saves time as you will not need to ask for all of the columns by name. They
will all be returned with the query. Looking at the query in the pgAdmin console in figure 1.8, FROM
MN_pIAPP after the SELECT statement is referring to the table of percent impervious surfaces in
the borough of Manhattan in NYC.
Often when referring to your table in a SQL query, double quotes will be needed with single quotes
referring to the values in a column. When you use lowercase as the default, there is an option to omit
the double quotes, for example, renaming the table as mn_piapp.

WHERE statements
The WHERE statement introduces an expression, to return values less than 47.32. The statement
will return values for surfaces less than 47.32% impervious. If the predicate is True, the value will
be returned in the table. A predicate evaluates which rows are returned in a specific query. Figure 1.8
illustrates the impervious surfaces in the geometry viewer in pgAdmin:
Exploring SQL 13

Figure 1.8 – Viewing Manhattan impervious surfaces in Geometry Viewer in pgAdmin

The impervious surfaces are highlighted in the graphic viewer. The output is surfaces less than 47.32%
impervious. Change the percentage, and the output will update once you run the following code and
view the previous graphical image:

SELECT * FROM public."MN_pIApp" WHERE "Percent_Impv" < 47.32

The polygons are visible, but what about our basemap? In our GUI, pgAdmin (introduced next in the
chapter), we are able to see a basemap if we transform the coordinates to the 4326 SRS or SRID. This is
because of a reliance on OpenStreetMap projected in 3857, and it will also yield a basemap if this is the
SRID of your data (https://www.openstreetmap.org/#map=5/38.007/-95.844). QGIS
is a far more powerful visualization tool, and you will explore the PostGIS integration in later chapters.
This may be updated to include other projections by the publication of the book so be on the look-out.
14 Introducing the Fundamentals of Geospatial Analytics

ST_Transform is a SQL expression allowing you to assign a different SRID once we have the SRID
changed to 4326:

SELECT ST_Transform (geom,4326) AS geom,*


FROM public."MN_pIApp" WHERE "Percent_Impv" < 47.32

We are able to view the basemap in Geometry Viewer in pgAdmin, shown in Figure 1.9:

Figure 1.9 – Viewing Manhattan impervious surfaces in Geometry Viewer in pgAdmin with a basemap

The rapidly expanding field of geospatial analytics is evolving across a wide variety of disciplines,
specialties, and even programming languages. The potential insights and deeper queries will likely be
at the forefront of skill acquisition; however, it is critical that you first explore fundamental geospatial
techniques regardless of your preferred computer language or even if you currently aren’t working
within a particular coding practice.
Exploring SQL 15

This book will assume no prior knowledge in either programming or geospatial technology, but at
the same time offers professionals anywhere the ability to dive deeper into detecting and quantifying
patterns visible through data exploration, visualization, data engineering, and the application of
analysis and spatial techniques.
At its core, geospatial technology provides an opportunity to explore location intelligence and how it
informs the data we collect. To get started, you will first need to download a few tools.

Installation of PostgreSQL

PostgreSQL is an open source relational database server with multiple ways to connect. PostgreSQL is
also known as Postgres, and I will be referring to the database server as Postgres. Remember—“client”
is another word for computer or host. You can access Postgres with a command line in terminal
for macOS or in the command line in Windows, through programming languages such as Python
or R, or by using a GUI. You will be running Postgres locally and will need both the client and the
server (Postgres).
Installation instructions here are specific for macOS but are also pretty straightforward for other
operating systems. Download from https://www.postgresql.org/ to select system-specific
options, as shown in Figure 1.10:

Figure 1.10 – PostgreSQL download options


16 Introducing the Fundamentals of Geospatial Analytics

Selecting your operating system of choice will yield a series of options. The Postgres.app installation
for macOS also includes PostGIS, which is the spatial data extension. The examples that follow do
not utilize the interactive installer. As I am working on a late model operating system, the potential
incompatibilities down the road pointed toward using Postgres.app. There are advantages either
way, and you can make a choice that works best for your workflow.
When I first began working with PostgreSQL, I noticed many resources for Windows-compatible
installations—they are everywhere—but what was lacking, it seemed, was instruction for those of us
working with macOS. The focus here will be primarily on macOS because there is not a compatible
import function directly for macOS at the time of this printing.
See the following tip box for the EnterpriseDB (EDB) PostgreSQL installer information and other
downloads selected for the installer option.

Tip
The installer option will download a setup wizard to walk through the steps of the installation.
EDB includes additional extensions to simplify the use of PostgreSQL but for now, download
the software onto your local computer.

Windows users and even macOS operating systems can opt for the installation wizard. Follow these
steps to set up the installation:

1. Navigate to the option shown in Figure 1.11 if you are selecting this option:

Figure 1.11 – EDB installer for PostgreSQL


Exploring SQL 17

2. Stack Builder simplifies downloading datasets and other features we will explore. You can see
it being launched in Figure 1.12:

Figure 1.12 – Launching Stack Builder located inside the PostgreSQL application folder

Depending on your setup options or work environment, select the components you would like
to download, as given in Figure 1.13.
3. Select the four default components, as shown in Figure 1.13:

Figure 1.13 – Default components in the installation wizard


18 Introducing the Fundamentals of Geospatial Analytics

Windows has an extensive presence for guiding the installation and a separate installer that includes
pgAdmin for managing and developing PostgreSQL, and Stack Builder. Stack Builder is also available
in the interactive installer for macOS, but the utility may depend on which version of macOS you
have installed.
Unless you are connecting to an existing server or host, localhost should be entered, as seen in
Figure 1.14. Regardless of your selection of operating system, the default port is 5432. This setting
can be changed, but I would suggest keeping the default unless there is a compelling reason to create
a different port—for example, if it is already in use. The superuser is postgres. This identity is a
superuser because you will have access to all of the databases created. You would customize this if
different databases had different authorization and access criteria. Select your password carefully for
the database superuser. It is a master password that you will need again.

Figure 1.14 – Creating a server instance in Postgres


Exploring SQL 19

Now that you have a database server installed locally (downloaded to your computer), you will need
a GUI management tool to interact with Postgres. Only a single instance of Postgres is able to run on
each port, but you can have more than one open connection to the same database.

Installation of pgAdmin

pgAdmin is the GUI selected as a graphical interface or command-line interface (CLI) for writing and
executing SQL commands. This is by no means the only option, but pgAdmin works across operating
systems and is available for download here: https://www.pgAdmin.org/.
Follow the next steps to complete the installation:

1. Drag the pgAdmin icon to the applications folder, and voilà! Do not rename the file.
2. Figure 1.15 shows the dashboard you will see once you download the software:

Figure 1.15 – pgAdmin web application for managing PostgreSQL

3. After logging in to pgAdmin, you will add a server.


4. Next, you will need a name for your server, as shown in Figure 1.16. You have the ability to add
servers as needed. The default settings are fine, and the default is Postgres:
20 Introducing the Fundamentals of Geospatial Analytics

Figure 1.16 – Setting up your server in pgAdmin

In the later chapters, you will learn more about pgAdmin properties and the browser. The objective
here is to install and create a working environment for exploring geospatial data using spatial SQL.
Here are the steps to achieve this:

1. The default database, Postgres, is already loaded in Figure 1.17, but let’s create a new one.
2. Right-click on Databases, and you will see the option to create a new database. Figure 1.17 shows
the steps for adding a database. You are able to customize, but for now, this is introductory for
familiarizing you with options. When selecting a longer name, you will need to use underscores
between words—for example, long_database_name:

Figure 1.17 – Creating a new database in pgAdmin

By default, the new database defaults to a public schema, as shown in Figure 1.18. Schemas can be
customized, as you will see. The tables and functions folders are also empty. The PostGIS extension has
not been added yet and will need to be integrated with each database to introduce spatial functionality:
Exploring SQL 21

Figure 1.18 – Customizing databases in pgAdmin

The PostGIS extension will need to be added to each database you create.
22 Introducing the Fundamentals of Geospatial Analytics

CREATE statements
Let’s go through the following set of instructions:

1. Select the Extensions option, right-click, and then write CREATE EXTENSION postgis
into the query tool, as shown in Figure 1.19.
2. Click the arrow and run the cell. You will see the extension added on the left once you click
Extensions and select Refresh.
3. Also, add CREATE EXTENSION postgis_raster as we will need this extension when
we work with raster models. Be certain to refresh after running the code:

Figure 1.19 – Adding extensions to the database

4. Returning to the Functions option, we now see 1171 functions have been added. Figure 1.20
shows a few of the new spatial functions updated once the PostGIS spatial extension has been
added to the database. You will also observe a spatial-ref_sys table has been added.
Explore the columns and note the available SRIDs within the database:
Exploring SQL 23

Figure 1.20 – Spatial functions have been populated in the database

You are now ready to begin working with spatial SQL in the Postgres database.

QGIS

QGIS is an open source GIS. Although you will be able to view maps on the pgAdmin dashboard,
the advanced capabilities of GIS viewing of maps, ease of data capture, and ability to integrate with
Postgres will be explored. Download QGIS to your desktop to complete the installation of tools by
using the following link: https://qgis.org/en/site/index.html. Figure 1.21 is the same
map created earlier in the graphical interface in pgAdmin rendered in QGIS.

Figure 1.21 – Downloading QGIS

Installing QGIS is straightforward, and we will customize it as we go. It is often recommended to look
for the long-term-release (LTR) version as it has the most stability.
Figure 1.22 demonstrates the additional viewing capabilities when QGIS renders the output of the
same query and the same data.
24 Introducing the Fundamentals of Geospatial Analytics

Figure 1.22 – QGIS map showing the location of where in Manhattan


the percentage of impervious soil < 47.32

Let’s summarize the chapter now.


Summary 25

Summary
In this chapter, you were introduced to geospatial fundamentals to help understand the graphical
syntax of spatial data science. You discovered a few SQL basic queries and set up your workflow for
the chapters that follow. Important concepts about the properties and characteristics of vector and
raster data were also introduced.
In Chapter 2, Conceptual Framework for SQL Spatial Data Science – Geometry Versus Geography, you
will begin learning about SQL by working with the database you created in this chapter.
The fundamentals of a query-based syntax will become clearer as you discover spatial functions for
discovering patterns and testing hypotheses in the datasets.
2
Conceptual Framework for
SQL Spatial Data Science –
Geometry Versus Geography
Before analyzing geospatial data, you will need to learn about the frameworks of spatial analysis and
the important distinction between geometry and geography. This is the primary difference between
SQL and spatial SQL and is an important consideration when bringing data together from different
datasets and—potentially—different SRIDs. Think about the difference between a map of bike rental
locations your hotel might provide while you are visiting from out of town. Perhaps a local graphic
designer creates it to show you sketches of the nearby ice cream shop and other amenities within a
few blocks of your location. How easy do you think it would be to superimpose this map with perhaps
one you brought with you from a local visitors center on your drive into town?
This is the same challenge when bringing multiple datasets together. We need to have confidence in
our source of “truth.”
In this chapter, we will explore the challenges of bringing datasets together, learn about a few psql
meta-commands in terminal, begin writing SQL functions, and begin to think spatially. Specifically,
we will be covering the following topics:

• Creating a spatial database


• Importing data
• Fundamentals of a query-based syntax
• Analyzing spatial relationships
• Detecting patterns, anomalies, and testing hypotheses
28 Conceptual Framework for SQL Spatial Data Science – Geometry Versus Geography

Technical requirements
I invite you to find your own data if you are comfortable or access the data recommended in this
book’s GitHub repository at: https://github.com/PacktPublishing/Geospatial-Analysis-with-SQL.
The following datasets are being used in the examples in this chapter:

• NYC Open Data: https://opendata.cityofnewyork.us


• DOHMH Indoor Environmental Complaints: DOHMH Indoor Environmental Complaints
• Census Reporter: https://censusreporter.org/2020/
• Neighborhood Tabulation Areas: 2020 Neighborhood Tabulation Areas (NTAs)—tabular (https://
opendata.cityofnewyork.us/)

Creating a spatial database


In Chapter 1, Introducing the Fundamentals of Geospatial Analytics, maybe you created a database. If
you were simply following along, you will need to create a database for working through the examples
in the book. As a refresher, let’s create another to hold the data for this chapter. You will use this
database to explore the components of working with PostGIS and spatial data.
This is how you do it:

1. Simply right-click the database name you created and scroll to Query Tool. Figure 2.1 shows
the other options available. You will explore these in later chapters, but for now, Delete/Drop
is how you delete a database, Refresh will update the database (important when we add files
in QGIS), and View/Edit Data will render a table in your console. If you simply want to see
the column headings, a quick look at Properties is helpful:
Another random document with
no related content on Scribd:
PLATE LXXII

MEADOW-BEAUTY.—R. Virginica.

Of the plant in the late year, Thoreau writes: “The scarlet leaves
and stem of the rhexia, sometime out of flower, make almost as
bright a patch in the meadows now as the flowers did. Its seed-
vessels are perfect little cream-pitchers of graceful form.”

Clammy Cuphea. Wax-weed.


Cuphea viscosissima. Loosestrife Family.

Stem.—Sticky, hairy, branching. Leaves.—Usually opposite, rounded, lance-


shaped. Flowers.—Deep purplish-pink, solitary or in racemes. Calyx.—Tubular,
slightly spurred at the base on the upper side, six-toothed at the apex, usually with
a slight projection between each tooth. Corolla.—Small, of six unequal petals.
Stamens.—Eleven or twelve, of unequal sizes, in two sets. Pistil.—One, with a two-
lobed stigma.
In the dry fields and along the roadsides of late summer this
plant is found in blossom. Its rather wrinkled purplish-pink petals
and unequal stamens suggest the flowers of the spiked loosestrife, L.
Salicaria, to which it is closely related.

Sea Pink.
Sabbatia stellaris. Gentian Family.

Stem.—Slender, loosely branched. Leaves.—Opposite, oblong to lance-shaped,


the upper narrowly linear. Flowers.—Large, deep pure pink to almost white. Calyx.
—Usually five-parted, the lobes long and slender. Corolla.—Usually five-parted,
conspicuously marked with red and yellow in the centre. Stamens.—Usually five.
Pistil.—One, with two-cleft style.
The advancing year has few fairer sights to show us than a salt
meadow flushed with these radiant blossoms. They are so abundant,
so deep-hued, so delicate! One feels tempted to lie down among the
pale grasses and rosy stars in the sunshine of the August morning
and drink his fill of their beauty. How often nature tries to the
utmost our capacity of appreciation and leaves us still insatiate! At
such times it is almost a relief to turn from the mere contemplation
of beauty to the study of its structure; it rests our overstrained
faculties.
PLATE LXXIII

SEA PINK.—S. stellaris.

The vivid coloring and conspicuous marking of these flowers


indicate that they aim to attract certain members of the insect world.
As in the fireweed the pistil of the freshly opened blossom is curved
sideways, with its lobes so closed and twisted as to be inaccessible on
their stigmatic surfaces to the pollen which the already mature
stamens are discharging. When the effete anthers give evidence that
they are hors de combat by their withered appearance, the style
erects itself and spreads its stigmas.
S. angularis is a species which may be found in rich soil inland.
Its somewhat heart-shaped, clasping, five-nerved leaves and angled
stem serve to identify it.
S. chloroides is a larger and peculiarly beautiful species which
borders brackish ponds along the coast. Its corolla is about two
inches broad and eight to twelve-parted.

Marsh St. John’s-wort.


Elodes campanulata. St. John’s-wort Family.

Stem.—One or two feet high, often pinkish, later bright red. Leaves.—
Opposite, set close to the stem or clasping by a broad base. Flowers.—Pinkish or
flesh-color, small, closely clustered at the summit of the stem and in the axils of the
leaves. Calyx.—Of five sepals, often pinkish. Corolla.—Of five petals. Stamens.—
Nine, in three sets, the sets separated by orange-colored glands. Pistil.—One, with
three styles.
If one has been so unlucky, from the usual point of view, or so
fortunate, looking at the matter with the eyes of the flower-lover, as
to find himself in a rich marsh early in August, his eye is likely to fall
upon the small, pretty pinkish flowers and pale clasping leaves of the
marsh St. John’s-wort. A closer inspection will discover that the
foliage is dotted with the pellucid glands, and that the stamens are
clustered in groups after the family fashion. Should the same marsh
be visited a few weeks later dashes of vivid color will guide one to the
spot where the little pink flowers were found. In their place glow the
conspicuous ovaries and bright leaves which make the plant very
noticeable in late August.
Elodes is a corruption from a Greek word which signifies
growing in marshes.
PLATE LXXIV

Sabbatia chloroides.

Rose Mallow. Swamp Mallow.


Hibiscus Moscheutos. Mallow Family.

Stem.—Stout and tall, four to eight feet high. Leaves.—The lower three-lobed,
the upper oblong, whitish and downy beneath. Flowers.—Large and showy, pink.
Calyx.—Five-cleft, with a row of narrow bractlets beneath. Corolla.—Of five large
petals. Stamens.—Many, on a tube which encloses the lower part of the style.
Pistils.—Five, united into one, with five stigmas which are like pin-heads.
When the beautiful rose mallow slowly unfolds her pink banner-
like petals and admits the eager bee to her stores of golden pollen,
then we feel that the summer is far advanced. As truly as the wood
anemone and the blood-root seem filled with the essence of spring
and the promise of the opening year, so does this stately flower glow
with the maturity and fulfilment of late summer. Here is none of the
timorousness of the early blossoms which peep shyly out, as if ready
to beat a hasty retreat should a late frost overtake them, but rather a
calm assurance that the time is ripe, and that the salt marshes and
brackish ponds are only awaiting their rosy lining.
The marsh mallow, whose roots yield the mucilaginous
substance utilized in the well-known confection, is Althæa
officinalis, an emigrant from Europe. It is a much less common plant
than the Hibiscus, its pale pink flowers being found in some of the
salt marshes of New England and New York.
The common mallow, Malva rotundifolia, which overruns the
country dooryards and village waysides, is a little plant with
rounded, heart-shaped leaves and small purplish flowers. It is used
by the country people for various medicinal purposes and is
cultivated and commonly boiled with meat in Egypt. Job pictures
himself as being despised by those who had been themselves so
destitute as to “cut up mallows by the bushes ... for their meat.”[7]
PLATE LXXV

ROSE MALLOW.—H. Moscheutos.

Salt Marsh Fleabane.


Pluchea camphorata. Composite Family (p. 13).

Stem.—Two to five feet high. Leaves.—Pale, thickish, oblong or lance-shaped,


toothed. Flower-heads.—Pink, small, in flat-topped clusters, composed entirely of
tubular flowers.
In the salt marshes where we find the starry sea pinks and the
feathery sea lavender, we notice a pallid-looking plant whose pink
flower-buds are long in opening. It is late summer or autumn before
the salt marsh fleabane is fairly in blossom. There is a strong
fragrance to the plant which hardly suggests camphor, despite its
specific title.
Hairy Willow-herb.
Epilobium hirsutum. Evening Primrose Family.

Three to five feet high. Stem.—Densely hairy, stout, branching. Leaves.—


Mostly opposite, lance-oblong, finely toothed. Flower.—Purplish, pink, small, in
the axils of the upper leaves, or in a leafy, short raceme. Calyx.—Four or five-
parted. Corolla.—Of four petals. Stamens.—Eight. Pistil.—One, with a four-parted
stigma.
The hairy willow-herb is found in waste places, blossoming in
midsummer. It is an emigrant from Europe.

Fireweed. Great Willow-herb.


Epilobium angustifolium. Evening Primrose Family.

Stem.—Four to seven feet high. Leaves.—Scattered, lance-shaped, willow-like.


Flowers.—Purplish-pink, large, in a long raceme. Calyx.—Four-cleft. Corolla.—Of
four petals. Stamens.—Eight. Pistil.—One, with a four-lobed stigma.
In midsummer this striking plant begins to mass its deep-hued
blossoms along the roadsides and low meadows. It is supposed to
flourish with especial abundance in land that has newly been burned
over; hence, its common name of fireweed. Its willow-like foliage has
given it its other English title. The likeness between the blossoms of
this plant and those of the evening primrose betray their kinship.
When the stamens of the fireweed first mature and discharge their
pollen the still immature style is curved backward and downward
with its stigmas closed. Later it straightens and lengthens to its full
dimensions, so spreading its four stigmas as to be in position to
receive the pollen of another flower from the visiting bee.
PLATE LXXVI

FIREWEED.—E. angustifolium.

——— ———
Epilobium coloratum. Evening Primrose Family.

One to three feet high. Leaves.—Rather large, lance-shaped, sharply toothed.


Flowers.—Pale pink, small, more or less nodding, resembling in structure those of
the hairy willow-herb. Pistil.—One, with a club-shaped stigma.
This species is found in abundance in wet places in summer.
Purple Gerardia.
Gerardia purpurea. Figwort Family.

Stem.—One to four feet high, widely branching. Leaves.—Linear, sharply


pointed. Flowers.—Bright purplish-pink, rather large. Calyx.—Five-toothed.
Corolla.—One inch long, somewhat tubular, swelling above, with five more or less
unequal, spreading lobes, often downy and spotted within. Stamens.—Four, in
pairs, hairy. Pistil.—One.
In late summer and early autumn these pretty noticeable flowers
brighten the low-lying ground along the coast and in the
neighborhood of the Great Lakes. The sandy fields of New England
and Long Island are oftentimes a vivid mass of color owing to their
delicate blossoms. The plant varies somewhat in the size of its
flowers and in the manner of its growth.
The little seaside gerardia, G. maritima, is from four inches to a
foot high. Its smaller blossoms are also found in salt marshes.
The slender gerardia, G. tenuifolia, is common in mountainous
regions. The leaves of this species are exceedingly narrow. Like the
false foxglove (Pl. LIX.) and other members of this genus, these
plants are supposed to be parasitic in their habits.

Joe-Pye-weed. Trumpet-weed.
Eupatorium purpureum. Composite Family (p. 13).

Stem.—Stout and tall, two to twelve feet high, often dotted. Leaves.—In whorls
of three to six, oblong or oval, pointed, rough, veiny, toothed. Flower-heads.—
Purplish-pink, small, composed entirely of tubular blossoms, with long protruding
styles, growing in large clusters at or near the summit of the stem.
PLATE LXXVII

JOE-PYE-WEED.—E. purpureum.

The summer is nearly over when the tall, conspicuous Joe-Pye-


weed begins to tinge with “crushed raspberry” the lowlands through
which we pass. In parts of the country it is nearly as common as the
golden-rods and asters which appear at about the same season. With
the deep purple of the iron-weed it gives variety to the intense hues
which herald the coming of autumn.
“Joe Pye” is said to have been the name of an Indian who cured
typhus fever in New England by means of this plant. The tiny
trumpet-shaped blossoms which make up the flower-heads may have
suggested the other common name.

Pink Knotweed.
Polygonum Pennsylvanicum. Buckwheat Family.
One to four feet high. Stem.—Branching. Leaves.—Alternate, lance-shaped.
Flowers.—Bright pink, growing in thick, short, erect spikes. Calyx.—Mostly five-
parted, the divisions petal-like, pink. Corolla.—None. Stamens.—Usually eight.
Pistil.—One, with a two-cleft style.
In late summer this plant can hardly escape notice. Its erect pink
spikes direct attention to some neglected corner in the garden or
brighten the fields and roadsides. The rosy divisions of the calyx
persist till after the fruit has formed, pressing closely against the
dark seed-vessel within.

Sand Knotweed.
Polygonella articulata. (Formerly Polygonum articulatum.)
Buckwheat Family.

Erect, branching, four to twelve inches high. Leaves.—Linear, inconspicuous.


Flowers.—Rose-color, nodding, in very slender racemes. Calyx.—Five-parted.
Corolla.—None. Stamens.—Eight. Pistil.—One, with three styles.
Under date of September 26th, Thoreau writes: “The
Polygonum articulatum, giving a rosy tinge to Jenny’s desert, is very
interesting now, with its slender dense racemes of rose-tinted
flowers, apparently without leaves, rising cleanly out of the sand. It
looks warm and brave, a foot or more high, and mingled with
deciduous blue curls. It is much divided, with many spreading,
slender-racemed branches, with inconspicuous linear leaves,
reminding me, both by its form and its colors, of a peach-orchard in
blossom, especially when the sunlight falls on it; minute rose-tinted
flowers that brave the frosts, and advance the summer into fall,
warming with their color sandy hill-sides and deserts, like the glow
of evening reflected on the sand, apparently all flower and no leaf.
Rising apparently with clean bare stems from the sand, it spreads out
into this graceful head of slender, rosy racemes, wisp-like. This little
desert of less than an acre blushes with it.”

Note.—The Moss Pink, Phlox subulata, with purple-pink flowers, and Phlox
glaberrima, with pink or whitish flowers, will be found in the Blue and Purple
section (p. 235). The Mountain Laurel (p. 57) and the American Rhododendron (p.
60) are frequently found bearing pink flowers. At times it has been difficult to
determine whether certain flowers should be described in the Pink or in the Purple
section. The reader should bear this in mind, consulting both in dubious cases.
IV
RED

Wild Columbine.
Aquilegia Canadensis. Crowfoot Family.

Twelve to eighteen inches high. Stem.—Branching. Leaves.—Much-divided,


the leaflets lobed. Flowers.—Large, bright red, yellow within, nodding. Calyx.—Of
five red petal-like sepals. Corolla.—Of five petals in the form of large hollow spurs,
which are red without and yellow within. Stamens.—Numerous. Pistils.—Five, with
slender styles.

—A woodland walk,
A quest of river-grapes, a mocking thrush,
A wild-rose or rock-loving columbine,
Salve my worst wounds,

declares Emerson; and while perhaps few among us are able to make
so light-hearted and sweeping a claim for ourselves, yet many will
admit the soothing power of which the woods and fields know the
secret, and will own that the ordinary annoyances of life may be held
more or less in abeyance by one who lives in close sympathy with
nature.
About the columbine there is a daring loveliness which stamps it
on the memories of even those who are not ordinarily minute
observers. It contrives to secure a foothold in the most precipitous
and uncertain of nooks, its jewel-like flowers gleaming from their
lofty perches with a graceful insouciance which awakens our
sportsmanlike instincts and fires us with the ambition to equal it in
daring and make its loveliness our own. Perhaps it is as well if our
greediness be foiled and we get a tumble for our pains, for no flower
loses more with its surroundings than the columbine. Indeed, these
destructive tendencies which are strong within most of us generally
defeat themselves by decreasing our pleasure in a blossom the
moment we have ruthlessly and without purpose snatched it from its
environment. If we honestly wish to study its structure, or to bring
into our homes for preservation a bit of the woods’ loveliness, its
interest and beauty are sure to repay us. But how many pluck every
striking flower they see only to toss it carelessly aside when they
reach their destination, if they have not already dropped it by the
way. Surely if in such small matters sense and self-control were
inculcated in children, more would grow up to the poet’s standard of
worthiness:

PLATE LXXVIII

WILD COLUMBINE.—A. Canadensis.

Hast thou named all the birds without a gun?


Loved the wood-rose and left it on its stalk?
At rich men’s tables eaten bread and pulse?
Unarmed, faced danger with a heart of trust?
And loved so well a high behavior,
In man or maid, that thou from speech refrained,
Nobility more nobly to repay?
O, be my friend, and teach me to be thine![8]

The name of columbine is derived from colomba—a dove, but its


significance is disputed. Some believe that it was associated with the
bird-like claws of the blossom; while Dr. Prior maintains that it
refers to the “resemblance of its nectaries to the heads of pigeons in a
ring around a dish, a favorite device of ancient artists.”
The meaning of the generic title is also doubtful. Gray derives it
from aquilegus—water-drawing, but gives no further explanation,
while other writers claim that it is from aquila, an eagle, seeing a
likeness to the talons of an eagle in the curved nectaries.

Wake Robin. Birthroot.


Trillium erectum. Lily Family.

Stem.—Stout, from a tuber-like rootstock. Leaves.—Broadly ovate, three in a


whorl a short distance below the flower. Flower.—Single, terminal, usually
purplish-red, occasionally whitish, pinkish, or greenish, on an erect or somewhat
inclined flower-stalk. Calyx.—Of three green spreading sepals. Corolla.—Of three
large lance-shaped petals. Stamens.—Six. Pistil.—One, with three large spreading
stigmas. Fruit.—A large, ovate, six-angled reddish berry.
PLATE LXXIX

WAKE ROBIN.—T. erectum.

This wake robin is one of the few self-assertive flowers of the


early year. Its contemporaries act as if somewhat uncertain as to
whether the spring had really come to stay, but no such lack of
confidence possesses our brilliant young friend, who almost flaunts
her lurid petals in your face, as if to force upon you the welcome
news that the time of birds and flowers is at hand. Pretty and
suggestive as is the common name, it is hardly appropriate, as the
robins have been on the alert for many days before our flower unfurls
its crimson signal. Its odor is most unpleasant. Its reddish fruit is
noticeable in the woods of late summer.
The sessile trillium, T. sessile, has no separate flower-stalk, its
red or greenish blossom being set close to the stem-leaves. Its petals
are narrower, and its leaves are often blotched or spotted. Its berry is
globular, six-angled, and red or purplish.
The wake robins are native to North America, only one species
being found just beyond the boundaries in the Russian territory.

Wood Betony. Lousewort.


Pedicularis Canadensis. Figwort Family.

Stems.—Clustered, five to twelve inches high. Leaves.—The lower ones deeply


incised, the upper less so. Flowers.—Yellow and red, growing in a short dense
spike. Calyx.—Of one piece split in front. Corolla.—Two-lipped, the narrow upper
lip arched, the lower three-lobed. Stamens.—Four. Pistil.—One.
The bright flowers of the wood betony are found in our May
woods, often in the company of the columbine and yellow violet.
Near Philadelphia they are said to be among the very earliest of the
flowers, coming soon after the trailing arbutus. In the later year the
plant attracts attention by its uncouth spikes of brown seed-pods.
Few wayside weeds have been accredited with greater virtue
than the ancient betony, which a celebrated Roman physician
claimed could cure forty-seven different disorders. The Roman
proverb, “Sell your coat and buy betony,” seems to imply that the
plant did not flourish so abundantly along the Appian Way as it does
by our American roadsides. Unfortunately we are reluctantly forced
to believe once more that our native flower is not identical with the
classic one, but that it has received its common name through some
superficial resemblance to the original betony or Betonica.

Painted Cup.
Castilleia coccinea. Figwort Family.

Stem.—Hairy, six inches to a foot high. Root-leaves.—Clustered, oblong. Stem-


leaves.—Incised, those among the flowers three to five-cleft, bright scarlet toward
the summit, showy. Flowers.—Pale yellow, spiked. Calyx.—Tubular, flattened.
Corolla.—Two-lipped, its upper lip long and narrow, its lower short and three-
lobed. Stamens.—Four, unequal. Pistil.—One.

——Scarlet tufts
Are glowing in the green like flakes of fire;
The wanderers of the prairie know them well,
And call that brilliant flower the painted cup.[9]

But we need not go to the prairie in order to see this plant, for it
is equally abundant in certain low sandy New England meadows as
well as in the near vicinity of New York City. Under date of June 3d,
Thoreau graphically describes its appearance near Concord, Mass.:
“The painted cup is in its prime. It reddens the meadow, painted-cup
meadow. It is a splendid show of brilliant scarlet, the color of the
cardinal-flower, and surpassing it in mass and profusion.... I do not
like the name. It does not remind me of a cup, rather of a flame when
it first appears. It might be called flame flower, or scarlet tip. Here is
a large meadow full of it, and yet very few in the town have ever seen
it. It is startling to see a leaf thus brilliantly painted, as if its tip were
dipped into some scarlet tincture, surpassing most flowers in
intensity of color.”

Wood Lily. Wild Red Lily.


Lilium Philadelphicum. Lily Family.

Stem.—Two to three feet high. Leaves.—Whorled or scattered, narrowly lance-


shaped. Flower.—Erect, orange-red or scarlet, spotted with purple. Perianth.—Of
six erect narrowly clawed sepals, with nectar-bearing furrows at their base.
Stamens.—Six. Pistil.—One, with three-lobed stigma.
Here and there in the shadowy woods is a vivid dash of color
made by some wild red lily which has caught a stray sunbeam in its
glowing cup. The purple spots on its sepals guide the greedy bee to
the nectar at their base; we too can take the hint and reap a sweet
reward if we will, after which we are more in sympathy with those
eager, humming bees.
This erect, deep-hued flower is so different from its nodding
sister of the meadows, that we wonder that the two should be so
often confused. When seen away from its surroundings it has less
charm perhaps than either the yellow or the Turk’s cap lily; but when
it rears itself in the cool depths of its woodland home we feel the
uniqueness of its beauty.
Turk’s Cap Lily.
Lilium superbum. Lily Family.

Stem.—Three to seven feet high. Leaves.—Lance-shaped, the lower whorled.


Flowers.—Orange or scarlet, with purple spots within, three inches long, from
three to forty growing in pyramidal clusters. Perianth.—Of six strongly recurved
sepals. Stamens.—Six, with long anthers. Pistil.—One, with a three-lobed stigma.

Consider the lilies of the field, how they grow;


They toil not, neither do they spin;
And yet I say unto you, that even Solomon in all his glory
Was not arrayed like one of these.

How they come back to us, the beautiful hackneyed lines, and
flash into our memories with new significance of meaning when we
chance suddenly upon a meadow bordered with these the most
gorgeous of our wild flowers.
We might doubt whether our native lilies at all resembled those
alluded to in the scriptural passage, if we did not know that a nearly
allied species grew abundantly in Palestine; for we have reason to
believe that lily was a title freely applied by many Oriental poets to
any beautiful flower.
Perhaps this plant never attains far inland the same luxuriance
of growth which is common to it in some of the New England
lowlands near the coast. Its radiant, nodding blossoms are seen in
great profusion as we travel by rail from New York to Boston.

You might also like