Invariant Properties

  • rss
  • Home

Getting Started On “PostGIS in Action” on Ubuntu

Bear Giles | July 4, 2011

I’ve worked with proto-GIS software at a number of positions – that is, I had dynamic data and background information (roads, urban areas, etc.), all in long-lat coordinates. But it was the dark ages of computer science and we didn’t have access to free high-quality libraries so it was all roll-your-own. Fortunately in both cases (meteorology and aviation) we just needed the ability to display static and very constrained dynamic data, albeit sometimes in interesting ways. (E.g., creating vertical of the atmosphere along great circle lines.)

This meant I was really looking forward to PostGIS in Action from Manning Press. I’ll admit that a lot of that is morbid curiosity – how long would it take to do a task today vs. the late 90s?

The first step is to get the software. Most of it is already packaged in Ubuntu packages for postgresql-8.4, postfix, and postgresql-8.4-postfix. Unfortunately the standard packages do not include shp2pgsql-gui and we must build it ourselves.

The process is relatively straightforward if you’re comfortable building C projects. The GUI client is in the loader directory and you’ll need to specify the path to the header files and libraries in your Makefile. My changes are listed below.

  1. # GTK includes and libraries
  2. GTK_CFLAGS = -I/usr/include/gtk-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0 -I/usr/lib/gtk-2.0/include
  3. GTK_LIBS = -lgtk-x11-2.0
# GTK includes and libraries
GTK_CFLAGS = -I/usr/include/gtk-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0 -I/usr/lib/gtk-2.0/include
GTK_LIBS = -lgtk-x11-2.0

Finally copy the executable to /usr/local/bin.

I now create the postgis template and test database according to instructions in Appendix B.

  1. $ psql (as postgresql superuser)
  2. CREATE DATABASE template_postgis WITH TEMPLATE = template1 ENCODING = 'UTF8';
  3. \c template_postgis;
  4. CREATE LANGUAGE plpgsql; --this may not be needed if running 8.4
  5. \i /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql;
  6. \i /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql;
  7. \i /usr/share/postgresql/8.4/contrib/postgis_comments.sql;
  8. UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
  9. GRANT ALL ON geometry_columns TO PUBLIC;
  10. GRANT ALL ON spatial_ref_sys TO PUBLIC;
  11.  
  12. CREATE DATABASE testgis WITH TEMPLATE = template_postgis;
  13. \q
$ psql (as postgresql superuser)
CREATE DATABASE template_postgis WITH TEMPLATE = template1 ENCODING = 'UTF8';
\c template_postgis;
CREATE LANGUAGE plpgsql; --this may not be needed if running 8.4
\i /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql;
\i /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql;
\i /usr/share/postgresql/8.4/contrib/postgis_comments.sql;
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
GRANT ALL ON geometry_columns TO PUBLIC;
GRANT ALL ON spatial_ref_sys TO PUBLIC;

CREATE DATABASE testgis WITH TEMPLATE = template_postgis;
\q

and download and install a number of shape files downloaded the sites mentioned in the back of the book.

At this point I have a GIS-enabled database containing a few gigabytes of data…. now what?

That’s a good question. So far I’ve had a few hours to play with two Ubuntu packages: OPENJump and qgis.  The latter can read files from PostGIS and it looks like it will be easy to do full relational queries on the data. That is, do things like “show the location of all McDonalds within 50 miles of a wilderness area.” OPENJump also has a ‘query’ function but I don’t know how powerful it is.

Still… it makes me wonder about alternative approaches to those earlier problems. E.g., what would be the costs and benefits of breaking the old presentation architecture into two pieces. The first would take the scientific data and convert it to GIS XYM (and XYZM) data and the second would be a standard GIS client. It adds a step and it might complicate things like animations… but it would also make it trivial to provide the information in multiple forms since there would be complete decoupling of the science and the presentation.

Comments
1 Comment »
Categories
linux
Comments rss Comments rss
Trackback Trackback

Archives

  • May 2020 (1)
  • March 2019 (1)
  • August 2018 (1)
  • May 2018 (1)
  • February 2018 (1)
  • November 2017 (4)
  • January 2017 (3)
  • June 2016 (1)
  • May 2016 (1)
  • April 2016 (2)
  • March 2016 (1)
  • February 2016 (3)
  • January 2016 (6)
  • December 2015 (2)
  • November 2015 (3)
  • October 2015 (2)
  • August 2015 (4)
  • July 2015 (2)
  • June 2015 (2)
  • January 2015 (1)
  • December 2014 (6)
  • October 2014 (1)
  • September 2014 (2)
  • August 2014 (1)
  • July 2014 (1)
  • June 2014 (2)
  • May 2014 (2)
  • April 2014 (1)
  • March 2014 (1)
  • February 2014 (3)
  • January 2014 (6)
  • December 2013 (13)
  • November 2013 (6)
  • October 2013 (3)
  • September 2013 (2)
  • August 2013 (5)
  • June 2013 (1)
  • May 2013 (2)
  • March 2013 (1)
  • November 2012 (1)
  • October 2012 (3)
  • September 2012 (2)
  • May 2012 (6)
  • January 2012 (2)
  • December 2011 (12)
  • July 2011 (1)
  • June 2011 (2)
  • May 2011 (5)
  • April 2011 (6)
  • March 2011 (4)
  • February 2011 (3)
  • October 2010 (6)
  • September 2010 (8)

Recent Posts

  • 8-bit Breadboard Computer: Good Encapsulation!
  • Where are all the posts?
  • Better Ad Blocking Through Pi-Hole and Local Caching
  • The difference between APIs and SPIs
  • Hadoop: User Impersonation with Kerberos Authentication

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Pages

  • About Me
  • Notebook: Common XML Tasks
  • Notebook: Database/Webapp Security
  • Notebook: Development Tips

Syndication

Java Code Geeks

Know Your Rights

Support Bloggers' Rights
Demand Your dotRIGHTS

Security

  • Dark Reading
  • Krebs On Security Krebs On Security
  • Naked Security Naked Security
  • Schneier on Security Schneier on Security
  • TaoSecurity TaoSecurity

Politics

  • ACLU ACLU
  • EFF EFF

News

  • Ars technica Ars technica
  • Kevin Drum at Mother Jones Kevin Drum at Mother Jones
  • Raw Story Raw Story
  • Tech Dirt Tech Dirt
  • Vice Vice

Spam Blocked

53,314 spam blocked by Akismet
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox