Skip to content

Commit

Permalink
Added CIMIS Mobile info. Added Preliminary Zones Map.
Browse files Browse the repository at this point in the history
  • Loading branch information
qjhart committed Aug 6, 2016
1 parent 2fc05d8 commit 2b3be7b
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 2 deletions.
14 changes: 13 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
*.tif binary
*.mp4 binay
*.mp4 binay export-ignore
Makefile export-ignore
.git* export-ignore
*.sql export-ignore
*.mk export-ignore
classifications/ export-ignore
fft/ export-ignore
earthengine/ export-ignore
shp/ export-ignore
src/ export-ignore
station_comparisons/ export-ignore
tif/ export-ignore
zone_nums.csv export-ignore
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ geojson/original_zones.geojson: src/original_zones.vrt

# Here's an Example of materializing that VRT file, for example to
# upload to Google Maps.
shp: src/original_zones.vrt
shp:: src/original_zones.vrt
ogr2ogr $@ $<

original_zones.csv: src/original_zones.vrt
Expand All @@ -17,3 +17,13 @@ original_zones.csv: src/original_zones.vrt

original_zones_each.csv: src/original_zones.vrt
psql service=eto_zones -c '\COPY (with b as (select definition,st_asKML(wkb_geometry) as boundary from original_zones) select num,definition,boundary from zone_nums join b using (definition)) to $@ with csv header'

shp/final_zones.shp:src/final_zones.vrt
ogr2ogr $@ $<

eto_zones.geojson: src/final_zones.vrt
ogr2ogr -f GEOJSON -t_srs WGS84 $@ $<

postgis: shp/final_zones.shp
shp2pgsql -s 3310 -d $< | ${PG}

60 changes: 60 additions & 0 deletions cimis_mobile.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
-- This SQL creates the required json for calculating the daily summaries by
-- dau and eto_zone

create view keys as
with g as (
select
510 as ncols,
560 as nrows,
-410000 as xllcorner,
-660000 as yllcorner,
2000 as cellsize
)
select
pid,north,east,
nrows-floor((north - yllcorner) / cellsize) ||'-'||
floor((east-xllcorner) / cellsize ) as key
from g,cimis_boundary order by north desc,east asc;


-- CIMIS pixels retrieved from website.
create table cimis_boundary as
select
pid,east,north,
st_setsrid(st_makebox2d(
st_makepoint(east-1000,north-1000),
st_makepoint(east+1000,north+1000)),3310) as boundary
from raster_15avg
join cimis_pixels using (pid);

-- Areas for each pixel in each DAU
create temp table dau_pixel_area as
select pid,dau_code,
st_area(st_intersection(p.boundary,d.wkb_geometry)) as area
from cimis_boundary p
join detailed_analysis_units d on st_intersects(p.boundary,d.wkb_geometry);

create view json_index as with a as (
select pid,
'DAU'||dau_code as code,
(100*area/4000000.0)::integer as area
from dau_pixel_area
union
select pid,'Z'||zone_id as code,
100 as area
from avg_0625.total_move_rmse_min where zones=17
),
k as (
select
--east,north,
key,
json_object(
array_agg(code order by code),
array_agg(area::text order by code)
) as v
from a join cimis_boundary using (pid)
join keys using (pid)
where area > 5
group by key
order by key)
select ('{'||string_agg('"'||key||'":'||v,',')||'}')::jsonb as index from k;
226 changes: 226 additions & 0 deletions eto_zones.geojson

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions final_zones.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- From the import of Mui's final zones table.....
-- The 1 byte id is p0*25. Or p0 ~ zone_number/25
alter table final_zones add column zone_number integer;
update final_zones set zone_number = (p0*25)::integer;

create table final_zones_rast as
with t as (
select rast
from avg_0625.zones_map
limit 1
),
v(t,b,e) as (
values (ARRAY['8BUI','32BF','32BF','32BF','32BF','32BF'],
ARRAY[
ROW(null,'8BUI',0,0),
ROW(null,'32BF',0,0),
ROW(null,'32BF',0,0),
ROW(null,'32BF',0,0),
ROW(null,'32BF',0,0),
ROW(null,'32BF',0,0)]::addbandarg[],
ARRAY[0.0,0,0,0,0,0])
),
r as (
select
st_union(st_asRaster(geom,rast,t,
ARRAY[(p0*25)::integer::float,p0,p1,p2,h1,h2],e)) as rast
from final_zones,t,v
),
tot as (
select st_addBand(rast,b) as rast from t,v
union
select rast from r
)
select st_union(rast) as rast
from tot;

create table final_zones_pixels as
with f as (
select (st_pixelascentroids(rast,1)).*
from final_zones_rast
),
p as (
select st_x(geom) as east,st_y(geom) as north,val
from f
)
select
pid,east,north,val
from p
left join cimis_boundary
using (east,north);

0 comments on commit 2b3be7b

Please sign in to comment.