get spatial extend
generate a raster covering this extand with givenpixel size and given bands
for pixel which intersects a point, set pixel band values with point attributes
Cheers,use efficient image processing code to interpolate
SELECT postgis_full_version();--POSTGIS="2.1.0 r11822" GEOS="3.5.0dev-CAPI-1.9.0 r3963" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.10.0, released 2013/04/24" LIBXML="2.8.0" RASTER----converting a patch to raster--get patch extend--create a raster with this extend--explode patch to points--set pixel value to point intersecting it.--preparing raster :--creating the raster tableDROP TABLE IF EXISTS patch_to_raster;CREATE TABLE patch_to_raster(rid serial primary key, rast raster);----DELETE from patch_to_raster--inserting an empty rasterINSERT INTO patch_to_raster (rast) VALUES (ST_MakeEmptyRaster(50,50,upperleftx:=0,upperlefty:=0,scalex:=1, scaley:=1, skewx:=0,skewy:=0, srid:=932011) --srid of translated lambert 93 to match laser referential);--setting the correct pixel sizeUPDATE patch_to_raster SET rast = ST_SetScale(rast,0.02,0.02);--checking the content:SELECT ST_Summary(rast)FROM patch_to_raster;--Raster of 50x50 pixels has 0 bands and extent of BOX(0 0,1 1)--adding band--first band is Z : float--second band is reflectance : floatUPDATE patch_to_raster SET rast = ST_AddBand( --1'st band, Zrast,pixeltype:='32BF' -- '32BUI', initialvalue:=NULL, nodataval:=NULL);UPDATE patch_to_raster SET rast = ST_AddBand( --2nd band, reflectancerast, pixeltype:='32BF' --'32BUI', initialvalue:=NULL, nodataval:=NULL);--checking the content:SELECT ST_Summary(rast) FROM patch_to_raster;--Raster of 50x50 pixels has 2 bands and extent of BOX(0 0,1 1)--band 1 of pixtype 32BF is in-db with no NODATA value--band 2 of pixtype 32BF is in-db with no NODATA value--getting a patch and creating a table with itDROP TABLE IF EXISTS one_patch_into_points;CREATE TABLE one_patch_into_points ASWITH patch AS (SELECT gid,patchFROM acquisition_tmob_012013.riegl_pcpatch_spaceWHERE gid = 87263),point AS (SELECT PC_Explode(patch) AS pointFROM patch)SELECT row_number() over() AS qgis_id, ST_SetSRID(point::geometry,932011) AS geom, @(PC_Get(point, 'z')*1000)::int AS z, @((PC_Get(point, 'reflectance')+50)*200)::int aS reflectanceFROM point;--2746 points--checkingSELECT *FROM one_patch_into_points--1 01010000A0AB380E00DC7EFB3A1090A140CDFDD4780132D440A69BC42020834840 49024 8110--2 POINT Z (2247.76560000001 20680.2519999999 49.0198828125) 49020 7890--updating the raster to set it on the patch place.--we get the upper left coordinate of patchWITH patch AS (SELECT gid,patch, ST_AsText(patch::geometry)FROM acquisition_tmob_012013.riegl_pcpatch_spaceWHERE gid = 87263),centroid AS (SELECT ST_Centroid(patch::geometry) AS centroidFROM patch),upperleft AS (SELECT round(ST_X(centroid)) -0.5 AS upper_left_x, round(ST_y(centroid))-0.5 AS upper_left_yFROM centroid)--updating the raster with itUPDATE patch_to_raster SET rast = ST_SetUpperLeft(rast,upper_left_x,upper_left_y)FROM upperleft;--checking the rasterSELECT ST_Summary(rast) FROM patch_to_raster;--Raster of 50x50 pixels has 2 bands and extent of BOX(2247.5 20679.5,2248.5 20680.5)--note : the patch bbox : POLYGON((2247.51 20679.50,2247.51 20680.49,2248.49 20680.49,2248.49 20679.50,2247.51 20679.50)), some pixels will be empty--updating the raster with pixel value--using postgis_addons function : https://raw.github.com/pedrogit/postgisaddons/master/postgis_addons.sql--UPDATE patch_to_raster SET rast =ST_ExtractToRaster(rast,band:=1,schemaname:= 'test_raster',tablename:= 'one_patch_into_points',geomrastcolumnname:= 'geom',valuecolumnname:='z');--5 sec : way too long!UPDATE patch_to_raster SET rast =ST_ExtractToRaster(rast,band:=2,schemaname:= 'test_raster',tablename:= 'one_patch_into_points',geomrastcolumnname:= 'geom',valuecolumnname:='reflectance',method:='MEAN_OF_VALUES_AT_PIXEL_CENTROID');--6 sec, way too long !--checking the value of pixel in both band (no shortcut to get several bands at a time??)SELECT s1 as x, s2 as y, ST_Value(rast, 1,s1, s2, exclude_nodata_value:=true) AS value_band_1, ST_Value(rast, 2,s1, s2, exclude_nodata_value:=true) AS value_band_2FROM generate_series(1,50) as s1, generate_series(1,50) as s2, patch_to_raster;--values are NULL!--checking the histogramSELECT ST_Histogram( rast, 1 ) --, boolean exclude_nodata_value=trueFROM patch_to_raster;--no line returned--checking resultSELECT ST_Summary(rast) FROM patch_to_raster;--Raster of 50x50 pixels has 2 bands and extent of BOX(2247.5 20679.5,2248.5 20680.5)-- band 1 of pixtype 32BF is in-db with NODATA value of -3.40282346638529e+38-- band 2 of pixtype 32BF is in-db with NODATA value of -3.40282346638529e+38////////////////////////////////