PostGIS in Action by Regina O. Obe & Leo S.Hsu (Manning)

This is another book from Manning publications in the excellent ‘.. in Action’ series, which guides the reader through some practical uses of the book’s subject. In this case the subject is PostGIS, which for people that come across the term for the first time, is a spatial database extender for the PostgreSQL database management system. As described in the introduction the audience of this book includes GIS Practitioners and Programmers, DB Practitioners as well as Scientists, Researchers, Educators and Engineers. That makes it obvious that the audience covers a wide spectrum of professionals that would have various degrees of experience with the subject matter.

The material is divided in three main parts, which are: Learning PostGIS, Putting PostGIS to work, and Using PostGIS with other tools as well as four additional appendices.

The first part about Learning PostGIS is an introduction to GIS database concepts and practices, that introduces the geometry, geography, raster and topology types and what problems can be solved by each one of them. There is a thorough explanation of what PostGIS is and what you can do with a spatially enabled database that is not possible with a relational database. There are also chapters describing the spatial types that PostGIS offers and their related functions, an introduction to spatial reference systems and their concepts, tools for loading spatial data as well as desktop tools for viewing and querying them, and the use of geometry, geography and raster functions, geocoding and finally an introduction to spatial relationships.

The second part Putting PostGIS to work, is where all the pieces are put together, using the theory foundation from the previous part, in order to solve real world problems to questions like: which places are within X distance and what are the N closest places?
These cover the traditional methods of finding closest neighbours as well as KNN indexes. Following that there is a section dedicated to geotagging. Geometry and geography processing has its own chapter to demonstrate techniques to manipulate geometries, and some of the most common problems and solutions related to them. Other chapters include raster processing, topology which includes creating a topology, and building and working with topogeometries as well as the simplification and validation of them. The final two chapters of this part offer the reader practical solutions in how to organise the spatial storage depending on the requirements, and some very useful tips about query performance tuning and optimisations. It should be also noted that throughout the book there are plenty of examples for the reader to follow, and especially in this part, that are of great practical use.

In the Using PostGIS with other tools part we are told how PostGIS can be extended by means of add-ons like the PostgreSQL procedural languages PL/R and PL/Python that allows us to use the wealth of statistical functions and plotting capabilities of R as well as the numerous Python packages. A variety of travelling-salesperson problems are displayed in this section, and the pgRouting used for building routing applications is also covered. The remaining chapters cover server-side mapping servers and client-side mapping frameworks to display PostGIS data on the web.

Finally the appendices have a very useful section with additional resources, instruction for installing PostGIS, an SQL primer and a separate section with the PostgreSQL features that includes table inheritance, roles, functions and performance tips.

To summarise, this is an extremely useful book for a variety of professional people interested in discovering PostGIS and at the same time PostgreSQL. It does not require any previous knowledge of geospatial databases as there is a great explanation and coverage of the theory, systems and tools needed. It would be helpful if the reader has some knowledge of SQL in order to follow the examples provided, even though there is very good appendix that covers SQL.
A highly recommended book for starting your exploration in the world of spatial databases.

Disclosure of Material Connection: I received this book free from the publisher. I was not required to write a positive review. The opinions I have expressed are my own. Regardless, I only recommend products or services I use personally and believe will add value to readers.

ERROR: could not open extension control file “/usr/share/postgresql/9.3/extension/plr.control”: No such file or directory

Problem

You are trying to install the PL/R extension to PostgreSQL, after install R in your linux ubuntu development environment, but when trying to install the extension inside your PostgresSQL with:

create extension plr;

you are getting the following error:

ERROR:  could not open extension control file "/usr/share/postgresql/9.3/extension/plr.control": No such file or directory

Solution

Install the necessary package for your PostgreSQL version with the following, and install the extension in your psql:

sudo apt-get install postgresql-9.x-plr

OSVDB 119927 : http Gem for Ruby SSL Certificate Validation MitM Spoofing

Problem

There was a security vulnerability issued by Gemnasium about the http gem with the title OSVDB-119927 – MitM Security Vulnerability.

The details for it are here.

Solution

After some investigation (gem dependency http –reverse-dependencies) it turns out that the twitter gem (5.14.), is using an older vulnerable http dependency (0.6.3).

In order to remove this warning and until there is a new twitter gem released, you can use the github master branch of twitter, like:

gem 'twitter', github: 'sferik/twitter'

Dreamhost, DreamCompute(OpenStack) ssh login

Problem

You have just created your first instance in Dreamhost’s new service DreamCompute using OpenStack and you would like to login with ssh, but you get ‘Permission Denied’.

Solution

The solution is described here, and it’s the fact that the user name that you need to use is not your Dreamhost account name, or the DreamCompute dashboard user anme but the the username called:

dhc-user

NOTE: It seems that is also described here, at the bottom.

Using Elixir with Docker

In order to be able to use Elixir with the help of Docker, so that you can run different containers with different versions, and to have a shared code folder, you could follow the steps below:

  • Install docker in your system. Installation instructions for different systems are here
  • Download the elixir image from the Docker Hub:
    sudo docker pull trenpixster/elixir
  • List the images on your host:
    sudo ps docker images
  • Start a specific version of the elixir docker container (ie elixir 1.0.3):
    sudo docker run -t -i trenpixster/elixir:1.0.3 /bin/bash
  • Use a shared folder with code between the docker container and your host:
    sudo docker run -v /home/user/Prog:/Prog -t -i trenpixster/elixir:1.0.3 /bin/bash

    where the folders after the -v option are /home/user/Prog (host) and /Prog (docker)

  • Use a port forwarding:
    sudo docker run -p 8000 -v /home/user/Prog:/Prog -t -i trenpixster/elixir:1.0.3 /bin/bash

Some useful docker commands

Having started to use docker recently, some of the commands that are needed are a bit difficult to remember. I’m sure that this will change the more that I use it, but as a quick reminder/look up for this initial phase, I’m just going to list some of them here.

List current images:

sudo docker images

List currrent running containers:

sudo docker ps

Saving the state of a container by using the id from above command:

sudo docker commit -m "latest state comment" -a "John Somebody" 7ed30_id_no new_name_of_container:v2

Starting a container with port forwarding:

sudo docker run -p 8000 -t -i new_name_of_container:v2 /bin/bash

Sharing a directory from the host system (/home/user/Prog) inside the container (Prog):

sudo docker run -p 8000 -v /home/user/Prog:/Prog -t -i new_name_of_container:v2 /bin/bash

No PostgreSQL clusters exist; see “man pg_createcluster”

Problem

After installing postgresql in a new Ubuntu 14.04 installation you get the error:

No PostgreSQL clusters exist; see "man pg_createcluster"

and when you try to start the server with:

sudo service postgresql start

you get the error that the server does not exist:

psql: coud not create to server: No such file or directory ...

Solution

The solution can be found in the article here, and is to create manually the first cluster by:

sudo pg_createcluster 9.3 main

Fixing a broken sudoers file without rebooting

Problem

If by accident you make a mistake in your sudoers file then you won’t be able to run sudo command after saving the file.

Solution

Following the answer here, you can simply run the command pkexec visudo, supply your password and provided you already had sudo permissions, fix the sudoers file, make sure that you save it using the Q when prompted, and you should be able to use sudo commands again.

Docker error – error response from daemon: Cannot start container….is not within /var/lib/docker/aufs/mnt

Problem

You are trying to use an image from Docker in your Ubuntu 14.04 system, but you are getting a error like the following:

014/12/13 17:10:23 Error response from daemon: Cannot start container 4023610855c0551bdc44d0e602f20999c0527da3cfe010169707248887b3a1f0: /var/lib/docker/aufs/mnt/4023610855c0551bdc44d0e602f20999c0527da3cfe010169707248887b3a1f0 is not within /var/lib/docker/aufs/mnt/4023610855c0551bdc44d0e602f20999c0527da3cfe010169707248887b3a1f0

Solution

Your docker version is outdated (ie 1.0.1) so you would need to upgrade your docker installation.
There is a script for this (information from here):

After running the following you should be able to use your images as normal with: sudo docker run -t -i image/name bin/bash:

$ curl -s https://get.docker.io/ubuntu/ | sudo sh

Project ERROR: Unknown module(s) in QT: webkitwidgets

Problem

You are trying to bundle install a Gemfile that includes the capybara-webkit gem, in an Ubuntu system but you get the following error:

ERROR:  Error installing capybara-webkit:
ERROR: Failed to build gem native extension.
Project ERROR: Unknown module(s) in QT: webkitwidgets

Solution

It seems that the latest ubuntu versions are using QT version 5 instead of 4. So in order to be able to install the gem you would need to install the qt development libraries for version 5 like:

sudo apt-get install libqt5webkit5-dev