How to get buffered rectangle?

24 views
Skip to first unread message

Jason Williams

unread,
Aug 4, 2022, 12:10:53 PM8/4/22
to SpatiaLite Users
The function input is <lon>, <lat> and <buffer_in_miles>, output should be xmin, xmax, ymin, ymax.

I can think of a way to get the AsText for the box, but I need xmin, xmax, ymin, ymax. how to get the xmin, xmax, ymin, ymax?

SELECT ST_AsText(ST_Envelope(
                    ST_Transform(
                         ST_Buffer(
                              ST_Transform(SetSRID(ST_Point({lon}, {lat}), 4326), 3857), 
                                   {buffer_in_miles}), 
                          4326))





Jason Williams

unread,
Aug 4, 2022, 12:17:41 PM8/4/22
to SpatiaLite Users
Correction: it should be buffer_in_meters.

The function input is <lon>, <lat> and <buffer_in_meters>, output should be xmin, xmax, ymin, ymax.

I can think of a way to get the AsText for the box, but I need xmin, xmax, ymin, ymax. how to get the xmin, xmax, ymin, ymax?

SELECT ST_AsText(ST_Envelope(
                    ST_Transform(
                         ST_Buffer(
                              ST_Transform(SetSRID(ST_Point({lon}, {lat}), 4326), 3857), 
                                   {buffer_in_meters}), 
                          4326))

mj10777

unread,
Aug 4, 2022, 3:07:51 PM8/4/22
to SpatiaLite Users
On Thursday, 4 August 2022 at 18:17:41 UTC+2 Jason Williams wrote:
Correction: it should be buffer_in_meters.

The function input is <lon>, <lat> and <buffer_in_meters>, output should be xmin, xmax, ymin, ymax.

I can think of a way to get the AsText for the box, but I need xmin, xmax, ymin, ymax. how to get the xmin, xmax, ymin, ymax?

SELECT ST_AsText(ST_Envelope(
                    ST_Transform(
                         ST_Buffer(
                              ST_Transform(SetSRID(ST_Point({lon}, {lat}), 4326), 3857), 
                                   {buffer_in_meters}), 
                          4326))
Your must use a subquery as your source polygon and then extract the needed members of the polygon:

SELECT
 ST_MinX(source_envelope) AS xmin,
 ST_Miny(source_envelope) AS ymin,
 ST_MaxX(source_envelope) AS xman,
 ST_Maxy(source_envelope) AS yman
FROM
(
 SELECT
  ST_Envelope
  (
   ST_Transform
   (
    ST_Buffer
    (
     ST_Transform
     (
      SetSRID
      (
       ST_Point({lon}, {lat}), 
       4326
      ),
      3857
     ),                                    
     {buffer_in_meters}
    ), 
    4326
   )
  )
) source_envelope

Jason Williams

unread,
Aug 5, 2022, 12:02:02 AM8/5/22
to SpatiaLite Users
Fantastic! Thank you!!!
Reply all
Reply to author
Forward
0 new messages