Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#3425 closed defect (fixed)

Raster Query Misclassification

Reported by: geographika Owned by: warmerdam
Priority: normal Milestone: 5.6 release
Component: GDAL Support Version: 5.6
Severity: normal Keywords: raster query class
Cc:

Description

queryByPoint returns correct raster values for a GeoTiff, but the class value is always the same.

Attached is a sample GeoTIFF, Python script, and MAP file used to recreate the problem. The same result occurs for 5.2 and 5.6.

The raster displays with the correct classifications when using MapServer.

If the expressions in mapfile are in quotes e.g. EXPRESSION "1" then the following line is required in the script or queryByPoint returns an error:

new_class = mapscript.classObj(layer)

If expressions are written as EXPRESSION (1) no error occurs. The classification is incorrect in either case. CLASSITEM was set to [pixel] and also commented out resulting in no changes in the script.

Attachments (1)

raster_query_test.zip (8.4 KB ) - added by geographika 14 years ago.
MAP file, Tiff, and Python Script

Download all attachments as: .zip

Change History (5)

by geographika, 14 years ago

Attachment: raster_query_test.zip added

MAP file, Tiff, and Python Script

comment:1 by warmerdam, 14 years ago

Cc: warmerdam@… removed
Component: MapScript-PythonGDAL Support
Owner: changed from hobu to warmerdam

This doesn't really have any specific relationship to mapscript python, so I'm recategorizing it and stealing the ticket from hobu.

comment:2 by warmerdam, 14 years ago

Resolution: fixed
Status: newclosed

The sample map file was using classes like:

		CLASS
			NAME '0-50m'
			EXPRESSION (0)
			STYLE
			  COLOR 69 117 181
			END
		END  
		CLASS
			NAME '50-100m'
			EXPRESSION (1)
			STYLE
			  COLOR 162 180 189
			END
		END 

However, I believe this is inappropriate. Using this approach I was unable to get map rendering working, and everything came out as class 1. I determined that is because expressions in round brackets are evaluated as numerical/logical expressions and a value of zero means not in the class, and a value of non-zero means the class applies. So EXPRESSION (1) always was the selected class whether rendering or doing raster query.

A review of the EXPRESSION discussion at http://mapserver.org/mapfile/class.html indicates brackets should not be used to do a simple string comparison. So the classes can be written like

this:

		CLASS
			NAME '0-50m'
			EXPRESSION "0"
			STYLE
			  COLOR 69 117 181
			END
		END  
		CLASS
			NAME '50-100m'
			EXPRESSION "1"
			STYLE
			  COLOR 162 180 189
			END
		END 

I found this worked fine for map rendering, but did not work properly for raster query. It turned out this was because raster query was formatting the string using "%18g" (instead of %d as used in the drawing case) and this caused a failure to match. I have made corrections in trunk (r10092) and 5.6 branch (r10093) to strip leading white space. Once this was done raster query also worked well.

Alternatively the EXPRESSIONs could have been done like:

   EXPRESSION ([pixel] = 1)

So, I think, some user error, and also a problem with the software.

in reply to:  2 comment:3 by geographika, 14 years ago

That's great Frank - thanks. I'll try out one of the nightly builds on Monday. Just briefly on the EXPRESSION clauses, I was originally using EXPRESSION "1" etc. as these drew my layer correctly, but when running the script with that MAP file the following line always returned a failure (not incorrect results - I only got that far using EXPRESSION (1) etc.).

if layer.queryByPoint(mymap, pnt, mapscript.MS_SINGLE,0) == mapscript.MS_FAILURE:

I also tried EXPRESSION ([value_0] = 1) - but again this returned an error on the same line in the script.

comment:4 by warmerdam, 14 years ago

ah, that explains how the map drawing worked for you.

([value_0] = 1) does not work because the expression evaluator is currently only populated with [pixel], [red], [green] and [blue].

I imagine you were getting the failure because no points matched due to the issue I did fix, but I'm not sure about that.

Note: See TracTickets for help on using tickets.