Professional Documents
Culture Documents
Geospatial Analysis With SQL A Hands On Guide To Performing Geospatial Analysis by Unlocking The Syntax of Spatial SQL Mcclain Full Chapter
Geospatial Analysis With SQL A Hands On Guide To Performing Geospatial Analysis by Unlocking The Syntax of Spatial SQL Mcclain Full Chapter
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.
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
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
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
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
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.
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.
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:
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:”
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.”
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.
https://packt.link/free-ebook/9781835083147
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:
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:
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:
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:
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.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
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:
Next to the srid column in Figure 1.3, you can see geometry types. The next section will introduce
you to the different geometries.
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.
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.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
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
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
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:
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:
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:
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:
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:
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.
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:
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:
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
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:
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
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.
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
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:
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:
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.”
Sea Pink.
Sabbatia stellaris. Gentian 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.
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
FIREWEED.—E. angustifolium.
——— ———
Epilobium coloratum. Evening Primrose Family.
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.
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.
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.
—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
Painted Cup.
Castilleia coccinea. Figwort Family.
——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.”
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.