#5607 closed defect (invalid)

ST_SquareGrid fails in edge cases

Reported by: tobwen Owned by: pramsey
Priority: medium Milestone: PostGIS 3.4.2
Component: postgis Version: 3.4.x
Keywords: Cc:

Description

## summary

If a point lies exactly in the corner of a rectangle, four results must be returned.

The documentation should point out that only one geometry is returned. It must also be explained how this geometry is selected.

### example 1

WITH grid AS (
    SELECT (ST_SquareGrid(1000, ST_SetSRID(ST_Point(3183000, 4209000), 3035))).*
)
SELECT
    ST_AsText(geom)
FROM
    grid;

### example 2

SELECT ST_AsText((ST_SquareGrid(1000, ST_SetSRID(ST_Point(3183000, 4209000), 3035))).geom);

### result

POLYGON((3183000 4209000,3183000 4210000,3184000 4210000,3184000 4209000,3183000 4209000))

### expected result

POLYGON((3183000 4209000,3183000 4210000,3184000 4210000,3184000 4209000,3183000 4209000))
POLYGON((3183000 4208000,**3183000 4209000**,3184000 4209000,3184000 4208000,3183000 4208000))
POLYGON((3182000 4208000,3182000 4209000,**3183000 4209000**,3183000 4208000,3182000 4208000))
POLYGON((3182000 4209000,3182000 4210000,3183000 4210000,**3183000 4209000**,3182000 4209000))

## additional notes

This is a regression.

Change History (4)

comment:1 by robe, 12 months ago

This is a regression from 3.3?

comment:2 by robe, 12 months ago

Milestone: PostGIS 3.4.1PostGIS 3.4.2

comment:3 by pramsey, 12 months ago

When did it have different behaviour?

You're feeding it a zero-area bounds, and it's producing the one grid square that last a lower-left corner "in" that bounds. I can rework the documentation to describe the situation better, but I like it more than the "four squares returned" option, because it is effectively an open-on-one-side interval. You can see this in the 1x1 bounds case

SELECT ST_AsText((ST_SquareGrid(1000, ST_SetSRID(ST_MakeLine(ST_Point(3183000, 4209000),ST_Point(3183001, 4209001)), 3035))).geom);

and also when you push out to a 1000x1000 bounds, again it's hitting just the lower left.

SELECT ST_AsText((ST_SquareGrid(1000, ST_SetSRID(ST_MakeLine(ST_Point(3183000, 4209000),ST_Point(3184000, 4210000)), 3035))).geom);

comment:4 by pramsey, 11 months ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.