Module: PostgisFunctions
- Defined in:
- lib/postgis_functions.rb,
lib/postgis_functions/bbox.rb,
lib/postgis_functions/class.rb,
lib/postgis_functions/common.rb,
lib/postgis_adapter/acts_as_geom.rb
Overview
PostGIS Adapter
Defined Under Namespace
Modules: ClassMethods, LineStringFunctions, PointFunctions, PolygonFunctions
Constant Summary collapse
- EARTH_SPHEROID =
WGS84 Spheroid
"'SPHEROID[\"GRS-80\",6378137,298.257222101]'"
Class Method Summary collapse
Instance Method Summary collapse
-
#as_geo_json(precision = 15, bbox = 0) ⇒ Object
Returns Geometry as GeoJSON.
-
#bbox(operator, other) ⇒ Object
These operators utilize indexes.
-
#binary_equal?(other) ⇒ Boolean
bbox literal method.
-
#boundary ⇒ Object
Returns the closure of the combinatorial boundary of this Geometry.
- #buffer(width = 0.1) ⇒ Object
-
#build_area ⇒ Object
Creates an areal geometry formed by the constituent linework of given geometry.
-
#centroid ⇒ Object
Computes the geometric center of a geometry, or equivalently, the center of mass of the geometry as a POINT.
-
#completely_contained_by?(other) ⇒ Boolean
bbox literal method.
-
#completely_contains?(other) ⇒ Boolean
bbox literal method.
-
#contains?(other) ⇒ Boolean
True if geometry B is completely inside geometry A.
-
#convex_hull ⇒ Object
The convex hull of a geometry represents the minimum closed geometry that encloses all geometries within the set.
-
#covered_by?(other) ⇒ Boolean
(also: #inside?)
True if no point in Geometry A is outside Geometry B.
-
#d_within?(other, margin = 0.1) ⇒ Boolean
(also: #in_bounds?)
True if the geometries are within the specified distance of one another.
-
#dimension ⇒ Object
How many dimensions the geom is made of (2, 3 or 4).
-
#disjoint?(other) ⇒ Boolean
True if the Geometries do not “spatially intersect” - if they do not share any space together.
-
#distance_to(other) ⇒ Object
2D minimum cartesian distance between two geometries in projected units.
-
#envelope ⇒ Object
Returns the minimum bounding box for the supplied geometry, as a geometry.
-
#envelopes_intersect?(other) ⇒ Boolean
True if a Geometry`s Envelope “spatially intersect”, share any portion of space.
- #geo_columns ⇒ Object
-
#interacts_with?(other) ⇒ Boolean
bbox literal method.
-
#intersection(other) ⇒ Object
Geometry that represents the point set intersection of the Geometries.
-
#intersects?(other) ⇒ Boolean
True if Geometries “spatially intersect”, share any portion of space.
-
#is_simple? ⇒ Boolean
(also: #simple?)
Returns true if this Geometry has no anomalous geometric points, such as self intersection or self tangency.
-
#outside?(other) ⇒ Boolean
Eye-candy.
-
#overlaps?(other) ⇒ Boolean
True if the Geometries share space, are of the same dimension, but are not completely contained by each other.
-
#overlaps_or_above?(other) ⇒ Boolean
bbox literal method.
-
#overlaps_or_below?(other) ⇒ Boolean
bbox literal method.
-
#overlaps_or_left_of?(other) ⇒ Boolean
bbox literal method.
-
#overlaps_or_right_of?(other) ⇒ Boolean
bbox literal method.
-
#point_on_surface ⇒ Object
ST_PointOnSurface — Returns a POINT guaranteed to lie on the surface.
-
#polygonize ⇒ Object
Aggregate.
-
#postgis_calculate(operation, subjects, options = {}) ⇒ Object
SRID => 4326.
-
#relate?(other, m = nil) ⇒ Boolean
Returns true if this Geometry is spatially related to anotherGeometry, by testing for intersections between the Interior, Boundary and Exterior of the two geometries as specified by the values in the intersectionPatternMatrix.
-
#same_as?(other) ⇒ Boolean
bbox literal method.
-
#segmentize(max_length = 1.0) ⇒ Object
Returns a modified geometry having no segment longer than the given distance.
-
#simplify(tolerance = 0.1) ⇒ Object
Returns a “simplified” version of the given geometry using the Douglas-Peuker algorithm.
- #simplify!(tolerance = 0.1) ⇒ Object
-
#simplify_preserve_topology(tolerance = 0.1) ⇒ Object
Returns a “simplified” version of the given geometry using the Douglas-Peuker algorithm.
-
#spatially_equal?(other) ⇒ Boolean
True if the given geometries represent the same geometry.
-
#srid ⇒ Object
Returns the instance`s geom srid.
- #st_collect(other = nil) ⇒ Object
-
#strictly_above?(other) ⇒ Boolean
bbox literal method.
-
#strictly_below?(other) ⇒ Boolean
bbox literal method.
-
#strictly_left_of?(other) ⇒ Boolean
bbox literal method.
-
#strictly_right_of?(other) ⇒ Boolean
bbox literal method.
- #to_utm ⇒ Object
-
#to_utm!(utm = nil) ⇒ Object
Returns the Geometry in its UTM Zone.
-
#touches?(other) ⇒ Boolean
True if the geometries have at least one point in common, but their interiors do not intersect.
- #transform(new_srid) ⇒ Object
-
#transform!(new_srid) ⇒ Object
Transform the geometry into a different spatial reference system.
-
#utm_zone ⇒ Object
Return UTM Zone for a geom.
-
#valid_geom? ⇒ Boolean
Test if a geometry is well formed.
-
#within?(other) ⇒ Boolean
True if geometry A is completely inside geometry B.
Class Method Details
.included(base) ⇒ Object
7 8 9 |
# File 'lib/postgis_adapter/acts_as_geom.rb', line 7 def self.included(base) base.send :extend, ClassMethods end |
Instance Method Details
#as_geo_json(precision = 15, bbox = 0) ⇒ Object
Returns Geometry as GeoJSON
524 525 526 |
# File 'lib/postgis_functions/common.rb', line 524 def as_geo_json(precision=15, bbox=0) postgis_calculate(:AsGeoJSON, self, [precision, bbox]) end |
#bbox(operator, other) ⇒ Object
These operators utilize indexes. They compare geometries by bounding boxes.
You can use the literal forms or call directly using the ‘bbox’ method. eg.:
@point.bbox(">>", @area)
@point.bbox("|&>", @area)
Cheatsheet:
A &< B => A overlaps or is to the left of B
A &> B => A overlaps or is to the right of B
A << B => A is strictly to the left of B
A >> B => A is strictly to the right of B
A &<| B => A overlaps B or is below B
A |&> B => A overlaps or is above B
A <<| B => A strictly below B
A |>> B => A strictly above B
A = B => A bbox same as B bbox
A @ B => A completely contained by B
A ~ B => A completely contains B
A && B => A and B bboxes interact
A ~= B => A and B geometries are binary equal?
34 35 36 |
# File 'lib/postgis_functions/bbox.rb', line 34 def bbox(operator, other) postgis_calculate(:bbox, [self, other], operator) end |
#binary_equal?(other) ⇒ Boolean
bbox literal method.
118 119 120 |
# File 'lib/postgis_functions/bbox.rb', line 118 def binary_equal? other bbox("~=", other) end |
#boundary ⇒ Object
Returns the closure of the combinatorial boundary of this Geometry. The combinatorial boundary is defined as described in section 3.12.3.2 of the OGC SPEC. Because the result of this function is a closure, and hence topologically closed, the resulting boundary can be represented using representational geometry primitives as discussed in the OGC SPEC, section 3.12.2.
Do not call with a GEOMETRYCOLLECTION as an argument.
Performed by the GEOS module.
Returns Geometry ST_Boundary(geometry geomA);
99 100 101 |
# File 'lib/postgis_functions/common.rb', line 99 def boundary postgis_calculate(:boundary, self) end |
#buffer(width = 0.1) ⇒ Object
249 250 251 |
# File 'lib/postgis_functions/common.rb', line 249 def buffer(width=0.1) postgis_calculate(:buffer,self,width) end |
#build_area ⇒ Object
Creates an areal geometry formed by the constituent linework of given geometry. The return type can be a Polygon or MultiPolygon, depending on input. If the input lineworks do not form polygons NULL is returned. The inputs can be LINESTRINGS, MULTILINESTRINGS, POLYGONS, MULTIPOLYGONS, and GeometryCollections.
Returns Boolean ST_BuildArea(geometry A);
372 373 374 |
# File 'lib/postgis_functions/common.rb', line 372 def build_area postgis_calculate(:buildarea, self) end |
#centroid ⇒ Object
Computes the geometric center of a geometry, or equivalently, the center of mass of the geometry as a POINT. For [MULTI]POINTs, this is computed as the arithmetric mean of the input coordinates. For [MULTI]LINESTRINGs, this is computed as the weighted length of each line segment. For [MULTI]POLYGONs, “weight” is thought in terms of area. If an empty geometry is supplied, an empty GEOMETRYCOLLECTION is returned. If NULL is supplied, NULL is returned.
The centroid is equal to the centroid of the set of component Geometries of highest dimension (since the lower-dimension geometries contribute zero “weight” to the centroid).
Computation will be more accurate if performed by the GEOS module (enabled at compile time).
postgis.refractions.net/documentation/manual-svn/ST_Centroid.html
Returns Geometry ST_Centroid(geometry g1);
82 83 84 |
# File 'lib/postgis_functions/common.rb', line 82 def centroid postgis_calculate(:centroid, self) end |
#completely_contained_by?(other) ⇒ Boolean
bbox literal method.
41 42 43 |
# File 'lib/postgis_functions/bbox.rb', line 41 def completely_contained_by? other bbox("@", other) end |
#completely_contains?(other) ⇒ Boolean
bbox literal method.
48 49 50 |
# File 'lib/postgis_functions/bbox.rb', line 48 def completely_contains? other bbox("~", other) end |
#contains?(other) ⇒ Boolean
True if geometry B is completely inside geometry A.
For this function to make sense, the source geometries must both be of the same coordinate projection, having the same SRID. ‘contains?’ is the inverse of ‘within?’.
So a.contains?(b) is like b.within?(a) except in the case of invalid geometries where the result is always false regardless or not defined.
Do not call with a GEOMETRYCOLLECTION as an argument Do not use this function with invalid geometries. You will get unexpected results.
Performed by the GEOS module
Returns Boolean ST_Contains(geometry geomA, geometry geomB);
164 165 166 |
# File 'lib/postgis_functions/common.rb', line 164 def contains? other postgis_calculate(:contains, [self, other]) end |
#convex_hull ⇒ Object
The convex hull of a geometry represents the minimum closed geometry that encloses all geometries within the set.
It is usually used with MULTI and Geometry Collections. Although it is not an aggregate - you can use it in conjunction with ST_Collect to get the convex hull of a set of points. ST_ConvexHull(ST_Collect(somepointfield)). It is often used to determine an affected area based on a set of point observations.
Performed by the GEOS module.
Returns Geometry ST_ConvexHull(geometry geomA);
360 361 362 |
# File 'lib/postgis_functions/common.rb', line 360 def convex_hull postgis_calculate(:convexhull, self) end |
#covered_by?(other) ⇒ Boolean Also known as: inside?
True if no point in Geometry A is outside Geometry B
This function call will automatically include a bounding box comparison that will make use of any indexes that are available on the geometries. To avoid index use, use the function _ST_CoveredBy.
Do not call with a GEOMETRYCOLLECTION as an argument. Do not use this function with invalid geometries. You will get unexpected results.
Performed by the GEOS module.
Aliased as ‘inside?’
Returns Boolean ST_CoveredBy(geometry geomA, geometry geomB);
184 185 186 |
# File 'lib/postgis_functions/common.rb', line 184 def covered_by? other postgis_calculate(:coveredby, [self, other]) end |
#d_within?(other, margin = 0.1) ⇒ Boolean Also known as: in_bounds?
True if the geometries are within the specified distance of one another. The distance is specified in units defined by the spatial reference system of the geometries. For this function to make sense, the source geometries must both be of the same coorindate projection, having the same SRID.
Returns boolean ST_DWithin(geometry g1, geometry g2, double precision distance);
143 144 145 |
# File 'lib/postgis_functions/common.rb', line 143 def d_within?(other, margin=0.1) postgis_calculate(:dwithin, [self, other], margin) end |
#dimension ⇒ Object
How many dimensions the geom is made of (2, 3 or 4)
Returns Integer ST_Dimension(geom g1)
219 220 221 |
# File 'lib/postgis_functions/common.rb', line 219 def dimension postgis_calculate(:dimension, self).to_i end |
#disjoint?(other) ⇒ Boolean
True if the Geometries do not “spatially intersect” - if they do not share any space together.
Overlaps, Touches, Within all imply geometries are not spatially disjoint. If any of the aforementioned returns true, then the geometries are not spatially disjoint. Disjoint implies false for spatial intersection.
Do not call with a GEOMETRYCOLLECTION as an argument.
Returns boolean ST_Disjoint( geometry A , geometry B );
210 211 212 |
# File 'lib/postgis_functions/common.rb', line 210 def disjoint? other postgis_calculate(:disjoint, [self, other]) end |
#distance_to(other) ⇒ Object
2D minimum cartesian distance between two geometries in projected units.
Returns Float ST_Distance(geometry g1, geometry g2);
108 109 110 |
# File 'lib/postgis_functions/common.rb', line 108 def distance_to(other) postgis_calculate(:distance, [self, other]).to_f end |
#envelope ⇒ Object
Returns the minimum bounding box for the supplied geometry, as a geometry. The polygon is defined by the corner points of the bounding box ((MINX, MINY), (MINX, MAXY), (MAXX, MAXY), (MAXX, MINY), (MINX, MINY)). PostGIS will add a ZMIN/ZMAX coordinate as well/
Degenerate cases (vertical lines, points) will return a geometry of lower dimension than POLYGON, ie. POINT or LINESTRING.
In PostGIS, the bounding box of a geometry is represented internally using float4s instead of float8s that are used to store geometries. The bounding box coordinates are floored, guarenteeing that the geometry is contained entirely within its bounds. This has the advantage that a geometry’s bounding box is half the size as the minimum bounding rectangle, which means significantly faster indexes and general performance. But it also means that the bounding box is NOT the same as the minimum bounding rectangle that bounds the geome.
Returns GeometryCollection ST_Envelope(geometry g1);
59 60 61 |
# File 'lib/postgis_functions/common.rb', line 59 def envelope postgis_calculate(:envelope, self) end |
#envelopes_intersect?(other) ⇒ Boolean
True if a Geometry`s Envelope “spatially intersect”, share any portion of space.
It`s ‘intersects?’, for envelopes.
Returns Boolean SE_EnvelopesIntersect(geometry geomA, geometry geomB);
289 290 291 |
# File 'lib/postgis_functions/common.rb', line 289 def envelopes_intersect? other postgis_calculate(:se_envelopesintersect, [self, other]) end |
#geo_columns ⇒ Object
27 28 29 |
# File 'lib/postgis_functions.rb', line 27 def geo_columns @geo_columns ||= postgis_geoms[:columns] end |
#interacts_with?(other) ⇒ Boolean
bbox literal method.
111 112 113 |
# File 'lib/postgis_functions/bbox.rb', line 111 def interacts_with? other bbox("&&", other) end |
#intersection(other) ⇒ Object
Geometry that represents the point set intersection of the Geometries. In other words - that portion of geometry A and geometry B that is shared between the two geometries. If the geometries do not share any space (are disjoint), then an empty geometry collection is returned.
‘intersection’ in conjunction with intersects? is very useful for clipping geometries such as in bounding box, buffer, region queries where you only want to return that portion of a geometry that sits in a country or region of interest.
Do not call with a GEOMETRYCOLLECTION as an argument. Performed by the GEOS module.
Returns Geometry ST_Intersection(geometry geomA, geometry geomB);
308 309 310 |
# File 'lib/postgis_functions/common.rb', line 308 def intersection other postgis_calculate(:intersection, [self, other]) end |
#intersects?(other) ⇒ Boolean
True if Geometries “spatially intersect”, share any portion of space. False if they don’t (they are Disjoint).
‘overlaps?’, ‘touches?’, ‘within?’ all imply spatial intersection. If any of the aforementioned returns true, then the geometries also spatially intersect. ‘disjoint?’ implies false for spatial intersection.
Returns Boolean ST_Intersects(geometry geomA, geometry geomB);
278 279 280 |
# File 'lib/postgis_functions/common.rb', line 278 def intersects? other postgis_calculate(:intersects, [self, other]) end |
#is_simple? ⇒ Boolean Also known as: simple?
Returns true if this Geometry has no anomalous geometric points, such as self intersection or self tangency.
Returns boolean ST_IsSimple(geometry geomA);
382 383 384 |
# File 'lib/postgis_functions/common.rb', line 382 def is_simple? postgis_calculate(:issimple, self) end |
#outside?(other) ⇒ Boolean
Eye-candy. See ‘covered_by?’.
Returns !(Boolean ST_CoveredBy(geometry geomA, geometry geomB);)
194 195 196 |
# File 'lib/postgis_functions/common.rb', line 194 def outside? other !covered_by? other end |
#overlaps?(other) ⇒ Boolean
True if the Geometries share space, are of the same dimension, but are not completely contained by each other. They intersect, but one does not completely contain another.
Do not call with a GeometryCollection as an argument This function call will automatically include a bounding box comparison that will make use of any indexes that are available on the geometries. To avoid index use, use the function _ST_Overlaps.
Performed by the GEOS module.
Returns Boolean ST_Overlaps(geometry A, geometry B);
326 327 328 |
# File 'lib/postgis_functions/common.rb', line 326 def overlaps? other postgis_calculate(:overlaps, [self, other]) end |
#overlaps_or_above?(other) ⇒ Boolean
bbox literal method.
55 56 57 |
# File 'lib/postgis_functions/bbox.rb', line 55 def overlaps_or_above? other bbox("|&>", other) end |
#overlaps_or_below?(other) ⇒ Boolean
bbox literal method.
62 63 64 |
# File 'lib/postgis_functions/bbox.rb', line 62 def overlaps_or_below? other bbox("&<|", other) end |
#overlaps_or_left_of?(other) ⇒ Boolean
bbox literal method.
69 70 71 |
# File 'lib/postgis_functions/bbox.rb', line 69 def overlaps_or_left_of? other bbox("&<", other) end |
#overlaps_or_right_of?(other) ⇒ Boolean
bbox literal method.
76 77 78 |
# File 'lib/postgis_functions/bbox.rb', line 76 def overlaps_or_right_of? other bbox("&>", other) end |
#point_on_surface ⇒ Object
ST_PointOnSurface — Returns a POINT guaranteed to lie on the surface. geometry ST_PointOnSurface(geometry g1);eometry A, geometry B);
530 531 532 |
# File 'lib/postgis_functions/common.rb', line 530 def point_on_surface postgis_calculate(:pointonsurface, self) end |
#polygonize ⇒ Object
Aggregate. Creates a GeometryCollection containing possible polygons formed from the constituent linework of a set of geometries.
Geometry Collections are often difficult to deal with with third party tools, so use ST_Polygonize in conjunction with ST_Dump to dump the polygons out into
individual polygons.
Returns Geometry ST_Polygonize(geometry set geomfield);
397 398 399 |
# File 'lib/postgis_functions/common.rb', line 397 def polygonize postgis_calculate(:polygonize, self) end |
#postgis_calculate(operation, subjects, options = {}) ⇒ Object
SRID => 4326
22 23 24 25 |
# File 'lib/postgis_functions.rb', line 22 def postgis_calculate(operation, subjects, = {}) subjects = [subjects] unless subjects.respond_to?(:map) execute_geometrical_calculation(operation, subjects, ) end |
#relate?(other, m = nil) ⇒ Boolean
Returns true if this Geometry is spatially related to anotherGeometry, by testing for intersections between the Interior, Boundary and Exterior of the two geometries as specified by the values in the intersectionPatternMatrix. If no intersectionPatternMatrix is passed in, then returns the maximum intersectionPatternMatrix that relates the 2 geometries.
Version 1: Takes geomA, geomB, intersectionMatrix and Returns 1 (TRUE) if this Geometry is spatially related to anotherGeometry, by testing for intersections between the Interior, Boundary and Exterior of the two geometries as specified by the values in the intersectionPatternMatrix.
This is especially useful for testing compound checks of intersection, crosses, etc in one step.
Do not call with a GeometryCollection as an argument
This is the “allowable” version that returns a boolean, not an integer. This is defined in OGC spec. This DOES NOT automagically include an index call. The reason for that is some relationships are anti e.g. Disjoint. If you are using a relationship pattern that requires intersection, then include the && index call.
Version 2: Takes geomA and geomB and returns the DE-9IM (dimensionally extended nine-intersection matrix)
Do not call with a GeometryCollection as an argument Not in OGC spec, but implied. see s2.1.13.2
Both Performed by the GEOS module
Returns:
String ST_Relate(geometry geomA, geometry geomB);
Boolean ST_Relate(geometry geomA, geometry geomB, text intersectionPatternMatrix);
438 439 440 441 442 |
# File 'lib/postgis_functions/common.rb', line 438 def relate?(other, m = nil) # Relate is case sentitive....... m = "'#{m}'" if m postgis_calculate("Relate", [self, other], m) end |
#same_as?(other) ⇒ Boolean
bbox literal method.
125 126 127 |
# File 'lib/postgis_functions/bbox.rb', line 125 def same_as? other bbox("=", other) end |
#segmentize(max_length = 1.0) ⇒ Object
Returns a modified geometry having no segment longer than the given distance. Distance computation is performed in 2d only.
This will only increase segments. It will not lengthen segments shorter than max length
Return Geometry ST_Segmentize(geometry geomA, float max_length);
471 472 473 |
# File 'lib/postgis_functions/common.rb', line 471 def segmentize(max_length=1.0) postgis_calculate("segmentize", self, max_length) end |
#simplify(tolerance = 0.1) ⇒ Object
Returns a “simplified” version of the given geometry using the Douglas-Peuker algorithm. Will actually do something only with (multi)lines and (multi)polygons but you can safely call it with any kind of geometry. Since simplification occurs on a object-by-object basis you can also feed a GeometryCollection to this function.
Note that returned geometry might loose its simplicity (see ‘is_simple?’). Topology may not be preserved and may result in invalid geometries. Use ‘simplify_preserve_topology’ to preserve topology.
Performed by the GEOS Module.
Returns Geometry ST_Simplify(geometry geomA, float tolerance);
238 239 240 |
# File 'lib/postgis_functions/common.rb', line 238 def simplify(tolerance=0.1) postgis_calculate(:simplify, self, tolerance) end |
#simplify!(tolerance = 0.1) ⇒ Object
243 244 245 246 |
# File 'lib/postgis_functions/common.rb', line 243 def simplify!(tolerance=0.1) #FIXME: not good.. self.update_attribute(geo_columns.first, simplify) end |
#simplify_preserve_topology(tolerance = 0.1) ⇒ Object
Returns a “simplified” version of the given geometry using the Douglas-Peuker algorithm. Will avoid creating derived geometries (polygons in particular) that are invalid. Will actually do something only with (multi)lines and (multi)polygons but you can safely call it with any kind of geometry. Since simplification occurs on a object-by-object basis you can also feed a GeometryCollection to this function.
Performed by the GEOS module. Requires GEOS 3.0.0+
Returns Geometry ST_SimplifyPreserveTopology(geometry geomA, float tolerance);0.005
264 265 266 |
# File 'lib/postgis_functions/common.rb', line 264 def simplify_preserve_topology(tolerance=0.1) postgis_calculate(:simplifypreservetopology, self, tolerance) end |
#spatially_equal?(other) ⇒ Boolean
True if the given geometries represent the same geometry. Directionality is ignored.
Returns TRUE if the given Geometries are “spatially equal”. Use this for a ‘better’ answer than ‘=’. Note by spatially equal we mean ST_Within(A,B) = true and ST_Within(B,A) = true and also mean ordering of points can be different but represent the same geometry structure. To verify the order of points is consistent, use ST_OrderingEquals (it must be noted ST_OrderingEquals is a little more stringent than simply verifying order of points are the same).
This function will return false if either geometry is invalid even if they are binary equal.
Returns Boolean ST_Equals(geometry A, geometry B);
35 36 37 |
# File 'lib/postgis_functions/common.rb', line 35 def spatially_equal?(other) postgis_calculate(:equals, [self, other]) end |
#srid ⇒ Object
Returns the instance`s geom srid
478 479 480 |
# File 'lib/postgis_functions/common.rb', line 478 def srid self[postgis_geoms.keys.first].srid end |
#st_collect(other = nil) ⇒ Object
344 345 346 |
# File 'lib/postgis_functions/common.rb', line 344 def st_collect(other=nil) postgis_calculate(:collect, [self, other]) end |
#strictly_above?(other) ⇒ Boolean
bbox literal method.
83 84 85 |
# File 'lib/postgis_functions/bbox.rb', line 83 def strictly_above? other bbox("|>>", other) end |
#strictly_below?(other) ⇒ Boolean
bbox literal method.
90 91 92 |
# File 'lib/postgis_functions/bbox.rb', line 90 def strictly_below? other bbox("<<|", other) end |
#strictly_left_of?(other) ⇒ Boolean
bbox literal method.
97 98 99 |
# File 'lib/postgis_functions/bbox.rb', line 97 def strictly_left_of? other bbox("<<", other) end |
#strictly_right_of?(other) ⇒ Boolean
bbox literal method.
104 105 106 |
# File 'lib/postgis_functions/bbox.rb', line 104 def strictly_right_of? other bbox(">>", other) end |
#to_utm ⇒ Object
515 516 517 |
# File 'lib/postgis_functions/common.rb', line 515 def to_utm dup.to_utm! end |
#to_utm!(utm = nil) ⇒ Object
Returns the Geometry in its UTM Zone
Return Geometry
510 511 512 513 |
# File 'lib/postgis_functions/common.rb', line 510 def to_utm!(utm=nil) utm ||= utm_zone self[postgis_geoms.keys.first] = transform(utm) end |
#touches?(other) ⇒ Boolean
True if the geometries have at least one point in common, but their interiors do not intersect.
If the only points in common between g1 and g2 lie in the union of the boundaries of g1 and g2. The ‘touches?’ relation applies to all Area/Area, Line/Line, Line/Area, Point/Area and Point/Line pairs of relationships, but not to the Point/Point pair.
Returns Boolean ST_Touches(geometry g1, geometry g2);
340 341 342 |
# File 'lib/postgis_functions/common.rb', line 340 def touches? other postgis_calculate(:touches, [self, other]) end |
#transform(new_srid) ⇒ Object
459 460 461 |
# File 'lib/postgis_functions/common.rb', line 459 def transform(new_srid) dup.transform!(new_srid) end |
#transform!(new_srid) ⇒ Object
Transform the geometry into a different spatial reference system. The destination SRID must exist in the SPATIAL_REF_SYS table.
This method implements the OpenGIS Simple Features Implementation Specification for SQL. This method supports Circular Strings and Curves (PostGIS 1.3.4+)
Requires PostGIS be compiled with Proj support.
Return Geometry ST_Transform(geometry g1, integer srid);
455 456 457 |
# File 'lib/postgis_functions/common.rb', line 455 def transform!(new_srid) self[postgis_geoms.keys[0]] = postgis_calculate("Transform", self.new_record? ? self.geom : self, new_srid) end |
#utm_zone ⇒ Object
Return UTM Zone for a geom
Return Integer
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/postgis_functions/common.rb', line 486 def utm_zone if srid == 4326 geom = centroid else geomdup = transform(4326) mezzo = geomdup.length / 2 geom = case geomdup when Point then geomdup when LineString then geomdup[mezzo] else geomgeog[mezzo][geomgeo[mezzo]/2] end end pref = geom.y > 0 ? 32700 : 32600 zone = ((geom.x + 180) / 6 + 1).to_i zone + pref end |
#valid_geom? ⇒ Boolean
Test if a geometry is well formed.
14 15 16 |
# File 'lib/postgis_functions/common.rb', line 14 def valid_geom? postgis_calculate(:isvalid, self) end |
#within?(other) ⇒ Boolean
True if geometry A is completely inside geometry B.
For this function to make sense, the source geometries must both be of the same coordinate projection, having the same SRID. It is a given that if ST_Within(A,B) is true and ST_Within(B,A) is true, then the two geometries are considered spatially equal.
This function call will automatically include a bounding box comparison that will make use of any indexes that are available on the geometries. To avoid index use, use the function _ST_Within.
Do not call with a GEOMETRYCOLLECTION as an argument Do not use this function with invalid geometries. You will get unexpected results.
Performed by the GEOS module.
Returns Boolean ST_Within(geometry A, geometry B);
131 132 133 |
# File 'lib/postgis_functions/common.rb', line 131 def within? other postgis_calculate(:within, [self, other]) end |