Skip to content

Instantly share code, notes, and snippets.

@andrewjennings
Created September 15, 2011 19:20
Show Gist options
  • Save andrewjennings/1220206 to your computer and use it in GitHub Desktop.
Save andrewjennings/1220206 to your computer and use it in GitHub Desktop.
Exporting a plan to a shapefile
#!/bin/bash
# This will export the plan with id 1270, called "mf_exact", to
# a shapefile called mf_exact.shp
pgsql2shp -f mf_exact -u publicmapping -P <password_here> -h <hostname> publicmapping "select d.geom, d.name,
from redistricting_district as d
join (select max(version) as latest, district_id, plan_id from redistricting_district where plan_id = 1270 group by district_id, plan_id) as v on d.district_id = v.district_id and d.plan_id = v.plan_id and d.version = v.latest
where not (ST_IsEmpty(d.geom) or d.district_id = 0);"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment