Opened 11 years ago

Closed 11 years ago

#2555 closed defect (fixed)

[raster]: ST_Reclass Working with negative numbers seems broken

Reported by: robe Owned by: Bborie Park
Priority: medium Milestone: PostGIS 2.0.5
Component: raster Version: 2.0.x
Keywords: history Cc:

Description

I'm not sure if this is just my misunderstanding of how reclass works or if I'm missing something. I have a temp raster in celsius*10 units and wanted to get down to celsius by doing this:

UPDATE t SET rast = ST_Reclass(rast,1,'-9000-9000:-900-900'::text, '32BF'::text);

Results all come out NULL, but

UPDATE t SET rast = ST_Reclass(rast,1,'0-9000:0-900'::text, '32BF'::text);

seems to work as expected

Am I missing something. If so not clear from the docs how someone can reclassify negative numbers. There are some examples in the regress tests though none of those seem to amp a negative to a negative number and one even uses the letter a?

'a-100]:50-1,(-100-1000]:150-50,(1000-10000]:254-150'

what the heck does that mean?

at any rate if this is not a bug, it should be documented as its not intuitively obvious.

Change History (6)

comment:1 by Bborie Park, 11 years ago

Version: 2.1.x2.0.x

The use of letter "a" in the regression test is intentional. The test expects a message response...

NOTICE:  Invalid argument for reclassargset. Invalid band index (must use 1-based) for reclassarg of index 0 . Returning original raster

comment:2 by Bborie Park, 11 years ago

Do you happen to have the source raster so that I can test it?

The following seems to work for me.

WITH foo AS (
	SELECT
		ST_SetValues(
			ST_AddBand(
				ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),
				1, '32BF'::text
			),
			1,
			1, 1,
			ARRAY[
				[-9000, -6000, -3000],
				[-3000, 0, 3000],
				[-3000, -6000, -9000]
			]::double precision[]
		)	AS rast
), bar AS (
	SELECT
		ST_Reclass(rast, 1, '[-9000-3000]:[-900-300]', '32BF') AS rast
	FROM foo
)
SELECT ST_DumpValues(rast) FROM foo
UNION ALL 
SELECT ST_DumpValues(rast) FROM bar

                         st_dumpvalues                          
----------------------------------------------------------------
 (1,"{{-9000,-6000,-3000},{-3000,0,3000},{-3000,-6000,-9000}}")
 (1,"{{-900,-600,-300},{-300,0,300},{-300,-600,-900}}")

comment:3 by robe, 11 years ago

http://biogeo.ucdavis.edu/data/climate/worldclim/1_4/tiles/cur/tmean_26.zip

Which I loaded with:

raster2pgsql -s 4326 -I -C -M tmean/*.bil -F -t 256x256 tmean | psql

They came in as 16BSI. I just tried your query on this:

SELECT ST_Value(ST_Reclass(rast, 1, '[-9000-9000]:[-900-900]', '32BF'),1,1) As new, ST_Value(rast,1,1) As orig
from tmean limit 10;

and output is:

 new | orig
-----+------
   0 |  234
   0 |  236
   0 |  240
   0 |  241
   0 |  234
   0 |  211
   0 |  208
   0 |  225
   0 |  222
   0 |  230

This is running:

POSTGIS="2.2.0dev r11899" GEOS="3.4.2-CAPI-1.8.2 r3924" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.10.0, released 2013/04/24 GDAL_DATA not found" LIBXML="2.7.8" LIBJSON="UNKNOWN" TOPOLOGY (topology procs from "2.2.0dev r11808" need upgrade) RASTER

I've got to check what's up with my GDAL_DATA though I assume that doesn't matter for this case.

comment:4 by robe, 11 years ago

for record I was wrong about it not doing anything with negatives. The below actually does what I expect

SELECT ST_Value(ST_Reclass(rast, 1, '[-1000-9000]:[-100-900]', '32BF'),1,1) As new, ST_Value(rast,1,1) As orig
from ch12.tmean limit 10;


works as expected and gives:

        new        | orig
------------------+------
 23.3999996185303 |  234
 23.6000003814697 |  236
               24 |  240
 24.1000003814697 |  241
 23.3999996185303 |  234
 21.1000003814697 |  211
 20.7999992370605 |  208
             22.5 |  225
 22.2000007629395 |  222
               23 |  230

so it seems the -9000 is too far out. I have values in -9999 for no data value so not sure why that would be illegal

comment:5 by Bborie Park, 11 years ago

Status: newassigned

Hmmmm... looks like a reclassarg parsing issue.

comment:6 by Bborie Park, 11 years ago

Keywords: history added
Resolution: fixed
Status: assignedclosed

Fixed for trunk at r12152. Fixed for 2.1 in r12153. Fixed for 2.0 in r12154.

Note: See TracTickets for help on using tickets.