Functions for use in postgreSQL/postgis