Opened 8 years ago

Closed 7 years ago

Last modified 7 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 Changed 8 years ago by Bborie Park

Status: newassigned

comment:2 Changed 7 years ago by Bborie Park

Resolution: fixed
Status: assignedclosed

Committed in r9786

comment:3 Changed 7 years ago by pracine

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 Changed 7 years ago by strk

Milestone: PostGIS FuturePostGIS 2.1.0

comment:5 Changed 7 years ago by Bborie Park

Keywords: history added

comment:6 Changed 7 years ago by Bborie Park

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.

comment:7 in reply to:  6 Changed 7 years ago by pracine

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 Changed 7 years ago by Bborie Park

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.