Geospatial Analysis with SQL: A hands-on guide to performing geospatial analysis by unlocking the syntax of spatial SQL Mcclaindownload
Geospatial Analysis with SQL: A hands-on guide to performing geospatial analysis by unlocking the syntax of spatial SQL Mcclaindownload
https://ebookmass.com/product/geospatial-analysis-with-sql-a-
hands-on-guide-to-performing-geospatial-analysis-by-unlocking-
the-syntax-of-spatial-sql-mcclain/
https://ebookmass.com/product/a-guide-to-sql-10th-edition-mark-
shellman/
https://ebookmass.com/product/geospatial-data-analytics-on-aws-1st-
edition-scott-bateman/
https://ebookmass.com/product/getting-started-with-sql-and-databases-
managing-and-manipulating-data-with-sql-mark-simon/
https://ebookmass.com/product/getting-started-with-sql-and-databases-
managing-and-manipulating-data-with-sql-1st-edition-mark-simon/
https://ebookmass.com/product/spatial-analysis-john-t-kent/
https://ebookmass.com/product/spatial-analysis-john-t-kent-2/
Geospatial Analysis with 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.
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
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
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
copyright@packt.com 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:
— On.
— Jumala auttakoon!
Hän huokasi.
"Oh! nyt tiedän mitä se on!" ajatteli hän, "kun antaa vaan vallan,
niin kyllä sitten pääsee menoon! Sitten on rakkaus jo valmis:
hullutusta vaan! Setä on oikeassa. Mutta eläimen tunne ei saa minua
houkutelluksi — ei, siihen saakka minä en alennu."
Tuotiin rommia.
Niin ajattelee suurin osa naisista ja suurin osa pettää niitä, jotka
uskovat tätä sireenin laulua. Mutta Aleksander ei ollut mitään
huomaavinaan. Hän puheli tytön kanssa niinkuin olisi puhellut
ystävän tahi sedän kanssa: ei ollut merkkiäkään siitä hellyydestä,
joka vastoin tahtoakin hiipii miehen ja naisen ystävyyteen ja
vaikuttaa ettei niiden välit ole ystävyyden kaltaisia. Senpävuoksi
sanotaankin, ettei miehen ja naisen välillä ole eikä voi ollakaan
ystävyyttä, että se niiden välinen ystävyys — ei ole muuta kuin alku
tahi loppu rakkaudesta eli viimeksi oikeata rakkautta. Mutta
katsellessa Adujewin käytöstä Liisaa kohtaan, olisi voinut uskoa, että
semmoinen ystävyys on olemassa.
Liisa pahastui.
Liisa oli ääneti, mutta näytti siltä kuin hän olisi ajatellut "voiko se
tulla kysymykseen, ettei haluta?"
— Mitä, Jumalani?
— Pitää!
— Minkätähden?
"Vai niin! Siis jo!" ajatteli Aleksander, "en odottanut näin pian".
Sitten hän purskahti suureen nauruun.
ebookmasss.com