Skip to content

Commit

Permalink
Dissolved catchments
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusyoung committed May 28, 2019
1 parent 1576d43 commit 926ab75
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
11 changes: 10 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# stationdemandr 0.2.2.9000
# stationdemandr 0.2.3

## Performance improvements

- Modified `sdr_craete_json_catchment()` to improve catchment display performance.
Probability is now rounded to 1 decimal places and then st_union is used to
dissolve the postcode polygons, grouped by probability. The GeoJSON is then
generated. This means that any catchment will now have a maximum feature count
of 10. Also defined `maxdecimaldigits` for `st_asgeojson`, set to 5 rather than
the default of 15.


# stationdemandr 0.2.2
Expand Down
67 changes: 35 additions & 32 deletions R/sdr_create_json_catchment.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,57 +68,60 @@ sdr_create_json_catchment <-
stop("type not valid")
}

futile.logger::flog.info(paste0(
"Creating GeoJSON catchment where ", where_clause, " in ",
update_table,
".",
set_column
))
futile.logger::flog.info(
paste0(
"Creating GeoJSON catchment where ",
where_clause,
" in ",
update_table,
".",
set_column
)
)

query <- paste0(
"update ",
update_table,
" set ",
set_column,
" = (select row_to_json(fc)
" = ( select row_to_json(fc)
from (
select
select
'FeatureCollection' as \"type\",
array_to_json(array_agg(f)) as \"features\"
from (
select
'Feature' as \"type\",
st_asgeojson(st_transform(st_simplifypreservetopology(b.geom, ",
tolerance,
"), 4326)) :: json as \"geometry\",
(
select json_strip_nulls(row_to_json(t))
from (
select
a.postcode,
round(a.te19_prob, 2) as probability
) t
) as \"properties\"
from ",
with tmp as (
select round(a.te19_prob, 1) as probability, st_union(b.geom) as geom from ",
schema,
".probability_",
tablesuffix,
" as a
left join data.postcode_polygons b on a.postcode = b.postcode
left join data.pc_pop_2011 c on a.postcode = c.postcode
" a
left join data.postcode_polygons b on a.postcode = b.postcode
left join data.pc_pop_2011 c on a.postcode = c.postcode
where a.crscode = '",
crs,
"' and a.te19_prob > ",
cutoff,
" and st_within(c.geom,
(select service_area_60mins from ",
"' and a.te19_prob > 0.01 and st_within(c.geom, (select service_area_60mins from ",
sa_table,
" where crscode = '",
crs,
"'))
) as f
group by probability
)
select
'Feature' as \"type\",
st_asgeojson(st_transform(st_simplifypreservetopology(a.geom, ", tolerance, "), 4326), 5) :: json as \"geometry\",
(
select json_strip_nulls(row_to_json(t))
from (
select
a.probability
) t
) as \"properties\"
from tmp as a
) as f
) as fc ) where ",
where_clause
where_clause
)
sdr_dbExecute(con, query)
sdr_dbExecute(con, query)
}

0 comments on commit 926ab75

Please sign in to comment.