Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#1751 closed enhancement (fixed)

[raster] ST_NearestValue

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

Description

When sticking a pin through a tile to get a value, it may be that the pixel at that pin is NODATA. One possible solution is to do a buffer around the pin and then aggregate the values in that buffer (assuming that buffer contains any actual values). This solution works but is slow due to the intermediate generation of raster resulting from the intersection of the buffer and the tile, whose values then get aggregated.

Instead, a simpler solution is to take the point and find the nearest pixel to it and return that pixel's value. Additionally, it is pointless to call ST_Value and then ST_NearestValue when ST_Value returns NULL (NODATA), so ST_NearestValue will return ST_Value's value if the point is on a pixel with value.

ST_NearestValue() must match the signatures of ST_Value as it is a drop-in replacement for it.

ST_NearestValue(rast raster, band integer, pt geometry, exclude_nodata_value boolean DEFAULT TRUE)

ST_NearestValue(rast raster, pt geometry, exclude_nodata_value boolean DEFAULT TRUE)

ST_NearestValue(rast raster, band integer, x integer, y integer, exclude_nodata_value boolean DEFAULT TRUE)

ST_NearestValue(rast raster, x integer, y integer, exclude_nodata_value boolean DEFAULT TRUE)

Change History (8)

comment:1 by Bborie Park, 12 years ago

Status: newassigned

comment:2 by Bborie Park, 12 years ago

Resolution: fixed
Status: assignedclosed

Committed in r9786

comment:3 by pracine, 12 years ago

Am I wrong to say that when I set exclude_nodata_value to FALSE there is no difference between ST_Nearest() and ST_Value()?

What happen at the edge of a tile?

comment:4 by strk, 12 years ago

Milestone: PostGIS FuturePostGIS 2.1.0

comment:5 by Bborie Park, 12 years ago

Keywords: history added

comment:6 by Bborie Park, 12 years ago

Correct, if exclude_nodata_value = FALSE there is no difference between ST_NearestValue and ST_Value. There would be no performance difference in that situation.

Assuming you're talking about the possibility that there is no value in the tile when reaching the edge of the tile, there are checks in place to prevent infinite loops.

in reply to:  6 comment:7 by pracine, 12 years ago

Replying to dustymugs:

Correct, if exclude_nodata_value = FALSE there is no difference between ST_NearestValue and ST_Value. There would be no performance difference in that situation.

Then I don't see the need for all the variants taking the exclude_nodata_value parameter. If you want this to be false use ST_Value…

comment:8 by Bborie Park, 12 years ago

You're forgetting that ST_NearestValue is supposed to be a drop-in replacement for ST_Value thus allowing users to not think about which one to use. Hence the signatures must match.

Note: See TracTickets for help on using tickets.