Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am reading the documentation on the >> operator in PostGIS, and I cannot understand the meaning of strictly to the right because on the plane, right or left depends on the direction at which one is looking.

Reference: http://postgis.refractions.net/documentation/manual-1.4/ST_Geometry_Right.html

What would be that direction?

share|improve this question
3  
Left and right refer to the left and right of the line looking from the first vertex toward the last vertex. –  Michael Miles-Stimson Jun 23 at 0:44
    
@MichaelMiles-Stimson Can you clarify that a bit? I know what you're talking about in terms of lines, but how does that apply to a polygon or the bounding box (per the referenced help file) of a geometry? The start and end points are the same and everything would be either left or right of the bounding line's direction depending on clockwise or counter-clockwise creation. Is that the case? Mike's answer seems to make more sense (perhaps better stated as a comparison of x ranges), but it's got two downvotes and I'm not entirely sure why. –  Chris W Jun 23 at 3:13
    
Hi @ChrisW, this concept is fairly old in GIS terms, the operation works on vector cross products which have the curious mathematical property of (regardless of magnitude) one side is positive and the other negative. Polygon rings have an orientation: vertex 0 to 1, 1 to 2, 2 to 3.. until the end. In the polygon sense rightof would be inside or outside depending on clockwise or counter clockwise; Esri stores exterior polygons clockwise and interior counter clockwise, for what that's worth. –  Michael Miles-Stimson Jun 23 at 3:24
    
As a followup look at postgis.net/docs/ST_ForceRHR.html. This would give real meaning to RightOf. This makes the geometry clockwise for exterior. In respect to conventions and storage, there is no particular ring orientation for PostGIS, it stores the exterior first and then the interior polygons. –  Michael Miles-Stimson Jun 23 at 3:31
    
@MichaelMiles-Stimson So it does extend then - that's what I was thinking in terms of left and right becoming inside and outside. Does that (Esri) apply regardless of dig direction (ie it automatically reorders the points)? Do all databases have a standard that applies to? Because if not it would seem to make left and right kind of pointless unless operating on lines. And I think you've got enough for a full-on answer now. ;) –  Chris W Jun 23 at 3:36

2 Answers 2

up vote 4 down vote accepted

The language of left, right, above and below used for the bounding box operators refer to relative directions on a Cartesian grid. So "right" is a relatively positive direction along the x-axis, which is usually "to the east of" or "eastwards" for most projection systems (and ignoring that the world is round, where one could argue that everything is east of anything else).

So, in SQL-speak: Question: "is some geometry (A) to the right of another (B)"...

SELECT A << B as A_leftof_B, A >> B AS A_rigthtof_B
FROM (
SELECT
  'POINT (-40 30)'::geometry AS A,
  'POINT (90 10)'::geometry AS B
) AS d;
 a_leftof_b | a_rigthtof_b
------------+--------------
 t          | f
(1 row)

Answer: A is not right of B (but it is left of B).

As for the use of strictly, it depends if there is any overlap of the two bounding boxes along that dimension (the x-dimension for the case of left and right). For example, Italy is strictly east of Spain (since they don't even overlap east-west), but Spain is not strictly east of Portugal, since they overlap east to west. However, Spain is over to the east of Portugal, as demonstrated using the &> operator, since the bounding box for Spain is further to the east than Portugal's.


Addendum

The << or >> (or many other bounding box operators) do not consider the sequence of coordinates.

To determine what is left or right of the trajectory of a linestring you will need a custom-built function. One such promising function is from Andreas Neumann, called left_of_test.

share|improve this answer
    
Sorry @miket, you're right.. see changes. Please accept my apology. –  Michael Miles-Stimson Jun 23 at 6:11

I must rescind this statement in favor of the answer by Mike T

The correct answer is greater X as stated by Mike T; after much digging around the function is renamed several times and is in reality:

static bool box2df_right(const BOX2DF *a, const BOX2DF *b)
{
    if ( ! a || ! b ) return FALSE; /* TODO: might be smarter for EMPTY */

    /* a.xmin > b.xmax */
    return a->xmin > b->xmax;
}

The function I was thinking of was not this one, and may well have been a function in another API. I must sincerely apologize for my mistake. For those that don't speak "C" it is saying if the minimum X of the first is greater than the maximum X of the second then it's to the right.

I have left this as it was written just in case someone else becomes confused on the same point.

Left side and right side are considered by the order of the vertices; imagine yourself standing on the first vertex looking at the second, then walk to the second and look at the third and so on until you get to the end of the line. As you are standing on a vertex facing the next in sequence there is a definite left and right side regardless of which direction the segment is traversing in.

Sidedness is determined in a manner similar to the cross product of two vectors which has the mathematical properties of being negative if the point falls on the right of the line and positive if the point falls on the left of the line, for a programmatic explanation see here, which is repeated for each vertex in turn.

In order to give any real usefulness to this operator on polygons you should be using ST_ForceRHR to ensure that polygons are oriented in a clockwise order for the first exterior ring. Then in this case on-the-right would mean inside. PostGIS does not enforce any particular ring orientation but instead the first ring is the exterior and then interior rings follow.

share|improve this answer
    
This is good information nonetheless. I just wish the downvotes on the other answer would go away :) –  blah238 Jun 23 at 8:17
1  
@blah238 Agreed - what left and right mean in GIS (the original question title) is not the same as what left and right means to a particular function. This is part of what I found confusing when I first saw the question, as I would expect the doc page to make a distinction or explain how it works given the contextual nature of relative directions. Being unfamiliar with it, both answers seemed correct but the other one more logical in terms of usefulness for a function. –  Chris W Jun 23 at 18:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.