Module: PostgisAdapter::Functions::PointFunctions
- Defined in:
- lib/postgis_adapter/functions/common.rb
Overview
POINT
Instance Method Summary collapse
-
#azimuth(other) ⇒ Object
The azimuth of the segment defined by the given Point geometries, or NULL if the two points are coincident.
-
#distance_sphere_to(other) ⇒ Object
Linear distance in meters between two lon/lat points.
-
#distance_spheroid_to(other, spheroid = EARTH_SPHEROID) ⇒ Object
Calculates the distance on an ellipsoid.
-
#inside_circle?(x, y, r) ⇒ Boolean
True if the geometry is a point and is inside the circle.
-
#where_on_line(line) ⇒ Object
Returns a float between 0 and 1 representing the location of the closest point on LineString to the given Point, as a fraction of total 2d line length.
Instance Method Details
#azimuth(other) ⇒ Object
The azimuth of the segment defined by the given Point geometries, or NULL if the two points are coincident. Return value is in radians.
The Azimuth is mathematical concept defined as the angle, in this case measured in radian, between a reference plane and a point.
Returns Float ST_Azimuth(geometry pointA, geometry pointB);
798 799 800 801 802 803 |
# File 'lib/postgis_adapter/functions/common.rb', line 798 def azimuth other #TODO: return if not point/point postgis_calculate(:azimuth, [self, other]).to_f rescue ActiveRecord::StatementInvalid end |
#distance_sphere_to(other) ⇒ Object
Linear distance in meters between two lon/lat points. Uses a spherical earth and radius of 6370986 meters. Faster than ‘distance_spheroid’, but less accurate.
Only implemented for points.
Returns Float ST_Distance_Sphere(geometry pointlonlatA, geometry pointlonlatB);
762 763 764 |
# File 'lib/postgis_adapter/functions/common.rb', line 762 def distance_sphere_to(other) postgis_calculate(:distance_sphere, [self, other]).to_f end |
#distance_spheroid_to(other, spheroid = EARTH_SPHEROID) ⇒ Object
Calculates the distance on an ellipsoid. This is useful if the coordinates of the geometry are in longitude/latitude and a length is desired without reprojection. The ellipsoid is a separate database type and can be constructed as follows:
This is slower then ‘distance_sphere_to’, but more precise.
SPHEROID[<NAME>,<SEMI-MAJOR AXIS>,<INVERSE FLATTENING>]
Example:
SPHEROID["GRS_1980",6378137,298.257222101]
Defaults to:
SPHEROID["IERS_2003",6378136.6,298.25642]
Returns ST_Distance_Spheroid(geometry geomA, geometry geomB, spheroid);
785 786 787 |
# File 'lib/postgis_adapter/functions/common.rb', line 785 def distance_spheroid_to(other, spheroid = EARTH_SPHEROID) postgis_calculate(:distance_spheroid, [self, other], spheroid).to_f end |
#inside_circle?(x, y, r) ⇒ Boolean
True if the geometry is a point and is inside the circle.
Returns Boolean ST_point_inside_circle(geometry, float, float, float)
810 811 812 |
# File 'lib/postgis_adapter/functions/common.rb', line 810 def inside_circle?(x,y,r) postgis_calculate(:point_inside_circle, self, [x,y,r]) end |
#where_on_line(line) ⇒ Object
Returns a float between 0 and 1 representing the location of the closest point on LineString to the given Point, as a fraction of total 2d line length.
You can use the returned location to extract a Point (ST_Line_Interpolate_Point) or a substring (ST_Line_Substring).
This is useful for approximating numbers of addresses.
Returns float (0 to 1) ST_Line_Locate_Point(geometry a_linestring, geometry a_point);
749 750 751 |
# File 'lib/postgis_adapter/functions/common.rb', line 749 def where_on_line line postgis_calculate(:line_locate_point, [line, self]).to_f end |