#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)
Change History (18)
by , 3 years ago
comment:1 by , 3 years ago
Milestone: | PostGIS 3.2.1 → PostGIS 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 , 3 years ago
Attachment: | rasterize_line_#5084.patch added |
---|
Patch solving the bug for master branch
comment:2 by , 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 , 2 years ago
Type: | defect → patch |
---|---|
Version: | 3.2.x → 3.0.x |
comment:4 by , 2 years ago
Milestone: | PostGIS 3.0.6 → PostGIS 3.0.7 |
---|
comment:5 by , 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:7 by , 2 years ago
Milestone: | PostGIS 3.3.0 → PostGIS 3.0.8 |
---|
comment:15 by , 2 years ago
Milestone: | PostGIS 3.0.8 → PostGIS 2.5.9 |
---|
Bad line rasterization