I have a test raster that covers the world ((-180 90), (180 -90)). The SRID is WGS 84 (EPSG:4326). Values for cells in the north-western quadrant ((-180 90), (0 0)) are random integers in the range 1 to 10 (inclusive). Values for other cells are -99; this is the explicit
The test raster is stored in a PostGIS database (v.2.1). I'd like to compute summary statistics for a buffered point where the buffer is specified in either decimal degrees or in meters.
The Problem: My query using decimal degrees and the geometry type works as expected. However, the same query, using meters and the geography type, which I then cast back to the geometry type, does not. Can anyone suggest why this is the case?
Here's my query, where the buffer is specified in decimal degrees:
SELECT filename, (stats).* FROM ( SELECT filename, ST_SummaryStats( ST_Clip( rast, 1, ST_Buffer( ST_SetSRID( ST_Point(-90, 45), 4326 ), 1 ), TRUE ), 1, TRUE ) AS stats FROM rasters WHERE filename IN ('raster_grid_1_1_nodata.tif') ) AS stats_tbl;
As you can see, there are
rast columns that contain the name of the input file and the input raster, respectively. The result is as expected.
Here's my query, where the buffer is specified in meters:
SELECT (summarystats).* FROM ( SELECT ST_SummaryStats( ST_Clip( rast, 1, CAST( ST_Buffer( CAST( ST_SetSRID( ST_Point(-90, 45), 4326 ) AS geography ), 1000 ) AS geometry ), TRUE ), 1, TRUE ) AS summarystats FROM rasters WHERE filename IN ('raster_grid_1_1_nodata.tif') ) AS summarystats_tbl;
As you can see, I pass a
ST_Buffer so that the radius is specified in meters. The result, however, is not as expected: PostGIS reports that all pixels have the
NODATA value and, consequently, does not compute summary statistics. Can anyone suggest why this is the case?