Opened 13 years ago

Closed 13 years ago

#1574 closed defect (fixed)

[raster] ST_AsRaster(geometry, rast) do not align raster properly

Reported by: pracine Owned by: Bborie Park
Priority: medium Milestone: PostGIS 2.0.0
Component: raster Version: master
Keywords: Cc:

Description (last modified by pracine)

I made the queries to be easily displayable in OpenJump...

I have a geometry:

SELECT ST_Asbinary(ST_Buffer(ST_SetSRID(ST_MakePoint(2, 1), 0), 1.3));

and a raster:

SELECT ST_Asbinary((gv).geom) geom, (gv).val
FROM (SELECT ST_PixelAsPolygons(ST_MakeEmptyRaster(4, 4, 0, 0, 1, 1, 0, 0, 0)) gv) foo

and I want to rasterize that geometry aligned on this raster:

SELECT ST_Asbinary((gv).geom) geom, (gv).val
FROM (SELECT ST_PixelAsPolygons(
               ST_AsRaster(
                           ST_Buffer(ST_SetSRID(ST_MakePoint(2, 1), 0), 1.3),
                           ST_MakeEmptyRaster(4, 4, 0, 0, 1, 1, 0, 0, 0)
                          )
             ) gv 
     ) foo

The produced raster is not aligned properly.

Change History (9)

comment:1 by pracine, 13 years ago

Description: modified (diff)

comment:2 by pracine, 13 years ago

If I just negate the scaley of the raster then I get a raster correctly aligned :

SELECT ST_Asbinary((gv).geom) geom, (gv).val
FROM (SELECT ST_PixelAsPolygons(
               ST_AsRaster(
                           ST_Buffer(ST_SetSRID(ST_MakePoint(2, 1), 0), 1.3),
                           ST_MakeEmptyRaster(4, 4, 0, 0, 1, -1, 0, 0, 0)
                          )
             ) gv 
     ) foo

comment:3 by pracine, 13 years ago

Might be related to #1395...

comment:4 by Bborie Park, 13 years ago

Owner: changed from pracine to Bborie Park
Status: newassigned

#1395 isn't related. I've rewritten your test case and see what the problem is. I'm going to have to investigate but am expecting a floating point issue.

comment:5 by Bborie Park, 13 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r9187.

comment:6 by pracine, 13 years ago

Resolution: fixed
Status: closedreopened

Now for the same geometry, if the raster I want to align to is:

SELECT ST_Asbinary((gv).geom) geom, (gv).val
FROM (SELECT ST_PixelAsPolygons(ST_MakeEmptyRaster(4, 4, 0, 0, 1, -1, 0.2, 0.2, 0)) gv) foo

then:

SELECT ST_Asbinary((gv).geom) geom, (gv).val
FROM (SELECT ST_PixelAsPolygons(
               ST_AsRaster(
                           ST_Buffer(ST_SetSRID(ST_MakePoint(2, 1), 0), 1.3),
                           ST_MakeEmptyRaster(4, 4, 0, 0, 1, -1, 0.2, 0.2, 0)
                          )
             ) gv 
     ) foo

is also wrongly aligned... sorry...

comment:7 by Bborie Park, 13 years ago

Now that is probably a skew issue related to #1395. Since GDAL suggests a deskewed raster for the geometry, we need to reintroduce the skew (the same issue is true for GDAL Warp).

I'll see when I can get to this as this will take longer to resolve.

comment:8 by Bborie Park, 13 years ago

Please try r9271 as that introduced proper creation of skewed rasters.

comment:9 by Bborie Park, 13 years ago

Resolution: fixed
Status: reopenedclosed

The skewed example works. Refactored code

WITH foo AS (
	SELECT ST_MakeEmptyRaster(4, 4, 0, 0, 1, -1, 0.2, 0.2, 0) AS rast
)
SELECT
	ST_SameAlignment(
		ST_AsRaster(
			ST_Buffer(ST_SetSRID(ST_MakePoint(2, 1), 0), 1.3),
			rast
		),
		rast
	)
FROM foo
Note: See TracTickets for help on using tickets.