Thread: getting access to geodistance (what do I need to install/enable) in an existing db install

Hi,
  I was running postgres 8.1 on a windows xp box and I recall
installing it with postgis option.
I had a method in a db there that called geodistance. Everything worked fine.

Now I tried to restore the db on the debian server thats running 8.1
as well. The geodistance function (or any other geometry function ) is
not available.

What am i supposed to install enable (and how) to get those
functions/casts etc to be present.
Much thanks in advance.

-assad

On Wed, Jan 11, 2006 at 02:40:04PM -0700, Assad Jarrahian wrote:
>   I was running postgres 8.1 on a windows xp box and I recall
> installing it with postgis option.
> I had a method in a db there that called geodistance. Everything worked fine.

Neither PostgreSQL nor PostGIS have a geodistance function, at least
not in recent versions.  However, PostGIS does have distance,
distance_sphere, and distance_spheroid functions.

> Now I tried to restore the db on the debian server thats running 8.1
> as well. The geodistance function (or any other geometry function ) is
> not available.

Googling for "geodistance" returns a few hundred hits, but googling
for "postgresql geodistance" or "postgis geodistance" yields only
a few hits.  The following message to pgsql-hackers from over five
years ago is the only hit I found in the PostgreSQL or PostGIS
mailing lists:

http://archives.postgresql.org/pgsql-hackers/2000-11/msg01232.php

I'd guess geodistance is or was part of some add-on.  If you connect
to the XP box with psql, what does "\df+ geodistance" show?  If
it's an SQL or PL/pgSQL function then you could copy its source
into the new database with CREATE FUNCTION, but maybe you'd be
better off using one of the standard functions.

What, if anything, does geodistance do that the standard PostGIS
distance functions don't?

--
Michael Fuhr

Michael and all,
 my appologies. It was a typo. The method is geo_distance(point, point)
I copied this from psql

mingle=# \df+ geo_distance
                                                 List of functions
 Schema |     Name     | Result data type | Argument data types |  Owner   | Lan
guage | Source code  | Description
--------+--------------+------------------+---------------------+----------+----
------+--------------+-------------
 public | geo_distance | double precision | point, point        | postgres | c
      | geo_distance |
(1 row)


additionally I got this from pg_admin

CREATE OR REPLACE FUNCTION geo_distance(point, point)
  RETURNS float8 AS
'$libdir/earthdistance', 'geo_distance'
  LANGUAGE 'c' IMMUTABLE STRICT;
ALTER FUNCTION geo_distance(point, point) OWNER TO postgres;

I dont mind using any other distance method, but I cannot seem to find
any in my db (I presume I do not have postgis installed). How would I
go about installing (debian apt) and adding it to my current  db.

Much thanks in advance.
-assad



On 1/11/06, Michael Fuhr <mike@fuhr.org> wrote:
> On Wed, Jan 11, 2006 at 02:40:04PM -0700, Assad Jarrahian wrote:
> >   I was running postgres 8.1 on a windows xp box and I recall
> > installing it with postgis option.
> > I had a method in a db there that called geodistance. Everything worked fine.
>
> Neither PostgreSQL nor PostGIS have a geodistance function, at least
> not in recent versions.  However, PostGIS does have distance,
> distance_sphere, and distance_spheroid functions.
>
> > Now I tried to restore the db on the debian server thats running 8.1
> > as well. The geodistance function (or any other geometry function ) is
> > not available.
>
> Googling for "geodistance" returns a few hundred hits, but googling
> for "postgresql geodistance" or "postgis geodistance" yields only
> a few hits.  The following message to pgsql-hackers from over five
> years ago is the only hit I found in the PostgreSQL or PostGIS
> mailing lists:
>
> http://archives.postgresql.org/pgsql-hackers/2000-11/msg01232.php
>
> I'd guess geodistance is or was part of some add-on.  If you connect
> to the XP box with psql, what does "\df+ geodistance" show?  If
> it's an SQL or PL/pgSQL function then you could copy its source
> into the new database with CREATE FUNCTION, but maybe you'd be
> better off using one of the standard functions.
>
> What, if anything, does geodistance do that the standard PostGIS
> distance functions don't?
>
> --
> Michael Fuhr
>

On Wed, Jan 11, 2006 at 04:20:05PM -0700, Assad Jarrahian wrote:
>  my appologies. It was a typo. The method is geo_distance(point, point)

Ah, I'd forgotten about that one.  geo_distance is part of the
contrib/earthdistance module, as your pg_admin output hints at:

> CREATE OR REPLACE FUNCTION geo_distance(point, point)
>   RETURNS float8 AS
> '$libdir/earthdistance', 'geo_distance'
>   LANGUAGE 'c' IMMUTABLE STRICT;
> ALTER FUNCTION geo_distance(point, point) OWNER TO postgres;

If you want to use that function then install contrib/earthdistance
(you'll have to install contrib/cube first because earthdistance
depends on it).  If you're not sure how to install those modules
then look around for files named cube.sql and earthdistance.sql and
load them into your database (cube.sql first).

--
Michael Fuhr

[Please copy the mailing list on replies.]

On Wed, Jan 11, 2006 at 08:02:56PM -0700, Assad Jarrahian wrote:
>    I tried that, but it said type cube does not exists. I tried
> looking around and could not find the file where CREATE type cube is
> in.

cube and earthdistance are contributed modules; in the PostgreSQL
source code they're under the contrib directory.  If you're using
pre-built packages then look through the available packages for
something with a name like postgresql-contrib, pgsql-contrib, etc.
The required SQL files and shared objects should be in that package.

--
Michael Fuhr

Michael,
     I found the files cube.sql and earthdistance.sql in the contrib
directory on my windows box. I put it on my debian box and then
psql'ed into the db and did \i cube.sql and thats how I got the
message.
 But I am still stumped as to how to get it to work.
Additionally, I was trying to install postgis on the debian box and
cannot find the contrib directory.

thanks for your help
-assad



On 1/11/06, Michael Fuhr <mike@fuhr.org> wrote:
> [Please copy the mailing list on replies.]
>
> On Wed, Jan 11, 2006 at 08:02:56PM -0700, Assad Jarrahian wrote:
> >    I tried that, but it said type cube does not exists. I tried
> > looking around and could not find the file where CREATE type cube is
> > in.
>
> cube and earthdistance are contributed modules; in the PostgreSQL
> source code they're under the contrib directory.  If you're using
> pre-built packages then look through the available packages for
> something with a name like postgresql-contrib, pgsql-contrib, etc.
> The required SQL files and shared objects should be in that package.
>
> --
> Michael Fuhr
>

On Wed, Jan 11, 2006 at 08:38:49PM -0700, Assad Jarrahian wrote:
>    Sorry for my hasty respone. The problem really seems to be that I
> dont have $libdir set
> How would I go about setting that?
[...]
> ERROR:  could not access file "$libdir/cube": No such file or directory

$libdir refers to the directory where modules' shared objects are
installed.  It's built-in to PostgreSQL; you can see its value by
running "pg_config --pkglibdir" from the command line.  I think the
problem isn't that $libdir isn't set, but rather that the cube
module's shared object (cube.so, or whatever it's called on your
platform) isn't in that directory.

Are you building from source or are you using pre-built packages?

--
Michael Fuhr

On Wed, Jan 11, 2006 at 09:22:16PM -0700, Assad Jarrahian wrote:
> Am I building what from source? cube.sql or postgis.
> for cube.sql
> I just took the cube.sql from windows and tried to run it in psql
> (debian) in script mode.

The .sql files are only part of what you need; you also need the
modules' shared objects (cube.so and earthdistance.so).  If you
don't have the shared objects for the modules you want to install
then you'll need to install them via a package or build them from
the source code.

> for postgis:
> I cannot find where the contrib directory is (I am following
> directions from the postgis site)

I'd recommend asking PostGIS-specific questions on the postgis-users
mailing list where there's more PostGIS expertise.

http://postgis.refractions.net/mailman/listinfo/postgis-users

--
Michael Fuhr