earthdistance

Started by Olivier Chaussavoineover 12 years ago12 messagesgeneral
Jump to latest
#1Olivier Chaussavoine
olivier.chaussavoine@gmail.com

I develope a project openbarter that needs to match objects based on a
maximum distance between their positions on earth. I saw that the
documentation of the extension earthdistance was interesting, but the
promise was not in the code. It would be nice to have these functions
available independently of sophisticated geographic systems. There is a
circle object for flat two dimensional space, but earth deals with
spherical caps. It would not be exact but enough to suppose that earth is a
sphere and that all dimensions latitude, longitude and distance are in
radian.
What would need to be done to adapt the circle type to a new type
'spherical cap' that would allow simple geographic indexing?

--
Olivier Chaussavoine

#2Brent Wood
Brent.Wood@niwa.co.nz
In reply to: Olivier Chaussavoine (#1)
Re: earthdistance

You might install Postgis to implement very powerful spatial functionality that can easily do what you are asking (plus a whole lot more).
http://www.postgis.org

Now that v2 installs as a Postgres extension, it is more closely coupled with the underlying database.

Brent Wood

Programme leader: Environmental Information Delivery
NIWA
DDI: +64 (4) 3860529
________________________________________
From: pgsql-general-owner@postgresql.org [pgsql-general-owner@postgresql.org] on behalf of Olivier Chaussavoine [olivier.chaussavoine@gmail.com]
Sent: Saturday, August 10, 2013 7:29 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] earthdistance

I develope a project openbarter that needs to match objects based on a maximum distance between their positions on earth. I saw that the documentation of the extension earthdistance was interesting, but the promise was not in the code. It would be nice to have these functions available independently of sophisticated geographic systems. There is a circle object for flat two dimensional space, but earth deals with spherical caps. It would not be exact but enough to suppose that earth is a sphere and that all dimensions latitude, longitude and distance are in radian.
What would need to be done to adapt the circle type to a new type 'spherical cap' that would allow simple geographic indexing?

--
Olivier Chaussavoine
--
Please consider the environment before printing this email.
NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Uwe C. Schroeder
uwe@oss4u.com
In reply to: Olivier Chaussavoine (#1)
Re: earthdistance

How accurate do you need it? My website has a lot of "local" listing stuff
based on a distance from the viewer and I use the earthdistance module in
contrib to do it.
Given, it's not accurate enough to calculate a surgical missile strike, but
for "within 20 miles" type of things it's good enough - give or take a mile.

The problem I have is to determine the location of the viewer/poster. Aside
from asking precice lat/long coordinates (which no user will have any clue
about), the next best thing is to rely on smartphones and their GPS - but what
of regular browser/computer users? When I let google map my location it shows
as San Francisco - which is about 56 miles off. So network location makes no
sense for this.
I'm using a zipcode based geographical mapping, which already has flaws since a
zipcode is an area, not a point. The commonly available zipcode databases give
you the geographical center of the zipcode - which certainly will be some
distance off from the real location.

I found that the inaccuracies work for my application - nobody cares about a
few more or less miles when looking for something. The advantage is that it
also protects the privacy of the poster to some degree - nobody really needs
to know exactly where the post originated...

If "openbarter" is what I think it is (kinda craigslist just with bartering),
I think a few miles off won't make a difference. Chances are, your members won't
divulge their true location anyways. We have members from South Africa using a
US zipcode - which is what ... 5000 miles off?
Earthdistance is definitely easy to deal with - just give a latitude/longitude
and off you go..

Uwe

On Fri, 08/09/2013 09:29:49 PM Olivier Chaussavoine wrote:

I develope a project openbarter that needs to match objects based on a maximum
distance between their positions on earth. I saw that the documentation of the
extension earthdistance was interesting, but the promise was not in the code.
It would be nice to have these functions available independently of
sophisticated geographic systems. There is a circle object for flat two
dimensional space, but earth deals with spherical caps. It would not be exact
but enough to suppose that earth is a sphere and that all dimensions latitude,
longitude and distance are in radian.
What would need to be done to adapt the circle type to a new type 'spherical
cap' that would allow simple geographic indexing?

--
Olivier Chaussavoine

#4John R Pierce
pierce@hogranch.com
In reply to: Brent Wood (#2)
Re: earthdistance

On 8/9/2013 5:18 PM, Brent Wood wrote:

You might install Postgis to implement very powerful spatial functionality that can easily do what you are asking (plus a whole lot more).

indeed, PostGIS is the logical answer, but the OP specifically stated he
wanted the functionality without 'sophisticated geographic systems'. so
I ignored the question.

the alternative would be implementing your own spherical geometry
functions, and hook them up to GiST indexing, its not /that /hard, but
by the time you got all the functionality you need, you'd be half way to
PostGIS, so why fight it?

--
john r pierce 37N 122W
somewhere on the middle of the left coast

#5Dann Corbit
DCorbit@connx.com
In reply to: Olivier Chaussavoine (#1)
Re: earthdistance

To calculate geographic distances, a great circle route calculation is used. This is not the same thing as the simple calculation for distances between two points on a sphere.
In order to perform the calculation, various model parameters must be chosen, such as the ellipsoidal reference model.
To see examples of how this calculation is performed, see the code from the project proj.4:
https://trac.osgeo.org/proj/
I see that PostGIS uses proj.4, so if you have installed that package, you should be able to perform the calculations you wish to make.

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Olivier Chaussavoine
Sent: Friday, August 9, 2013 12:30 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] earthdistance

I develope a project openbarter that needs to match objects based on a maximum distance between their positions on earth. I saw that the documentation of the extension earthdistance was interesting, but the promise was not in the code. It would be nice to have these functions available independently of sophisticated geographic systems. There is a circle object for flat two dimensional space, but earth deals with spherical caps. It would not be exact but enough to suppose that earth is a sphere and that all dimensions latitude, longitude and distance are in radian.
What would need to be done to adapt the circle type to a new type 'spherical cap' that would allow simple geographic indexing?

--
Olivier Chaussavoine

#6Olivier Chaussavoine
olivier.chaussavoine@gmail.com
In reply to: John R Pierce (#4)
Re: earthdistance

As a simple potential user, I tried to install PostGIS, downloaded all
libraries required: proj-4.8.0,
gdal-1.10.0,json-c,postgis-2.0.3,geos-3.3.8,libwml2-2.9.0, and tried to
build the first library with the simple procedure:

./configure
make
make install

I had a fatal error:

make[2]: entrant dans le répertoire « /home/olivier/ob/proj-4.8.0/src »
/bin/bash ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I.
-DPROJ_LIB=\"/usr/local/share/proj\" -DMUTEX_pthread -g -O2 -MT
jniproj.lo -MD -MP -MF .deps/jniproj.Tpo -c -o jniproj.lo jniproj.c
libtool: compile: gcc -DHAVE_CONFIG_H -I.
-DPROJ_LIB=\"/usr/local/share/proj\" -DMUTEX_pthread -g -O2 -MT jniproj.lo
-MD -MP -MF .deps/jniproj.Tpo -c jniproj.c -fPIC -DPIC -o .libs/jniproj.o
jniproj.c:52:26: fatal error: org_proj4_PJ.h: No such file or directory
compilation terminated.

problem out of the scope of this list, and probably not /difficult. Since I
look for a simple geographic indexing using imprecise lat,long coordinates
that do not deal with precise modeling; that I am afraid of long install
procedure, and heavy computations, I also give up.

Spacial mysql indexing seems to be included in pre-built packages.

What can we do?

2013/8/10 John R Pierce <pierce@hogranch.com>

On 8/9/2013 5:18 PM, Brent Wood wrote:

You might install Postgis to implement very powerful spatial functionality that can easily do what you are asking (plus a whole lot more).

indeed, PostGIS is the logical answer, but the OP specifically stated he
wanted the functionality without 'sophisticated geographic systems'. so I
ignored the question.

the alternative would be implementing your own spherical geometry
functions, and hook them up to GiST indexing, its not *that *hard, but by
the time you got all the functionality you need, you'd be half way to
PostGIS, so why fight it?

--
john r pierce 37N 122W
somewhere on the middle of the left coast

--
Olivier Chaussavoine

#7Olivier Chaussavoine
olivier.chaussavoine@gmail.com
In reply to: Uwe C. Schroeder (#3)
Re: earthdistance

I did not found any geographic indexing with earthdistance, and need it.

The need I have is simple:
"is the distance between two (lat,long) positions less than X km?"
the model used for the shape of the earth should be related to the
precision of lat,lon, and most sources are imprecise. The spherical model
should be enough.

How wrong I am to think that:
* postgres contains a circle object where distance is the hypothenuse. The
spherical problem using lat,long is also bidimensional. We could /just use
haversine distance instead of hypothenuse.
* gist and b-tree bidimensional indexing does not need to be changed to
fulfill this need.

2013/8/10 Uwe Schroeder <uwe@oss4u.com>

**

How accurate do you need it? My website has a lot of "local" listing stuff
based on a distance from the viewer and I use the earthdistance module in
contrib to do it.

Given, it's not accurate enough to calculate a surgical missile strike,
but for "within 20 miles" type of things it's good enough - give or take a
mile.

The problem I have is to determine the location of the viewer/poster.
Aside from asking precice lat/long coordinates (which no user will have any
clue about), the next best thing is to rely on smartphones and their GPS -
but what of regular browser/computer users? When I let google map my
location it shows as San Francisco - which is about 56 miles off. So
network location makes no sense for this.

I'm using a zipcode based geographical mapping, which already has flaws
since a zipcode is an area, not a point. The commonly available zipcode
databases give you the geographical center of the zipcode - which certainly
will be some distance off from the real location.

I found that the inaccuracies work for my application - nobody cares about
a few more or less miles when looking for something. The advantage is that
it also protects the privacy of the poster to some degree - nobody really
needs to know exactly where the post originated...

If "openbarter" is what I think it is (kinda craigslist just with
bartering), I think a few miles off won't make a difference. Chances are,
your members won't divulge their true location anyways. We have members
from South Africa using a US zipcode - which is what ... 5000 miles off?

Earthdistance is definitely easy to deal with - just give a
latitude/longitude and off you go..

Uwe

On Fri, 08/09/2013 09:29:49 PM Olivier Chaussavoine wrote:

I develope a project openbarter that needs to match objects based on a
maximum distance between their positions on earth. I saw that the
documentation of the extension earthdistance was interesting, but the
promise was not in the code. It would be nice to have these functions
available independently of sophisticated geographic systems. There is a
circle object for flat two dimensional space, but earth deals with
spherical caps. It would not be exact but enough to suppose that earth is a
sphere and that all dimensions latitude, longitude and distance are in
radian.
What would need to be done to adapt the circle type to a new type
'spherical cap' that would allow simple geographic indexing?

--
Olivier Chaussavoine

--
Olivier Chaussavoine

#8Brent Wood
Brent.Wood@niwa.co.nz
In reply to: Olivier Chaussavoine (#6)
Re: earthdistance

Is there not a precompiled Postgis package you can use?

There are a few dependencies, the PROJ.4 libraries you are missing enable projection support, and the package tools automatically manage such dependencies. I know packages are well supported for Debian, Ubuntu/Mint/etc, Suse & Fedora.

See: http://trac.osgeo.org/postgis/wiki/UsersWikiInstall

Brent Wood

Programme leader: Environmental Information Delivery
NIWA
DDI: +64 (4) 3860529
________________________________________
From: pgsql-general-owner@postgresql.org [pgsql-general-owner@postgresql.org] on behalf of Olivier Chaussavoine [olivier.chaussavoine@gmail.com]
Sent: Saturday, August 10, 2013 10:17 PM
To: John R Pierce
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] earthdistance

As a simple potential user, I tried to install PostGIS, downloaded all libraries required: proj-4.8.0, gdal-1.10.0,json-c,postgis-2.0.3,geos-3.3.8,libwml2-2.9.0, and tried to build the first library with the simple procedure:

./configure
make
make install

I had a fatal error:

make[2]: entrant dans le répertoire « /home/olivier/ob/proj-4.8.0/src »
/bin/bash ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -DPROJ_LIB=\"/usr/local/share/proj\" -DMUTEX_pthread -g -O2 -MT jniproj.lo -MD -MP -MF .deps/jniproj.Tpo -c -o jniproj.lo jniproj.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -DPROJ_LIB=\"/usr/local/share/proj\" -DMUTEX_pthread -g -O2 -MT jniproj.lo -MD -MP -MF .deps/jniproj.Tpo -c jniproj.c -fPIC -DPIC -o .libs/jniproj.o
jniproj.c:52:26: fatal error: org_proj4_PJ.h: No such file or directory
compilation terminated.

problem out of the scope of this list, and probably not /difficult. Since I look for a simple geographic indexing using imprecise lat,long coordinates that do not deal with precise modeling; that I am afraid of long install procedure, and heavy computations, I also give up.

Spacial mysql indexing seems to be included in pre-built packages.

What can we do?

2013/8/10 John R Pierce <pierce@hogranch.com<mailto:pierce@hogranch.com>>
On 8/9/2013 5:18 PM, Brent Wood wrote:

You might install Postgis to implement very powerful spatial functionality that can easily do what you are asking (plus a whole lot more).

indeed, PostGIS is the logical answer, but the OP specifically stated he wanted the functionality without 'sophisticated geographic systems'. so I ignored the question.

the alternative would be implementing your own spherical geometry functions, and hook them up to GiST indexing, its not that hard, but by the time you got all the functionality you need, you'd be half way to PostGIS, so why fight it?

--
john r pierce 37N 122W
somewhere on the middle of the left coast

--
Olivier Chaussavoine
--
Please consider the environment before printing this email.
NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#9Rob Sargent
robjsargent@gmail.com
In reply to: Brent Wood (#8)
Re: earthdistance

I just recently built the postgis stack (unbuntu 12.4) and had to go to
the trunk (maybe 2.1) for postgis itself for a work-around a dependency
failure on, ircc, geos.

rjs

On 08/10/2013 04:03 PM, Brent Wood wrote:

Is there not a precompiled Postgis package you can use?

There are a few dependencies, the PROJ.4 libraries you are missing enable projection support, and the package tools automatically manage such dependencies. I know packages are well supported for Debian, Ubuntu/Mint/etc, Suse & Fedora.

See: http://trac.osgeo.org/postgis/wiki/UsersWikiInstall

Brent Wood

Programme leader: Environmental Information Delivery
NIWA
DDI: +64 (4) 3860529
________________________________________
From: pgsql-general-owner@postgresql.org [pgsql-general-owner@postgresql.org] on behalf of Olivier Chaussavoine [olivier.chaussavoine@gmail.com]
Sent: Saturday, August 10, 2013 10:17 PM
To: John R Pierce
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] earthdistance

As a simple potential user, I tried to install PostGIS, downloaded all libraries required: proj-4.8.0, gdal-1.10.0,json-c,postgis-2.0.3,geos-3.3.8,libwml2-2.9.0, and tried to build the first library with the simple procedure:

./configure
make
make install

I had a fatal error:

make[2]: entrant dans le r�pertoire � /home/olivier/ob/proj-4.8.0/src �
/bin/bash ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -DPROJ_LIB=\"/usr/local/share/proj\" -DMUTEX_pthread -g -O2 -MT jniproj.lo -MD -MP -MF .deps/jniproj.Tpo -c -o jniproj.lo jniproj.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -DPROJ_LIB=\"/usr/local/share/proj\" -DMUTEX_pthread -g -O2 -MT jniproj.lo -MD -MP -MF .deps/jniproj.Tpo -c jniproj.c -fPIC -DPIC -o .libs/jniproj.o
jniproj.c:52:26: fatal error: org_proj4_PJ.h: No such file or directory
compilation terminated.

problem out of the scope of this list, and probably not /difficult. Since I look for a simple geographic indexing using imprecise lat,long coordinates that do not deal with precise modeling; that I am afraid of long install procedure, and heavy computations, I also give up.

Spacial mysql indexing seems to be included in pre-built packages.

What can we do?

2013/8/10 John R Pierce <pierce@hogranch.com<mailto:pierce@hogranch.com>>
On 8/9/2013 5:18 PM, Brent Wood wrote:

You might install Postgis to implement very powerful spatial functionality that can easily do what you are asking (plus a whole lot more).

indeed, PostGIS is the logical answer, but the OP specifically stated he wanted the functionality without 'sophisticated geographic systems'. so I ignored the question.

the alternative would be implementing your own spherical geometry functions, and hook them up to GiST indexing, its not that hard, but by the time you got all the functionality you need, you'd be half way to PostGIS, so why fight it?

--
john r pierce 37N 122W
somewhere on the middle of the left coast

--
Olivier Chaussavoine
--
Please consider the environment before printing this email.
NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#10Bruno Wolff III
bruno@wolff.to
In reply to: Olivier Chaussavoine (#7)
Re: earthdistance

On Sat, Aug 10, 2013 at 12:18:48 +0200,
Olivier Chaussavoine <olivier.chaussavoine@gmail.com> wrote:

I did not found any geographic indexing with earthdistance, and need it.

Some of the earthdistance stuff is based on cube which does have indexing.
I don't know how well that indexing works and it might be pretty bad in
practice.

The need I have is simple:
"is the distance between two (lat,long) positions less than X km?"
the model used for the shape of the earth should be related to the
precision of lat,lon, and most sources are imprecise. The spherical model
should be enough.

You might just be looking at this wrong. You don't have an index on the
distance. What you want is to find points within a cube that is big enough
to include all of the points of interest and then double check the returned
points to make sure they are really within the expected range. You can
calculate the size of the cube needed based on the distance and the
radius of the earth. I don't remember if there was a built in function
for that, since it's been such a long time since I looked at it.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#11Olivier Chaussavoine
olivier.chaussavoine@gmail.com
In reply to: Bruno Wolff III (#10)
Re: earthdistance

I also look at cube extension, but the built in type box - a couple of
points - does not require any extension and has a GIST index. It can be
used to represent a rectangle on the domain [-PI/2,+PI/2[*[-PI,PI[. If the
extension was providing a function get_rect_from_cap() giving the smallest
rectangle of this domain containing a spherical cap, this rectangle could
be used as you pointed out to reduce the set of rows where the earth
distance need to be computed to know if a point A belongs to the cap. The
operator && (box overlaps box) could be used if the point A is converted to
box(A,A). Do you think this function get_rect_from_cap() could be usefull?

2013/8/11 Bruno Wolff III <bruno@wolff.to>

On Sat, Aug 10, 2013 at 12:18:48 +0200,
Olivier Chaussavoine <olivier.chaussavoine@gmail.**com<olivier.chaussavoine@gmail.com>>
wrote:

I did not found any geographic indexing with earthdistance, and need it.

Some of the earthdistance stuff is based on cube which does have indexing.
I don't know how well that indexing works and it might be pretty bad in
practice.

The need I have is simple:

"is the distance between two (lat,long) positions less than X km?"
the model used for the shape of the earth should be related to the
precision of lat,lon, and most sources are imprecise. The spherical model
should be enough.

You might just be looking at this wrong. You don't have an index on the
distance. What you want is to find points within a cube that is big enough
to include all of the points of interest and then double check the returned
points to make sure they are really within the expected range. You can
calculate the size of the cube needed based on the distance and the radius
of the earth. I don't remember if there was a built in function for that,
since it's been such a long time since I looked at it.

--
Olivier Chaussavoine

#12Bruno Wolff III
bruno@wolff.to
In reply to: Olivier Chaussavoine (#11)
Re: earthdistance

On Tue, Aug 20, 2013 at 20:38:51 +0200,
Olivier Chaussavoine <olivier.chaussavoine@gmail.com> wrote:

I also look at cube extension, but the built in type box - a couple of
points - does not require any extension and has a GIST index. It can be
used to represent a rectangle on the domain [-PI/2,+PI/2[*[-PI,PI[. If the
extension was providing a function get_rect_from_cap() giving the smallest
rectangle of this domain containing a spherical cap, this rectangle could
be used as you pointed out to reduce the set of rows where the earth
distance need to be computed to know if a point A belongs to the cap. The
operator && (box overlaps box) could be used if the point A is converted to
box(A,A). Do you think this function get_rect_from_cap() could be usefull?

Depending on how the sphere is represented, getting the minimum bounding
cube is pretty simple and it might not be worth writing a function for
this.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general