Reduce the file size of PDFs with Ghostscript

Portable Document Format (PDF) is a common format used for publishing maps. PDFs can contain both raster and vector data and can be read by a large number of freely available viewer applications, such as Adobe Reader and Okular.

Adobe Reader Pro can be used to optimize the size of …

Continue reading »

Merging vector layers with ogr2ogr

In the example below we will merge a group of SQLite layers (first.sqlite, second.sqlite, third.sqlite, ...) into a single SQLite layer (topographicarea.sqlite).

The first step is to create an empty layer with the correct schema (i.e., the same geometry type and fields).

ogr2ogr -f SQLite -nln …

Continue reading »

Using Cartopy with Rasterio

This post demonstrates the basics of creating maps in Python using Cartopy with raster data read using Rasterio. Cartopy makes it easy to draw maps in matplotlib figures, using the Proj.4 library to handle any wacky projection you can throw at it, and the shapely Python module to work …

Continue reading »

Using Rtree spatial indexing with OGR

Spatial indexing can significantly reduce the time required to perform geoprocessing operations involving intersection. This includes intersections, unions, dissolves, and nearest neighbour analysis.

Spatial indexing speeds up queries by reducing the number of features that need to be evaluated with computationally expensive geometic calculations. It does this by performing a …

Continue reading »

Symbology of vector layers in QGIS Python Plugins

The symbology of a layer describes how the layer's data should be displayed on the map canvas. A layers symbology, or style, is composed of two things: a symbol (or multiple symbols) and a renderer.

The layer's renderer decides which features should be drawn using which symbols. The renderer can …

Continue reading »

Embedding PNGs in SVG markers in QGIS

QGIS has support for using Scaleable Vector Graphics (SVGs) as marker icons. This gives you a lot of control over how markers appear on your maps. But what if the marker you want to use doesn't have a vector version available? Fear not! Other image formats, including raster formats such …

Continue reading »

Writing unit tests for QGIS Python plugins

Testing your code is a good idea. Testing can help you find bugs early and spot regressions where you didn't expect them. The tests themselves can form a kind of "living" documentation, and can even drive the design of your project. A unit test is a test written for a …

Continue reading »

Multithreading in QGIS Python plugins

The Python bindings in QGIS allow plugins to be written in Python. Writing a plugin for QGIS involves two things: writing the geoprocessing algorithm itself, and writing a graphical user interface (GUI) that the user can interact with without writing any code.

Using a GIS often requires patience; geoprocessing tasks …

Continue reading »