Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#5084 closed patch (fixed)

Bad rasterization of linestring

Reported by: gvuidel Owned by: robe
Priority: high Milestone: PostGIS 2.5.9
Component: raster Version: 3.0.x
Keywords: Cc:

Description

In some cases rasterization of linestring is incomplete. Example :

SELECT ST_AsRaster('LINESTRING(986015.7 6720291.2,986024.3 6720347,986028 6720417.4,986025.6 6720474.3)'::geometry, 2::double precision, 2, 0, 0)

In the resulting raster the line is discontinuous at the right border of the raster. If I shift the grid the result is correct :

SELECT ST_AsRaster('LINESTRING(986015.7 6720291.2,986024.3 6720347,986028 6720417.4,986025.6 6720474.3)'::geometry, 2::double precision, 2, 0.1, 0.1)

I think the problem is related to the bounding box of the generated raster which is too small. In this case it should be enlarge at right to one pixel.

I have tested on PostGIS 3.2, 3.1.1 and 2.5.1 and I obtain the same erroneous result.

Attachments (3)

bad.png (4.6 KB ) - added by gvuidel 3 years ago.
Bad line rasterization
good.png (5.0 KB ) - added by gvuidel 3 years ago.
Good rasterization when shifting the grid
rasterize_line_#5084.patch (4.4 KB ) - added by gvuidel 3 years ago.
Patch solving the bug for master branch

Download all attachments as: .zip

Change History (18)

by gvuidel, 3 years ago

Attachment: bad.png added

Bad line rasterization

by gvuidel, 3 years ago

Attachment: good.png added

Good rasterization when shifting the grid

comment:1 by robe, 3 years ago

Milestone: PostGIS 3.2.1PostGIS 3.0.6

Just for clarity since ST_AsRaster has so many overloads I'm rewriting your query using named arguments.

-- bad
SELECT ST_AsRaster('LINESTRING(986015.7 6720291.2,986024.3 6720347,986028 6720417.4,986025.6 6720474.3)'::geometry,  scalex =>2,  scaley =>2,   gridx =>0,  gridy => 0)::geometry


-- good
SELECT ST_AsRaster('LINESTRING(986015.7 6720291.2,986024.3 6720347,986028 6720417.4,986025.6 6720474.3)'::geometry,  scalex =>2,  scaley =>2,   gridx =>0.1,  gridy => 0.1)

by gvuidel, 3 years ago

Attachment: rasterize_line_#5084.patch added

Patch solving the bug for master branch

comment:2 by gvuidel, 3 years ago

I have found where the problem comes from: in the function rt_raster_gdal_rasterize in rt_raster.c

The extent is supposed to be increased by one pixel (or a half) for linestring and point geometries. But in several cases the extent is not increased causing a wrong rasterization. I propose to simplify the code and always increase the extent when the geometry is a linestring or a point as written in the code comments.

I attach a patch file made from the master branch.

I have tested on dev branch and 3.2.1 version. If needed I can test on other branch/version.

comment:3 by robe, 2 years ago

Type: defectpatch
Version: 3.2.x3.0.x

comment:4 by robe, 2 years ago

Milestone: PostGIS 3.0.6PostGIS 3.0.7

comment:5 by robe, 2 years ago

We haven't had a chance to review this yet so pushing to next milestone. Will review after this batch of releases.

comment:6 by robe, 2 years ago

Milestone: PostGIS 3.0.7PostGIS 3.3.0

We are still reviewing this.

comment:7 by robe, 2 years ago

Milestone: PostGIS 3.3.0PostGIS 3.0.8

comment:8 by strk, 2 years ago

How about a simple regress test for this case ?

comment:9 by Regina Obe <lr@…>, 2 years ago

In b4b6932/git:

Fix bad rasterization of linestring (Gilles Vuidel)
References #5084 for PostGIS 3.4.0

comment:10 by Regina Obe <lr@…>, 2 years ago

In e5a8c35/git:

Fix bad rasterization of linestring (Gilles Vuidel)
References #5084 for PostGIS 3.3.2

comment:11 by Regina Obe <lr@…>, 2 years ago

In 1864ec51/git:

Fix bad rasterization of linestring (Gilles Vuidel)
References #5084 for PostGIS 3.2.4

comment:12 by Regina Obe <lr@…>, 2 years ago

In 110fae4/git:

Fix bad rasterization of linestring (Gilles Vuidel)
References #5084 for PostGIS 3.1.8

comment:13 by Regina Obe <lr@…>, 2 years ago

Resolution: fixed
Status: newclosed

In cca1f48/git:

Fix bad rasterization of linestring (Gilles Vuidel)
Closes #5084 for PostGIS 3.0.8

comment:14 by Regina Obe <lr@…>, 2 years ago

In 7e1ee433/git:

Fix bad rasterization of linestring (Gilles Vuidel)
References #5084 for PostGIS 2.5.9

comment:15 by robe, 2 years ago

Milestone: PostGIS 3.0.8PostGIS 2.5.9
Note: See TracTickets for help on using tickets.