[postgis-users] Spatial query questions

strk at refractions.net strk at refractions.net
Wed May 4 01:03:25 PDT 2005


On Wed, May 04, 2005 at 03:08:54PM +1000, Rhys Ickeringill wrote:
> Hi All,
> 
> I wish to clarify a few points from the PostGIS manual. If there is another
> document which will answer all these questions, feel free to point me at it
> (OGC?)...
> 
> 1. Regarding the *FromWKB geometry constructors - how do I use them given
> [what I presume is] a string representation of the bytea field?
> 
> For example I wish to do something like:
> 
> SELECT PointFromWKB('0101000020FF7F00009BC4C5F6FFA841C06555638D43A46240')
> 
> which doesn't work. Is it expecting octets like the postgreSQL manual
> suggests? I know
> 
> SELECT '0101000020FF7F00009BC4C5F6FFA841C06555638D43A46240'::geometry
> 
> works. Do the two methods when correctly used produce exactly the same
> geometry?

As postgreSQL manual suggest *FromWKB() expects octets (the canonical
text input form for bytea type). If you use binary cursors it will
expect real bytea. If you cast latter query to bytea you should get what's
expected by the former:

SELECT '0101000020FF7F00009BC4C5F6FFA841C06555638D43A46240'::geometry::bytea;

> 2. The contains binary operator "@"
> 
> The manual states this performs a comparison based on bounding boxes. Is
> this true? Do *I* have to supply the bounding boxes, or are the boxes
> caculated for me if I supply other geometry types? Looking at the list of
> "@" operators, it seems some but not all cases are covered, for example
> "line @ polygon" is missing

Bounding boxes comparison: true.
BBOX are computed for you, either read from cache or computed with full
geometry scan. 
All geometry types are supported.

> 3. The "within" and "contains" functions (this actually applies to many
> binary functions)
> 
> The manual is a ambiguous regarding the order of the comparison - is PostGIS
> computing whether arg1 is contained by arg2? Or arg2 contains arg1?
> 
> Also what is the definition of "contains" - I'm assuming it is compete
> rather than partial containment. Correct?

within(A, B) - A is within B - B contains A
contains(A, B) - A contains B - B is within A

OGC Simple Feature Specification for SQL is the reference document.
The URL should be in postgis manual.

> Thanks for your guidance.

Thanks for pointing out, I've updated the documentation.

> Rhys

--strk;




More information about the postgis-users mailing list