[postgis-devel] [postgis-users] Oddity in _ST_Expand(geography) ?

Paul Ramsey pramsey at cleverelephant.ca
Tue Jul 10 08:22:00 PDT 2018


ST_Buffer in geography is a shitty wrapper on top of reprojection
hacks. It *will* fail brutally for larger world-size polygons (country
level stuff). What we need is something that transforms the input into
another valid piece of WKT that happens to have a 3-space bounding box
that is the same as the expanded box we want. Tricksy.

On Tue, Jul 10, 2018 at 3:20 AM, Darafei "Komяpa" Praliaskouski
<me at komzpa.net> wrote:
>
>
> вт, 10 июл. 2018 г. в 12:48, Pavan Deolasee <pavan.deolasee at gmail.com>:
>>
>>
>> On Tue, Jul 10, 2018 at 12:22 PM, Darafei "Komяpa" Praliaskouski
>> <me at komzpa.net> wrote:
>>>
>>>
>>> What you can try is to short-circuit ST_Expand to ST_Buffer for now. It's
>>> more expensive computationally, but for most practical use cases the box it
>>> produces should be similar to that of ST_Expand, and serialized geometry
>>> should produce the same box on both sides of serialization.
>>>
>>
>>
>> Thanks for the tip. That seems to do the trick. Apart from the performance
>> impact, can this cause any regression?
>
>
> ST_Intersects(ST_Buffer()) is different from ST_Within() on the edge, by
> <1%.
> ST_Buffer on geography is actually ST_Buffer on plane, so for long
> geometries there are bigger error margins.
>
> Anything on the scale of city / buildings should be fine.
>
>>
>> FWIW PostGIS regression tests does not show any new failure, but anything
>> specific I should test?
>
>
> Test whether you can replace ST_DWithin(a, b, eps) with
> ST_Intersects(ST_Buffer(a, eps), b).
>
>>
>> With regard to performance impact, could it be material? And if so, in
>> what circumstances?
>
>
> You're replacing O(N) with somewhat like O(NlogN). ST_Expand output size is
> O(N), ST_Buffer's is up to O(4*N*quad_segs), where quad_segs is usually 8.
>
> A scenario with massive regression I see: you have a city polygon and want
> all buildings in it while your db holds just that city and a bit around.
> This way you calculate and throw away a buffer for every building in that
> city.
>
> A scenario with almost no regression: you have a GPS position of someone and
> want to get shops within N meters around them. You buffer their point once,
> select some small amount of shops around and buffer only them (as ST_DWithin
> buffers both sides).
>
>
>
>>
>>
>> Thanks,
>> Pavan
>>
>> --
>>  Pavan Deolasee                   http://www.2ndQuadrant.com/
>>  PostgreSQL Development, 24x7 Support, Training & Services
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/postgis-users
>
>
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-devel


More information about the postgis-devel mailing list