Module: PostgisAdapter::Functions::LineStringFunctions

Defined in:
lib/postgis_adapter/functions/common.rb

Overview

LINESTRING

Instance Method Summary collapse

Instance Method Details

#crosses?(other) ⇒ Boolean

Takes two geometry objects and returns TRUE if their intersection “spatially cross”, that is, the geometries have some, but not all interior points in common. The intersection of the interiors of the geometries must not be the empty set and must have a dimensionality less than the the maximum dimension of the two input geometries. Additionally, the intersection of the two geometries must not equal either of the source geometries. Otherwise, it returns FALSE.

Returns Boolean ST_Crosses(geometry g1, geometry g2);

Returns:

  • (Boolean)


626
627
628
# File 'lib/postgis_adapter/functions/common.rb', line 626

def crosses? other
  postgis_calculate(:crosses, [self, other])
end

#end_pointObject

Returns geometry end point.



610
611
612
# File 'lib/postgis_adapter/functions/common.rb', line 610

def end_point
  postgis_calculate(:endpoint, self)
end

#interpolate_point(fraction) ⇒ Object

Returns a point interpolated along a line. First argument must be a LINESTRING. Second argument is a float8 between 0 and 1 representing fraction of total linestring length the point has to be located.

See ST_Line_Locate_Point for computing the line location nearest to a Point.

Returns geometry ST_Line_Interpolate_Point(geometry a_linestring, float a_fraction);



687
688
689
# File 'lib/postgis_adapter/functions/common.rb', line 687

def interpolate_point(fraction)
  postgis_calculate(:line_interpolate_point, self, fraction)
end

#lengthObject

Returns the 2D length of the geometry if it is a linestring, multilinestring, ST_Curve, ST_MultiCurve. 0 is returned for areal geometries. For areal geometries use ‘perimeter’. Measurements are in the units of the spatial reference system of the geometry.

Returns Float



554
555
556
# File 'lib/postgis_adapter/functions/common.rb', line 554

def length
  postgis_calculate(:length, self).to_f
end

#length_3dObject

Returns the 3-dimensional or 2-dimensional length of the geometry if it is a linestring or multi-linestring. For 2-d lines it will just return the 2-d length (same as ‘length’)

Returns Float



565
566
567
# File 'lib/postgis_adapter/functions/common.rb', line 565

def length_3d
  postgis_calculate(:length3d, self).to_f
end

#length_spheroid(spheroid = EARTH_SPHEROID) ⇒ Object

Calculates the length of a geometry 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:

SPHEROID[<NAME>,<SEMI-MAJOR AXIS>,<INVERSE FLATTENING>]

Example:

SPHEROID["GRS_1980",6378137,298.257222101]

Defaults to:

SPHEROID["IERS_2003",6378136.6,298.25642]

Returns Float length_spheroid(geometry linestring, spheroid);



586
587
588
# File 'lib/postgis_adapter/functions/common.rb', line 586

def length_spheroid(spheroid = EARTH_SPHEROID)
  postgis_calculate(:length_spheroid, self, spheroid).to_f
end

#line_crossing_direction(other) ⇒ Object

Warning: PostGIS 1.4+

Return crossing direction



634
635
636
# File 'lib/postgis_adapter/functions/common.rb', line 634

def line_crossing_direction(other)
  postgis_calculate(:lineCrossingDirection, [self, other])
end

#line_mergeObject

Returns a (set of) LineString(s) formed by sewing together a MULTILINESTRING.

Only use with MULTILINESTRING/LINESTRINGs. If you feed a polygon or geometry collection into this function, it will return an empty GEOMETRYCOLLECTION

Returns geometry ST_LineMerge(geometry amultilinestring);



722
723
724
# File 'lib/postgis_adapter/functions/common.rb', line 722

def line_merge
  postgis_calculate(:LineMerge, self, { :stcollect => self})
end

#line_substring(s, e) ⇒ Object

Return a linestring being a substring of the input one starting and ending at the given fractions of total 2d length. Second and third arguments are float8 values between 0 and 1. This only works with LINESTRINGs. To use with contiguous MULTILINESTRINGs use in conjunction with ST_LineMerge.

If ‘start’ and ‘end’ have the same value this is equivalent to ‘interpolate_point’.

See ‘locate_point’ for computing the line location nearest to a Point.

Returns geometry ST_Line_Substring(geometry a_linestring, float startfraction, float endfraction);



703
704
705
# File 'lib/postgis_adapter/functions/common.rb', line 703

def line_substring(s,e)
  postgis_calculate(:line_substring, self, [s, e])
end

#locate_along_measure(measure) ⇒ Object

Return a derived geometry collection value with elements that match the specified measure. Polygonal elements are not supported.

Semantic is specified by: ISO/IEC CD 13249-3:200x(E) - Text for Continuation CD Editing Meeting

Returns geometry ST_Locate_Along_Measure(geometry ageom_with_measure, float a_measure);



662
663
664
# File 'lib/postgis_adapter/functions/common.rb', line 662

def locate_along_measure(measure)
  postgis_calculate(:locate_along_measure, self, measure)
end

#locate_between_measures(a, b) ⇒ Object

Return a derived geometry collection value with elements that match the specified range of measures inclusively. Polygonal elements are not supported.

Semantic is specified by: ISO/IEC CD 13249-3:200x(E) - Text for Continuation CD Editing Meeting

Returns geometry ST_Locate_Between_Measures(geometry geomA, float measure_start, float measure_end);



674
675
676
# File 'lib/postgis_adapter/functions/common.rb', line 674

def locate_between_measures(a, b)
  postgis_calculate(:locate_between_measures, self, [a,b])
end

#locate_point(point) ⇒ 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);



649
650
651
# File 'lib/postgis_adapter/functions/common.rb', line 649

def locate_point point
  postgis_calculate(:line_locate_point, [self, point]).to_f
end

#num_pointsObject

Return the number of points of the geometry. PostGis ST_NumPoints does not work as nov/08

Returns Integer ST_NPoints(geometry g1);



596
597
598
# File 'lib/postgis_adapter/functions/common.rb', line 596

def num_points
  postgis_calculate(:npoints, self).to_i
end

#start_pointObject

Returns geometry start point.



603
604
605
# File 'lib/postgis_adapter/functions/common.rb', line 603

def start_point
  postgis_calculate(:startpoint, self)
end