How To Install GDAL for Python with Anaconda
|

How To Install GDAL for Python with Anaconda

The Geospatial Data Abstraction Library (GDAL) is a fundamental package for spatial analysis with Python. GDAL is a powerful package with a lot of functionality. However, it is notoriously difficult to install. There are two reliable ways to install the GDAL python package: from the conda-forge channel using the conda installer or using pip to…

Spatial Joins with QGIS Using the “Join Attributes by Nearest” Tool

A spatial join is operation performed on spatial vector data that links the attributes of one feature set to the attributes of the closest feature in a second set. The result of a spatial join is a new feature set (vector layer) that contains the attributes of both the input feature and the closest feature…

Calculate Geometry in QGIS: How to calculate line length, polygon area, and polygon perimeter

Calculate Geometry in QGIS: How to calculate line length, polygon area, and polygon perimeter

For many GIS analyses, it is necessary to calculate the length, area, or perimeter of line or polygon features (i.e. geometries). These operations are referred to as calculating geometry. The QGIS tool that calculates feature geometries is the Field Calculator tool. There are some nuances and potential pitfalls when calculating geometry in QGIS. This guide…

Show Only Selected Features in a QGIS Attribute Table

Show Only Selected Features in a QGIS Attribute Table

Attribute tables display information about geographic features and are an essential element of any GIS. It is often necessary to subset, select, or remove features based on attribute data. Learning quick ways to accomplish these tasks can really speed up your GIS efficiency. One common, and very helpful, attribute table view is to show only…

Merge Multiple Rasters in QGIS (Create a Raster Mosaic)

Merge Multiple Rasters in QGIS (Create a Raster Mosaic)

With GIS analysis it’s a common occurrence that multiple raster tiles are required to cover a study area. For many analyses, and specifically hydrological analyses, a seamless, single raster is needed. The solution for combining multiple raster layers is to perform a raster merge, also referred to as a raster mosaic. QGIS uses the the…

Sort NumPy Arrays By Columns or Rows
|

Sort NumPy Arrays By Columns or Rows

NumPy is a fundamental module used in many Python programs and analyses because it conducts numerical computations very efficiently. However, for those new to NumPy, it can be difficult to grasp at first. Specifically, understanding array indexing and sorting quickly becomes complex. Fortunately, NumPy has some built-in functions that make performing basic sorting operations quite…

PyQGIS: Calculate Geometry and Field Values with the QGIS Python API
|

PyQGIS: Calculate Geometry and Field Values with the QGIS Python API

Using attribute fields in calculations is one of the most fundamental components of GIS analysis. Field calculations are what makes it possible to take data linked to spatial features and analyze features based on what they are and where they are. Manually performing field calculations in QGIS can be tedious, especially if you’re working with…

How to Make a False-Color  Satellite Image in QGIS
|

How to Make a False-Color Satellite Image in QGIS

False-color satellite images can be very useful to visually analyze different landscape characteristics. They also look really cool and are used to make very artistic maps and displays. False-color satellite images are created by displaying different band combinations with different colors. For example, a color near-infrared image is created by displaying data from the near-infrared…

Remote Sensing with QGIS: Calculate NDVI
|

Remote Sensing with QGIS: Calculate NDVI

Vegetation indices are a staple remote sensing product and the normalized difference vegetation index (NDVI) may be the most widely used vegetation index. To calculate NDVI you simply need appropriate imagery and a program that allows you to interact with the image data. QGIS is a great, free option for a GIS program that provides…

Vectorize Moving Window Grid Operations on NumPy Arrays
| |

Vectorize Moving Window Grid Operations on NumPy Arrays

There’s a good chance you’ve done something today that used a sliding window (also known as a moving window) and you didn’t even know it. Have you done any photo editing? Many editing algorithms are based on moving windows. Do you do terrain analysis in GIS? Most topographic raster metrics (slope, aspect, hillshade, etc.) are…

Use Python to Convert Polygons to Raster with GDAL.RasterizeLayer
|

Use Python to Convert Polygons to Raster with GDAL.RasterizeLayer

When you work with spatial data it’s inevitable that you will need to implement information from both a vector and raster data source for the same location. This task can easily be accomplished manually, but it often becomes quite cumbersome when the process must be automated across a large number of features, time periods, and/or…

PyQGIS: Dissolve Vector Features with Python and QGIS
|

PyQGIS: Dissolve Vector Features with Python and QGIS

The QGIS Python API (PyQGIS) makes it really simple automate a feature dissolve. PyQGIS gives access to all the QGIS processing tools directly from the Python interface. This tutorial will demonstrate three different dissolve examples with Python in QGIS. Basic Dissolve with Python First, lets dissolve polygon features into a single polygon, this is the…

Zonal Statistics Algorithm with Python in 4 Steps
| | |

Zonal Statistics Algorithm with Python in 4 Steps

It is a common need to summarize information from a gridded dataset within an irregularly shaped area. While at first glance this may seem simple, reconciling differences between raster (gridded) and vector (polygon) datatypes can quickly become complicated. This article shows how to implement a zonal statistics algorithm in Python in 4 steps. Load raster…

How to Generate Passive Income with Online Courses
|

How to Generate Passive Income with Online Courses

Everyone is good at something. With creativity and determination (and maybe some marketing) others will pay to learn from you. Teaching online courses is a great way to earn passive income. The barriers for entry are low, and if your online course doesn’t pan out, the only thing you’ll lose is time. Chances are, you’ll…

Create NetCDF Files with Python
|

Create NetCDF Files with Python

Gridded, spatial data are commonly stored in NetCDF files. This is especially true for climate data. NetCDF files offer more flexibility and transparency than some traditional raster formats by supporting multiple variables and detailed metadata. Because of the metadata and file structure NetCDF files can be more difficult to access than traditional raster formats. This…

Unsupervised Land Cover Classification with Python
| | |

Unsupervised Land Cover Classification with Python

Aerial imagery is used for purposes ranging from military actions to checking out the backyard of a house you might buy. Our human brains can easily identify features in these photographs, but it’s not as simple for computers. Automated analysis of aerial imagery requires classification of each pixel into a land cover type. In other…

Parallel Programming in Python with Message Passing Interface (mpi4py)
| | | |

Parallel Programming in Python with Message Passing Interface (mpi4py)

Did you know you can write parallel Python code that will run on your laptop and on a super computer? You can, and it’s not as difficult as you might expect. If you already write code for asynchronous parallelization then you won’t even have to do much restructuring. High Performance Computing (HPC) distributes pieces of jobs across…

Asynchronous Parallel Programming in Python with Multiprocessing
| |

Asynchronous Parallel Programming in Python with Multiprocessing

A flexible method to speed up code on a personal computer Do you wish your Python scripts could run faster? Maybe they can. And you won’t (probably) have to buy a new computer, or use a super computer. Most modern computers contain multiple processing cores but, by default, python scripts only use a single core….

4 Reasons to Use Open Source Software for your Business and Yourself

4 Reasons to Use Open Source Software for your Business and Yourself

Most popular computer programs have free alternatives. Switching to these free programs could save you some dough and give you earlier access to new features. Open source software is licensed so that its code can be used in other applications without legal violations. This creates an ideal environment for creativity, innovation and improvement in software…

NetCDF with Python (netCDF4): Metadata, Dimensions, and Variables
|

NetCDF with Python (netCDF4): Metadata, Dimensions, and Variables

Important information describing the data contained in netCDF files is embedded directly in the netCDF file. Accessing and reading of this information (i.e. metadata) can help you automate tasks, debug code, and validate results easily. This tutorial covers how to access information describing the metadata, dimensions, and variables contained in a netCDF file. For the…

Python: Geographic Object-Based Image Analysis (GeOBIA) – Part 2: Image Classification
| | | |

Python: Geographic Object-Based Image Analysis (GeOBIA) – Part 2: Image Classification

Use the random forests algorithm to classify image segments into land cover categories. This post is a continuation of Geographic Object-Based Image Analysis (GeOBIA). Herein, we use data describing land cover types to train and test the accuracy of a random forests classifier. Land cover data were created in the previous post. Step-be-step video instructions…

Python: Geographic Object-Based Image Analysis (GeOBIA) – Part 1: Image Segmentation
| | | |

Python: Geographic Object-Based Image Analysis (GeOBIA) – Part 1: Image Segmentation

This tutorial will walk you through segmenting and classifying high resolution imagery using Python. Part 1 of this tutorial teaches how to segment images with Python. After you have completed Part 1, Part 2 will teach how to use machine learning methods to classify segments into land cover types with Python. YouTube videos give step-by-step…

|

PyQGIS: Shapefile from Selected Features

A common operation with vector layers is to select features based on attribute values and save those features to a new vector layer (i.e. shapefile). This tutorial will walk you through how to create a new shapefile from selected features. We’ll select some features, then save those features to a new shapefile. First, we’ll open…

|

PyQGIS: Create Raster

In a previous tutorial I showed you how to access raster values and data with the Geospatial Data Abstraction Library (GDAL). This tutorial will show you how to create a raster with GDAL. Start by importing the gdal and osr Python modules. The osr module is used for handling spatial references. Also import numpy. Now…

|

R: Save NetCDF as a CSV

Sometimes certain analysis may require data in a tabular format (as opposed to the gridded format of NetCDF). This tutorial will take you through how to convert a NetCDF (or other raster/gridded data) to an R data frame, which can then used for analysis or saved as a CSV file. Read the NetCDF file First,…

|

numpy: Methods For Creating Arrays

It is tedious, and not practical, to manually type in values for array creation. In this tutorial we will go through methods for automating array creation and importing tabular data into numpy arrays. Creating empty arrays With numpy you don’t actually create an ‘empty’ array. But you can create an array without intializing specific values. This can be useful…

|

numpy: Array shapes and reshaping arrays

We’ve gone through the basics to manually create arrays of different dimensions and shapes. There will be times that you will want to query array shapes, or automatically reshape arrays. This tutorial will show you how to use numpy.shape and numpy.reshape to query and alter array shapes for 1D, 2D, and 3D arrays. Different methods are required to find…

|

numpy: Creating Arrays

Creating a simple array After numpy is installed, we can begin to create arrays. First, we’ll need to import numpy into our python project. Here I use the statement, import numpy as np, to limit my typing later. This code will allow me to use np in my script to represent instead of typing the full numpy everytime. Then, we can create a simpy…

|

numpy: Install numpy

Check Installation First, check to see if you already have numpy installed. From the terminal, you can use pip to do this. If numpy is installed you will get output similar to this. If numpy is not installed no output will be shown. Install numpy numpy can be installed simply using pip. Check version You can check the numpy version using pip show as demonstrated above. Video tutorial This…

|

numpy: Introduction to numpy

Requirements: Python version 2.7 or greater Beginner skills with python Desire to learn numpy Objectives: Teach the basics of using numpy in python Provide data science applications of numpy Introduce advanced numpy concepts What is numpy? numpy is a powerful python package for handling arrays. It uses C libraries to optimize procedures that would otherwise be slow/computationally expensive in python. What can I do…