Opened 11 years ago

Closed 11 years ago

#2210 closed enhancement (fixed)

[raster]: ST_Envelope for raster that considers only data values

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

Description

This would be like our current ST_Envelop (we could add an optional arg). This would essentially return the envelop of a raster not considering no data values.

We can do this now with ST_Envelope(ST_Polygon ..) but that process is slow because it has to consider all pixels. This one wouldn't need to consider all pixels because it would start at the outer perimeter, collapse inward and stop checking once it hit a pixel with data, since the envelop can't get any smaller.

In dustymug's words:

We're looking for a boundary function rather than a polygon function (which includes holes for interior NODATA pixels). I'm looking for less than that — since I still expect it to be a rectangle, not a concave hull

Change History (12)

comment:1 by Bborie Park, 11 years ago

Milestone: PostGIS FuturePostGIS 2.1.0
Status: newassigned

comment:2 by Bborie Park, 11 years ago

This is more like ST_ConvexHull() rather than ST_Envelope() as the returning geometry would take into account the raster's rotation.

What should the function be called? ST_Boundary()

comment:3 by robe, 11 years ago

Can we just add a flag to ST_ConvexHull?

I don't want to call it ST_Boundary because in geometry (for polygon) that would return the linestrings that define the rings of the polygon/multipolygon. I fear people might thing it means that.

comment:4 by Bborie Park, 11 years ago

I don't know if that'll work. This function requires a parameter for band number since bands may have different "edges".

ST_XXX(raster rast, nband integer DEFAULT NULL)

If nband = NULL, all bands are considered.

comment:5 by robe, 11 years ago

How about signature:

ST_ConvexHull(raster rast, exclude_no_data = false, band_num=NULL);

If band_nun is NULL then (all bands are considered as is current behavior) meaning the first band to hit a road block wins.

e.g.

Let's say you have 3 bands and for the sake of silly argument, band 1 is nothing but no data, but band 2 has all pixels with data, and band 3 has some.

Then an ST_ConvexHull that excludes no data will return the same as ST_ConvexHull that includes no data — since band 2 hits its limit first. In theory if there is any band that does not have a no data value you can return the same as current ST_ConvexHull if no bands are explicitly specified.

If you specify band 3 then you get a possibly smaller rectangle than the original and if you specify band 1 you get an EMPTY POLYGON.

comment:6 by Bborie Park, 11 years ago

The signature looks good. I'll have to see what the hiccups are with upgrading though.

comment:7 by Bborie Park, 11 years ago

Modifying ST_ConvexHull() may be a no-go as that function signature is critical for the raster to geometry cast. From the looks of the docs (and the error that forced me to look at the docs)…

Cast implementation functions can have one to three arguments. The first argument type must be identical to or binary-coercible from the cast's source type. The second argument, if present, must be type integer; it receives the type modifier associated with the destination type, or -1 if there is none. The third argument, if present, must be type boolean; it receives true if the cast is an explicit cast, false otherwise. (Bizarrely, the SQL standard demands different behaviors for explicit and implicit casts in some cases. This argument is supplied for functions that must implement such casts. It is not recommended that you design your own data types so that this matters.)

http://www.postgresql.org/docs/9.0/interactive/sql-createcast.html

That definitely will not work for us. So, different signature?

comment:8 by Bborie Park, 11 years ago

After additional testing of the changed ST_ConvexHull(), I think that path is an absolute minefield. I think we're better off with a new signature.

comment:9 by Bborie Park, 11 years ago

How about ST_MinConvexHull(rast raster, nband integer DEFAULT NULL)?

comment:10 by robe, 11 years ago

That works for me.

comment:11 by pracine, 11 years ago

A nice way to propagate the concept of "with value" pixels (in opposition to "nodata value"): ST_WithValueExtent()

comment:12 by Bborie Park, 11 years ago

Keywords: history added
Resolution: fixed
Status: assignedclosed

Added in r11118

Note: See TracTickets for help on using tickets.