Opened 12 years ago

Closed 12 years ago

#2077 closed defect (fixed)

[raster] ST_Hillshade output can be wrong

Reported by: dustymugs Owned by: dustymugs
Priority: medium Milestone: PostGIS 2.0.2
Component: raster Version: 2.0.x
Keywords: history Cc:

Description

The following doesn't return the correct answers.

WITH foo AS (
	SELECT
		ST_SetValue(
			ST_SetValue(
				ST_SetValue(
		ST_SetValue(
			ST_SetValue(
				ST_SetValue(
		ST_SetValue(
			ST_SetValue(
				ST_SetValue(
					ST_AddBand(ST_MakeEmptyRaster(5, 5, 0, 0, 1, -1, 0, 0, 0), 1, '32BF', 1, -9999),
					1, 2, 2, 2
				),
				1, 3, 2, 2
			),
			1, 4, 2, 2
		),
					1, 2, 3, 2
				),
				1, 3, 3, 3
			),
			1, 4, 3, 2
		),
					1, 2, 4, 2
				),
				1, 3, 4, 2
			),
			1, 4, 4, 2
		) AS rast
), bar AS (
	SELECT
		ST_Slope(rast, 1, '32BF') AS slope,
		ST_Aspect(rast, 1, '32BF') AS aspect,
		ST_Hillshade(rast, 1, '32BF', 1.75 * pi(), pi() / 4) AS hillshade
	FROM foo
)
SELECT
	x, y, val
FROM (
	SELECT
		(ST_PixelAsPolygons(hillshade)).*
	FROM bar
) baz

results in

 x | y |       val        
---+---+------------------
 1 | 1 |                 
 1 | 2 |                 
 1 | 3 |                 
 1 | 4 |                 
 1 | 5 |                 
 2 | 1 |                 
 2 | 2 |  251.32763671875
 2 | 3 | 220.749786376953
 2 | 4 | 147.224319458008
 2 | 5 |                 
 3 | 1 |                 
 3 | 2 | 220.749786376953
 3 | 3 | 180.312225341797
 3 | 4 | 67.7497863769531
 3 | 5 |                 
 4 | 1 |                 
 4 | 2 | 147.224319458008
 4 | 3 | 220.749786376953
 4 | 4 | 43.1210060119629
 4 | 5 |                 
 5 | 1 |                 
 5 | 2 |                 
 5 | 3 |                 
 5 | 4 |                 
 5 | 5 |                 
(25 rows)

The value for 4x3 is incorrect.

The equivalent in ArcGIS Spatial Analyst's Hillshade tool with azimuth = 315 degrees and altitude = 45 degrees on the attached raster (same as what is built in sql) looks like

NUL NUL NUL NUL NUL
NUL 251 220 147 NUL
NUL 220 180  67 NUL
NUL 147  67  43 NUL
NUL NUL NUL NUL NUL

The cell 4x3 should be 67, NOT 220.

Attachments (5)

test.tif (10.4 KB ) - added by dustymugs 12 years ago.
source raster
test.arc.hillshade.tif (1.0 KB ) - added by dustymugs 12 years ago.
ArcGIS's hillshade
test.tfw (18 bytes ) - added by dustymugs 12 years ago.
World file appropriate for both tif files
test.arc.slope.tif (64.8 KB ) - added by dustymugs 12 years ago.
ArcGIS's slope
test.arc.aspect.tif (64.8 KB ) - added by dustymugs 12 years ago.
ArcGIS's aspect

Download all attachments as: .zip

Change History (10)

by dustymugs, 12 years ago

Attachment: test.tif added

source raster

by dustymugs, 12 years ago

Attachment: test.arc.hillshade.tif added

ArcGIS's hillshade

by dustymugs, 12 years ago

Attachment: test.tfw added

World file appropriate for both tif files

comment:1 by dustymugs, 12 years ago

Status: newassigned

ST_Hillshade in -trunk is also incorrect.

by dustymugs, 12 years ago

Attachment: test.arc.slope.tif added

ArcGIS's slope

by dustymugs, 12 years ago

Attachment: test.arc.aspect.tif added

ArcGIS's aspect

comment:2 by dustymugs, 12 years ago

For -trunk, better to use the following query

WITH foo AS (
	SELECT ST_SetValues(
		ST_AddBand(ST_MakeEmptyRaster(5, 5, 0, 0, 1, -1, 0, 0, 0), 1, '32BF', 0, -9999),
		1, 1, 1, ARRAY[
			[1, 1, 1, 1, 1],
			[1, 2, 2, 2, 1],
			[1, 2, 3, 2, 1],
			[1, 2, 2, 2, 1],
			[1, 1, 1, 1, 1]
		]::double precision[][]
	) AS rast
), bar AS (
	SELECT
		ST_Slope(rast, 1, '32BF') AS slope,
		ST_Aspect(rast, 1, '32BF') AS aspect,
		ST_Hillshade(rast, 1, '32BF', 315, 45) AS hillshade
	FROM foo
)
SELECT
	ST_DumpValues(slope)
FROM bar

comment:3 by dustymugs, 12 years ago

Fixed in -trunk as of r10619

comment:4 by dustymugs, 12 years ago

Keywords: history added

Fixed in 2.0 as of r10620

comment:5 by dustymugs, 12 years ago

Resolution: fixed
Status: assignedclosed

Oops. Forgot to resolve ticket.

Note: See TracTickets for help on using tickets.