📄 readme.earthdistance
字号:
This contrib package contains two different approaches to calculatinggreat circle distances on the surface of the Earth. The one describedfirst depends on the contrib/cube package (which MUST be installed beforeearthdistance is installed). The second one is based on the pointdatatype using latitude and longitude for the coordinates. The installscript makes the defined functions executable by anyone.Make sure contrib/cube has been installed.makemake installmake installcheckTo use these functions in a particular database as a postgres superuser do:psql databasename < earthdistance.sql-------------------------------------------contrib/cube based Earth distance functionsBruno Wolff IIISeptember 2002A spherical model of the Earth is used.Data is stored in cubes that are points (both corners are the same) using 3coordinates representing the distance from the center of the Earth.The radius of the Earth is obtained from the earth() function. It isgiven in meters. But by changing this one function you can change itto use some other units or to use a different value of the radiusthat you feel is more appropiate.This package also has applications to astronomical databases as well.Astronomers will probably want to change earth() to return a radius of180/pi() so that distances are in degrees.Functions are provided to allow for input in latitude and longitude (indegrees), to allow for output of latitude and longitude, to calculatethe great circle distance between two points and to easily specify abounding box usable for index searches.The functions are all 'sql' functions. If you want to make these functionsexecutable by other people you will also have to make the referencedcube functions executable. cube(text), cube(float8), cube(cube,float8),cube_distance(cube,cube), cube_ll_coord(cube,int) andcube_enlarge(cube,float8,int) are used indirectly by the earth distancefunctions. is_point(cube) and cube_dim(cube) are used in constraints for datain domain earth. cube_ur_coord(cube,int) is used in the regression tests andmight be useful for looking at bounding box coordinates in user applications.A domain of type cube named earth is defined.There are constraints on it defined to make sure the cube is a point,that it does not have more than 3 dimensions and that it is very nearthe surface of a sphere centered about the origin with the radius ofthe Earth.The following functions are provided:earth() - Returns the radius of the Earth in meters.sec_to_gc(float8) - Converts the normal straight line (secant) distance betweenbetween two points on the surface of the Earth to the great circle distancebetween them.gc_to_sec(float8) - Converts the great circle distance between two pointson the surface of the Earth to the normal straight line (secant) distancebetween them.ll_to_earth(float8, float8) - Returns the location of a point on the surfaceof the Earth given its latitude (argument 1) and longitude (argument 2) indegrees.latitude(earth) - Returns the latitude in degrees of a point on the surfaceof the Earth.longitude(earth) - Returns the longitude in degrees of a point on the surfaceof the Earth.earth_distance(earth, earth) - Returns the great circle distance betweentwo points on the surface of the Earth.earth_box(earth, float8) - Returns a box suitable for an indexed search usingthe cube @> operator for points within a given great circle distance of alocation. Some points in this box are further than the specified great circledistance from the location so a second check using earth_distance should bemade at the same time.One advantage of using cube representation over a point using latitude andlongitude for coordinates, is that you don't have to worry about specialconditions at +/- 180 degrees of longitude or near the poles.Below is the documentation for the Earth distance operator that workswith the point data type.---------------------------------------------------------------------I corrected a bug in the geo_distance code where two double constantswere declared as int. I also changed the distance function to usethe haversine formula which is more accurate for small distances.Bruno WolffSeptember 2002---------------------------------------------------------------------Date: Wed, 1 Apr 1998 15:19:32 -0600 (CST)From: Hal Snyder <hal@vailsys.com>To: vmehr@ctp.comSubject: [QUESTIONS] Re: Spatial data, R-Trees> From: Vivek Mehra <vmehr@ctp.com>> Date: Wed, 1 Apr 1998 10:06:50 -0500> Am just starting out with PostgreSQL and would like to learn more about> the spatial data handling ablilities of postgreSQL - in terms of using> R-tree indexes, user defined types, operators and functions. > > Would you be able to suggest where I could find some code and SQL to> look at to create these?Here's the setup for adding an operator '<@>' to give distance instatute miles between two points on the Earth's surface. Coordinatesare in degrees. Points are taken as (longitude, latitude) and not viceversa as longitude is closer to the intuitive idea of x-axis andlatitude to y-axis.There's C source, Makefile for FreeBSD, and SQL for installing andtesting the function.Let me know if anything looks fishy!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -