Programatically determine PostGIS template

The name for the PostGIS template can be changed by setting the
POSTGIS_TEMPLATE setting. This commit allows for that.

Since PostGIS 2.0, the template is optional. This commit consequently
only issues the SQL CREATE statement if a template is used.

Fixes #489.
Merge pull request #517 from maikhoepfel/issue/489

Programatically determine PostGIS template