Using Pg_dump With PostGIS Topology

tl;dr

pg_dump defaults to outputting COPY commands for the topology.layer table before populating the topology.topology table. this breaks a foreign key constraint, and causes the following error:

1
2
ERROR:  insert or update on table "layer" violates foreign key constraint "layer_topology_id_fkey"
DETAIL:  Key (topology_id)=(1) is not present in table "topology".

To fix, manually swap the COPY block for topology.topology before topology.layer.

more →

Configure PostGIS With Travis CI

Thanks to a great presentation by foundatron on the continuous integration framework, Travis CI, I’ve finally been motivated to push for higher test coverage in my python projects.

Some of these projects require connectivity to a PostGIS database for testing, and with Travis CI that process is extremely straightforward. This post includes notes on configuring a Travis CI environment with PostgreSQL and PostGIS, then loading that empty database with data.

PostgreSQL/Postgis Versions

NOTE: These versions are current as of January 2014.

  • PostgreSQL: 9.1.11 by default, although you can explicitly declare 9.2 or 9.3.
  • PostGIS: 2.1.1 r12113
  • GEOS: 3.3.8
  • PROJ: 4.8.0
  • GDAL: 1.9.2
more →

Creating Label Points With OpenStreetMap Data

tl;dr

1
2
3
4
5
6
7
8
9
10
11
12
13
-- Use a CTE to create a table of water polygons, aggregating
-- overlapping polygons sharing the same name
WITH polys AS (
    SELECT name, (ST_DUMP(ST_BUFFER(ST_Collect(geometry), 0))).geom AS single_geom
    FROM osm_new_waterareas
    WHERE name IS NOT NULL
    GROUP BY name
)
-- Generate a name and label point for each feature
-- Generate an accurate area attribute by casting to geography
SELECT name, ST_PointOnSurface(single_geom),
       ST_Area(Geography(ST_Transform(single_geom, 4326))) AS area
FROM polys;
more →

TileStache-Links-Roundup

I’m giving a presentation at this year’s CUGOS Fall Fling Bling, on TileStache. The list below are a series of interesting links I’ve found regarding TileStache, or Vector Tiles in general.

Mind of Migurski

Nelson Minar Vector Tiles Notes

Data

My own slides from the Fall Fling can be found here. An introductory blog post on rendering TopoJSON with TileStache can be found, here.

TileStache: Generate [Topo|Geo]JSON Vector Tiles

Vector tiles are simply tiled representations of geographic data, much like raster tiles used to power typical web maps such as OpenStreetMap. They differ from traditional raster tiles however in that instead being an image, they actually contain the geographic coordinates and attributes of the features that exist within their bounding boxes. Vector tiles can be used for a variety of different rendered outputs within a modern web-mapping application. One examples can include serving as an intermediate step in the processing of raster tiles. This approach is adopted by Mapbox, who have defined their own mapnik-vector-tile spec. This allows for amazing styling possibilities, allowing raster tiles to be generated with different styles quickly and efficiently based on the same dataset. Another approach relies on transmitting vector data directly to the client, where client-side libs render data as SVGs directly in the browser. D3.js is a JavaScript library that can do this just this, as illustrated by Sam Matthews. Now that we know what they’re good for, how can we take our own local geographic data, and render our own?

more →

Quickstart GIS Setup on Ubuntu Linux 12.04 LTS

I had to recently setup a clean Ubuntu 12.04 LTS workstation for GIS data processing. For the simplicity and speed, I decided to go with packaged versions of many of the required GIS software. Many of the packages are derived from the ubuntugis-unstable repository.

What follows below are a blow-by-blow of my installation notes grouped by software package. Either code snippets or links to relevant blog posts. more →