Thread: earthdistance
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
You might install Postgis to implement very powerful spatial functionality that can easily do what you are asking (plus awhole 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. Itwould be nice to have these functions available independently of sophisticated geographic systems. There is a circle objectfor flat two dimensional space, but earth deals with spherical caps. It would not be exact but enough to suppose thatearth 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.
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
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
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:
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
./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.
Spacial mysql indexing seems to be included in pre-built packages.
indeed, PostGIS is the logical answer, but the OP specifically stated he wanted the functionality without 'sophisticated geographic systems'. so I ignored the question.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).
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
"is the distance between two (lat,long) positions less than X km?"
* 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.
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
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 automaticallymanage 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 impreciselat,long coordinates that do not deal with precise modeling; that I am afraid of long install procedure, and heavycomputations, 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 awhole lot more). indeed, PostGIS is the logical answer, but the OP specifically stated he wanted the functionality without 'sophisticatedgeographic 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 thathard, 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.
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 automaticallymanage 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 usingimprecise lat,long coordinates that do not deal with precise modeling; that I am afraid of long install procedure, andheavy 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 (plusa whole lot more). > > > indeed, PostGIS is the logical answer, but the OP specifically stated he wanted the functionality without 'sophisticatedgeographic systems'. so I ignored the question. > > the alternative would be implementing your own spherical geometry functions, and hook them up to GiST indexing, its notthat 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. > >
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.
On Sat, Aug 10, 2013 at 12:18:48 +0200,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.
Olivier Chaussavoine <olivier.chaussavoine@gmail.com> wrote:I did not found any geographic indexing with earthdistance, and need it.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.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.
--
Olivier Chaussavoine
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.