Book Image

Mastering Geospatial Analysis with Python

By : Silas Toms, Paul Crickard, Eric van Rees
Book Image

Mastering Geospatial Analysis with Python

By: Silas Toms, Paul Crickard, Eric van Rees

Overview of this book

Python comes with a host of open source libraries and tools that help you work on professional geoprocessing tasks without investing in expensive tools. This book will introduce Python developers, both new and experienced, to a variety of new code libraries that have been developed to perform geospatial analysis, statistical analysis, and data management. This book will use examples and code snippets that will help explain how Python 3 differs from Python 2, and how these new code libraries can be used to solve age-old problems in geospatial analysis. You will begin by understanding what geoprocessing is and explore the tools and libraries that Python 3 offers. You will then learn to use Python code libraries to read and write geospatial data. You will then learn to perform geospatial queries within databases and learn PyQGIS to automate analysis within the QGIS mapping suite. Moving forward, you will explore the newly released ArcGIS API for Python and ArcGIS Online to perform geospatial analysis and create ArcGIS Online web maps. Further, you will deep dive into Python Geospatial web frameworks and learn to create a geospatial REST API.
Table of Contents (23 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
7
Geoprocessing with Geodatabases
Index

Working with PostgreSQL and PostGIS using Python


To connect and manipulate your PostgreSQL database in Python, you will need a library to assist you. psyscopg2is that library. It provides a wrapper around the official libpq client library. In this section, we will cover how to install the library, how to connect to the database, and how to add a table and perform basic geospatial queries.

Connecting to PostgreSQL using psycopg2

pscycopg2 is the most popular library for working with PostgreSQL in Python. It fully implements the Python DB API 2.0 specificationand works with Python 3. In the following sections, you will learn how to install the library, make connections, execute queries, and read the results. You can read the full documentation here: http://initd.org/psycopg/docs/

Installing psycopg2

Installing most Python libraries requires you to open your console and type:

pip install psycopg2

If that doesn't work, and you are using an Anaconda Python distribution, you can run the conda command...