Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Geospatial Development Essentials

You're reading from   Python Geospatial Development Essentials Utilize Python with open source libraries to build a lightweight, portable, and customizable GIS desktop application

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher
ISBN-13 9781782175407
Length 192 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Karim Bahgat Karim Bahgat
Author Profile Icon Karim Bahgat
Karim Bahgat
Arrow right icon
View More author details
Toc

Imagining the roadmap ahead

Before we begin developing our application, it is important that we create a vision of how we want to structure our application. In Python terms, we will be creating a multilevel package with various subpackages and submodules to take care of different parts of our functionality, independently of any user interface. Only on top of this underlying functionality do we create the visual user interface as a way to access and run that underlying code. This way, we build a solid system, and allow power-users to access all the same functionality via Python scripting for greater automation and efficiency, as exists for ArcGIS and QGIS.

To setup the main Python package behind our application, create a new folder called pythongis anywhere on your computer. For Python to be able to interpret the folder pythongis as an importable package, it needs to find a file named __init__.py in that folder. Perform the following steps:

  1. Open Python IDLE from the Windows start menu.
  2. The first window to pop up is the interactive shell. To open the script editing window click on File and New.
  3. Click on File and then Save As.
  4. In the dialog window that pops up, browse into the pythongis folder, type __init__.py as the filename, and click on Save.

There are two main types of GIS data: vector (coordinate-based geometries such as points, lines, and polygons) and raster (a regularly spaced out grid of data points or cells, similar to an image and its pixels).

Tip

For a more detailed introduction to the differences between vector and raster data, and other basic GIS concepts, we refer the reader to the book Learning Geospatial Analysis with Python, by Joel Lawhead. You can find this book at:

https://www.packtpub.com/application-development/learning-geospatial-analysis-python

Since vector and raster data are so fundamentally different in all regards, we split our package in two, one for vector and one for raster. Using the same method as earlier, we create two new subpackage folders within the pythongis package; one called vector and one called raster (each with the same aforementioned empty __init__.py file). Thus, the structure of our package will look as follows (note that : package is not part of the folder name):

Imagining the roadmap ahead

To make our new vector and raster subpackages importable by our top level pythongis package, we need to add the following relative import statements in pythongis/__init__.py:

from . import vector
from . import raster

Throughout the course of this book, we will build the functionality of these two data types as a set of Python modules in their respective folders. Eventually, we want to end up with a GIS application that has only the most basic of geospatial tools so that we will be able to load, save, manage, visualize, and overlay data, each of which will be covered in the following chapters.

As far as our final product goes, since we focus on clarity and simplicity, we do not put too much effort into making it fast or memory efficient. This comes from an often repeated saying among programmers, an example of which is found in Structured Programming with go to Statements, ACM, Computing Surveys 6 (4):

 

premature optimization is the root of all evil

 
 --Donald E. Knuth

This leaves us with software that works best with small files, which in most cases is good enough. Once you have a working application and you feel that you need support for larger or faster files, then it's up to you if you want to put in the extra effort of optimization.

The GIS application you end up with at the end of the book is simple but functional, and is meant to serve as a framework that you can easily build on. To leave you with some ideas to pick up on, we placed various information boxes throughout the book with ways that you can optimize or extend your application. For any of the core topics and features that we were not able to cover earlier in the book, we give a broader discussion of missing functionality and future suggestions in the final chapter.

You have been reading a chapter from
Python Geospatial Development Essentials
Published in: Jun 2015
Publisher:
ISBN-13: 9781782175407
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image