<div dir="ltr"><div>Wrapping would look like this for srid=3857, and more complex for other srids (assuming my math is correct). I think having it as part of the ST_TileEnvelope will simplify this very common use case, avoid errors, and will run faster.</div><div><br></div>ST_Expand(<div>  ST_TileEnvelope(:zoom, :x, :y),<div>  <span style="color:rgb(0,0,0);white-space:pre-wrap">20037508.34 * 2 / (2 ^ :zoom) / :extent * :buffer</span></div><div>)</div><div><br></div><div>Both :extent and :buffer are defined in ST_AsMVTGeom().</div><div><br></div><div>Note that the same argument could have been used for ST_TileEnvelope() itself -- it can be easily implemented with a short function. but it was implemented as a native PostGIS function because of how frequently it is used.</div><div><a href="https://github.com/mapbox/postgis-vt-util/blob/master/src/TileBBox.sql#L17">https://github.com/mapbox/postgis-vt-util/blob/master/src/TileBBox.sql#L17</a><br></div><div><br></div><div><br></div><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 13, 2019 at 4:31 AM Felix Kunde <<a href="mailto:felix-kunde@gmx.de">felix-kunde@gmx.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:Verdana;font-size:12px"><div>What speaks against ST_Expand(ST_TileEnvelope ... ?
<div> 
<div name="quote" style="margin:10px 5px 5px 10px;padding:10px 0px 10px 10px;border-left:2px solid rgb(195,217,229)">
<div style="margin:0px 0px 10px"><b>Gesendet:</b> Mittwoch, 13. November 2019 um 07:06 Uhr<br>
<b>Von:</b> "Yuri Astrakhan" <<a href="mailto:yuriastrakhan@gmail.com" target="_blank">yuriastrakhan@gmail.com</a>><br>
<b>An:</b> "PostGIS Development Discussion" <<a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a>><br>
<b>Betreff:</b> [postgis-devel] Proposal: Adding buffer parameter to ST_TileEnvelope()</div>

<div name="quoted-content">
<div>Would it make sense to add a `buffer` parameter to ST_TileEnvelope(), similar to ST_AsMVTGeom() ? 
<div> </div>

<div>To my understanding, ST_TileEnvelope common use case is to create a bbox filter -- to get just the relevant data before packaging it with ST_AsMVT().  This works well for the line and polygon geometries, but when dealing with point data, e.g. city names, one has to increase that bbox by a significant margin (e.g. half of the tile size) in order to capture labels from the neighboring tiles and prevent label clipping.</div>

<div> </div>

<div>I think this use case is common enough to add buffer parameter to ST_TileEnvelope - where it would increase the bbox size by the the given distance in tile coordinate space.
<div> </div>

<div>Proposed additional signature:</div>

<div> </div>

<div>geometry ST_TileEnvelope(integer tileZoom, integer tileX, integer tileY, integer buffer=0, geometry bounds=...);</div>

<div><br>
(Would existing method signature without the buffer param conflict if the buffer is added before the existing bounds param? They are of different type.)</div>
</div>
</div>
_______________________________________________ postgis-devel mailing list <a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a> <a href="https://lists.osgeo.org/mailman/listinfo/postgis-devel" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-devel</a></div>
</div>
</div>
</div></div></div>
_______________________________________________<br>
postgis-devel mailing list<br>
<a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-devel" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-devel</a></blockquote></div></div></div></div>