Opened 13 years ago

Closed 13 years ago

#894 closed defect (fixed)

_ST_Expand for geography is broken

Reported by: robe Owned by: pramsey
Priority: blocker Milestone: PostGIS 2.0.0
Component: postgis Version: 1.5.X
Keywords: Cc:

Description (last modified by robe)

I think this may be related to #869.

In trying to trace the cause of failure of ST_DWithin in 869, I discovered that

_ST_Expand for any geography type for any distance always returns the same geography. What was especially puzzling is that it is also broken in PostGIS 1.5.2 and yet the ST_DWithin in that works.

_ST_DWithin by itself works fine and produces the correct answers in that regress for both 2.0 and 1.5.2 — so the failing part is the _ST_Expand.

My conclusion is that while PostGIS 1.5.2 is also broken, the cached box it produces must be right, but that when Paul enable the gserialized, it somehow probably made the cached box agree with the output geometry thus making the _ST_Expand ineffective in 2.0.

I'm not sure how to see the cached box of a geography though? Do we have a function for that?

So here is the case:

On PostGIS 1.5.2 and PostGIS 2.0

SELECT ST_AsText(_ST_EXPAND(ST_GeogFromText('LINESTRING(1 2, 3 4)'), 1000 );

-- result--
LINESTRING(1 2,3 4)

However watch this: — This returns true in both —

SELECT _ST_EXPAND('LINESTRING(1 2, 3 4)'::geography, 1000) && 'POINT(3 3)'::geography);

—- This returns true in PostGIS 1.5 and false in PostGIS 2.0 —

SELECT 'POINT(-20 -10)'::geography && _ST_Expand(ST_GeogFromText('POINT(0 0)'),3000000);

— This works in both —

SELECT _ST_Expand('POINT(-20 -10)'::geography,3000000) && ST_GeogFromText('POINT(0 0)');

So perhaps its expanding 0 0 that is at fault, but both are still producing erroneous geography output from _ST_Expand which doesn't agree with what is happening.

Change History (3)

comment:1 by robe, 13 years ago

Description: modified (diff)

Oops I was incorrect in the second part of my assumptions. I guess it is the expansion of 0 0 that is problematic because if I switch the expand it works. But notice the geography expand output is still wrong in both.

comment:2 by pramsey, 13 years ago

Can you re-confirm? I get 'true' in PostGIS 2.0 for all your examples.

Regards the first point, that expanding doesn't change the geometry, you are right, that it is the box being expanded, not the geography. More to the point, it's not possible to represent the box as a geography. The box is a 3d geocentric box. The geography is a set of 2d spherical coordinates. So expand grows the cached box but doesn't alter the coordinates of the object. This is why it's _ST_Expand(), because there's no way a user is ever going to grok the subtlety.

comment:3 by robe, 13 years ago

Resolution: fixed
Status: newclosed

Yap seems fine now.

Note: See TracTickets for help on using tickets.