[postgis-devel] ST_SetValues (Generating raster from point data)

David Haynes II dahaynes at umn.edu
Tue Oct 28 10:04:12 PDT 2014


Hello,

I am hoping someone can help point me in the correct direction on this
problem. I am trying to take a table of point data and generate a raster,
using some NOAA data. These are the steps that I have taken so far.
Everything is fine until step 4.
The ST_SetValues does not work as I have currently implemented. Because
each time a value is assigned it generates another raster.
The examples I have seen using ST_SetValues require each recordset to be
appended to each other. Does anyone have any knowledge about other psql
functions that will allow me to transpose the recordset or append
recordsets together. I am considering writing a custom function to do the
task.

1. Convert text to geometry value
2. Determine raster extent using convexhull.
3. Generate raster using ST_AsRaster
4. Set raster cell values using ST_SetValues

with noaa_raster as
(
select ST_AsRaster(p_bound.geom, 3.75::float8, 2.5::float8, '32BF', 1, 0)
as rast
 from (
  --Generate polygon extent from all points
  SELECT st_convexhull(ST_Collect(base.geom)) as geom
  FROM (
  --Converts text to geometry
  select p.grid_id, ST_geomfromtext('POINT(' || p.longitude || ' ' ||
p.latitude || ')',4326) as geom, p.value
  from noaa p
  ) base
  ) p_bound
)
--distances are changed to make sure we fine the centroid of each raster
cell
select r.rid, p.grid_id, ST_SetValues(r.rast, 1,
ARRAY[ROW(ST_geomfromtext('POINT(' || p.longitude + 1.875 || ' ' ||
p.latitude - 1.25 || ')',4326), p.value)]::geomval[], True ) as rast
from noaa p, noaa_raster r


see
http://postgis.net/docs/manual-dev/RT_ST_SetValues.html

-- 
David Haynes, Ph.D.
Research Associate Terra Populus
Minnesota Population Center
www.terrapop.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20141028/5b98c7f5/attachment.html>


More information about the postgis-devel mailing list