
select  Clip(data, '(-1704753, -581511, -1604753, -481829)'::Box) as
  data, rtime from rasters where frequency = 5 order by rtime;

select AVG(Clip(data, '(-1704753,-581511,-1604753,-481829)'::Box))
       as x from rasters 
where rtime = 1 ;

create table foo_1 as select  1 as rtime, 64 as resolution, 5 as frequency, 
       LowerRes(Clip(data, '(-1704753, -581511, -1604753, -481829)'::Box), 64) 
       as data from rasters where rtime = 1 and frequency = 5;

select * from points where name = 'Abadi Creek';

create table foo_2 as select * from polygons 
where location &  '(-1704753, -581511, -1604753, -581511, -1604753, -481829, -1704753, -481829)'::Poly;

select location
from polygons
where (size(location) > '1014420.0') and
       (location ^ '(-1701583, -584681, -1707923, -584681, -1707923, -578341, -1701583, -578341)'::Poly) and
       (location ^ Circ('(-1704753, -581511)'::Pnt,'3170.0'::double precision));

select p.landuse, p.location
from polygons p, points poi 
 where (p.location & box_make_poly(make_box(poi.location,'50000.0'))) and
       (poi.name = 'Zaca Ridge');

select p.location, Clip(r.data, p.location) as x
  from polygons p, rasters r 
 where p.landuse = 92 and r.frequency = 5 and r.rtime = 1; 
