Skip to content

Commit

Permalink
Add territory outlines and increase resolution
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
arcresu committed Jan 11, 2024
1 parent 6b770f6 commit 6ab6942
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 58 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
export(crs_gda2020)
export(normalise_postcodes)
export(normalise_state_names)
export(outline)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

* Add Primary Health Network (PHN) map data as `phn` dataset.
* Fixed the `poa_nsw` dataset to avoid strange geometries near the state border.
* Added geometries for Lord Howe Island, Australian Capital Territory, and
Jervis Bay Territory, and a utility function `outline()` for using them.
* Slightly increase the resolution to 750 m instead of 1 km.

# nswgeo 0.3.3

Expand Down
42 changes: 36 additions & 6 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,43 @@
#' @describeIn australia State and internal territory boundaries of Australia.
"states"

#' Outlines of New South Wales and relevant territories.
#'
#' Lord Howe Island is administratively part of NSW, but as it is a small
#' island some 600 km off the coast, it is frequently omitted from maps of NSW.
#'
#' The Australian Capital Territory is an enclave within NSW, and Jervis Bay
#' Territory is a small Australian territory on the coast, surrounded by NSW.
#' Neither are NSW territory, but they affect the shape of NSW's outline and are
#' sometimes useful to include in maps alongside NSW due to their locations.
#'
#' The geometry for `nsw` has been simplified with a tolerance of 750 m to
#' reduce the level of detail, whereas the territories maintain their full
#' resolution.
#'
#' @seealso [outline()]
#' @source
#' Australian Bureau of Statistics. "Australian Statistical Geography Standard (ASGS) Edition 3." ABS, Jul2021-Jun2026,
#' \url{https://www.abs.gov.au/statistics/standards/australian-statistical-geography-standard-asgs-edition-3/jul2021-jun2026}, accessed 27 September 2022.
#'
#' The original dataset is published under the [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/) licence, © Commonwealth of Australia 2021.
#' @describeIn nsw External state boundary excluding LHI but including ACT and JBT.
"nsw"
#' @describeIn nsw Australian Capital Territory boundary.
"act"
#' @describeIn nsw Lord Howe Island boundary.
"lhi"
#' @describeIn nsw Jervis Bay Territory boundary.
"jbt"

#' Geospatial data of the New South Wales administrative boundaries.
#'
#' Excludes the borders with the ACT and Jervis Bay Territory, and Lord Howe Island.
#' These include the Unincorporated Far West Region.
#' `lga_nsw` excludes Jervis Bay Territory and the ACT.
#' `poa_nsw` includes both territories and some postal areas extend past the
#' state boundary.
#'
#' The geometries have been simplified with a tolerance of 1 km to reduce the
#' The geometries have been simplified with a tolerance of 750 m to reduce the
#' level of detail.
#'
#' @examples
Expand All @@ -62,11 +94,9 @@
#' \url{https://www.abs.gov.au/statistics/standards/australian-statistical-geography-standard-asgs-edition-3/jul2021-jun2026}, accessed 27 September 2022.
#'
#' The original dataset is published under the [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/) licence, © Commonwealth of Australia 2021.
#' @describeIn nsw External boundaries of New South Wales as a multipolygon.
"nsw"
#' @describeIn nsw Local Government Area boundaries of New South Wales.
#' @describeIn nsw_admin Local Government Area boundaries of New South Wales.
"lga_nsw"
#' @describeIn nsw Postal area boundaries of New South Wales.
#' @describeIn nsw_admin Postal area boundaries of New South Wales.
"poa_nsw"

#' Local Health Districts of NSW.
Expand Down
49 changes: 49 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,52 @@ normalise_postcodes <- function(codes) {
crs_gda2020 <- function() {
sf::st_crs("EPSG:7844")
}

#' New South Wales outline with or without related territories
#'
#' The default outline `nswgeo::nsw` includes Jervis Bay Territory, excludes
#' Lord Howe Island, and does not have a cut out for the ACT. This utility
#' allows each of these to be adjusted.
#'
#' @seealso [nsw]
#'
#' @param lord_howe_island Include Lord Howe Island.
#' @param act_cutout Cut out the area of the Australian Capital Territory.
#' @param jervis_bay Cover the area of the Jervis Bay Territory.
#'
#' @return A simple features data frame with the requested geometries.
#' @export
#'
#' @examples
#' library(ggplot2)
#'
#' outline(lord_howe_island = TRUE) |> ggplot() + geom_sf()
outline <- function(lord_howe_island = FALSE, act_cutout = TRUE, jervis_bay = TRUE) {
base <- nswgeo::nsw

if (act_cutout) {
base <- sf::st_difference(base, nswgeo::act)
}

if (!jervis_bay) {
# Since the default includes JBT and is simplified (reduced resolution), the
# shape of JBT needs to be enlarged a bit to avoid leaving odd pieces of
# geometry behind when intersecting.
crs_working <- sf::st_crs("+proj=eqc +lat_ts=34 units=m")
jbt <- nswgeo::jbt |>
sf::st_transform(crs_working) |>
sf::st_simplify(dTolerance = 750L) |>
sf::st_buffer(250L)
base <- base |>
sf::st_transform(crs_working) |>
sf::st_difference(jbt) |>
sf::st_transform(sf::st_crs(nswgeo::nsw)) |>
sf::st_make_valid()
}

if (lord_howe_island) {
sf::st_sf(geometry = rbind(base, nswgeo::lhi), name = c("NSW", "Lord Howe Island"))
} else {
sf::st_sf(geometry = base, name = "NSW")
}
}
87 changes: 61 additions & 26 deletions data-raw/ASGS_Ed3.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ library(nngeo)
sf_use_s2(FALSE)

# reduce the resolution of the borders to 1km
tolerance_m <- 1000L
tolerance_m <- 750L

# list layers available
st_layers(abs_geopackage)
Expand All @@ -27,44 +27,79 @@ lga <- read_sf(abs_geopackage, layer = "LGA_2021_AUST_GDA2020")
crs_nsw <- sf::st_crs(7844) # GDA2020
crs_working <- sf::st_crs("+proj=eqc +lat_ts=34 units=m")

# Unincorporated NSW includes Lord Howe Island but also the Unincorporated Far
# West Region. Remove LHI by culling everything east of 150.
# NSW administrative boundaries have some quirks to account for:
#
# - Unincorporated Far West Region
# - Lord Howe Island
# - Australian Capital Territory
# - Jervis Bay Territory

# The ABS LGA region of "Unincorporated NSW" includes both Lord Howe Island
# and the Unincorporated Far West Region. Separate these.
nsw_hires_ui <- filter(lga, LGA_NAME_2021 == "Unincorporated NSW")
bb <- st_bbox(nsw_hires_ui)
bb["xmax"] <- 150
nsw_hires_ui <- st_intersection(
ufwr_hires <- st_intersection(
st_transform(nsw_hires_ui, crs_working),
st_transform(st_as_sfc(bb), crs_working)
) |> st_transform(crs_nsw)
bb <- st_bbox(nsw_hires_ui)
bb["xmin"] <- 158
lhi_hires <- st_intersection(
st_transform(nsw_hires_ui, crs_working),
st_transform(st_as_sfc(bb), crs_working)
) %>% st_transform(crs_nsw)
) |> st_transform(crs_nsw)
lhi <- st_geometry(lhi_hires)
object.size(lhi)
usethis::use_data(lhi, overwrite = TRUE)

lga_nsw <- lga %>%
filter(STATE_NAME_2021 == "New South Wales", LGA_NAME_2021 != "Unincorporated NSW") %>%
rbind(nsw_hires_ui) %>%
st_transform(crs_working) %>%
st_simplify(dTolerance = tolerance_m) %>%
# The ABS LGA region of "Unincorp. Other Territories" includes both Norfolk
# Island and the Jervis Bay Territory, of which we only need the latter.
aus_hires_ui <- filter(lga, LGA_NAME_2021 == "Unincorp. Other Territories")
bb <- st_bbox(aus_hires_ui)
bb["xmax"] <- 153
jbt_hires <- st_intersection(
st_transform(aus_hires_ui, crs_working),
st_transform(st_as_sfc(bb), crs_working)
) |> st_transform(crs_nsw)
jbt <- st_geometry(jbt_hires)
object.size(jbt)
usethis::use_data(jbt, overwrite = TRUE)

lga_nsw <- lga |>
filter(STATE_NAME_2021 == "New South Wales", LGA_NAME_2021 != "Unincorporated NSW") |>
rbind(ufwr_hires) |>
st_transform(crs_working) |>
st_simplify(dTolerance = tolerance_m) |>
st_transform(crs_nsw)
object.size(lga_nsw)
usethis::use_data(lga_nsw, overwrite = TRUE)

nsw_hires <- lga %>%
filter(STATE_NAME_2021 == "New South Wales", LGA_NAME_2021 != "Unincorporated NSW") %>%
rbind(nsw_hires_ui) %>%
st_transform(crs_working) %>%
st_union() %>%
st_remove_holes() %>%
act_hires <- lga |>
filter(STATE_NAME_2021 == "Australian Capital Territory", ! st_is_empty(geom))
act <- st_geometry(act_hires)
object.size(act)
usethis::use_data(act, overwrite = TRUE)

nsw_hires <- lga |>
filter(STATE_NAME_2021 == "New South Wales", LGA_NAME_2021 != "Unincorporated NSW") |>
rbind(ufwr_hires, jbt_hires) |>
st_transform(crs_working) |>
st_union() |>
st_remove_holes() |>
st_make_valid()
nsw <- nsw_hires %>%
st_simplify(dTolerance = tolerance_m) %>%
nsw <- nsw_hires |>
st_simplify(dTolerance = tolerance_m) |>
st_transform(crs_nsw)
object.size(nsw_hires)
object.size(nsw)
usethis::use_data(nsw, overwrite = TRUE)

# sal <- read_sf(abs_geopackage, layer = "SAL_2021_AUST_GDA2020")
# sal_nsw <- sal %>%
# st_transform(crs_working) %>%
# filter(STATE_NAME_2021 == "New South Wales") %>%
# st_simplify(dTolerance = tolerance_m) %>%
# sal_nsw <- sal |>
# st_transform(crs_working) |>
# filter(STATE_NAME_2021 == "New South Wales") |>
# st_simplify(dTolerance = tolerance_m) |>
# st_transform(crs_nsw)
# object.size(sal_nsw)

Expand All @@ -78,10 +113,10 @@ poa_in_nsw <- st_intersects(
st_buffer(nsw_hires, -100L)) |>
sapply(function(x) length(x) > 0)

poa_nsw <- poa[poa_in_nsw, ] %>%
st_transform(crs_working) %>%
st_simplify(dTolerance = tolerance_m, preserveTopology = TRUE) %>%
st_transform(crs_nsw) %>%
poa_nsw <- poa[poa_in_nsw, ] |>
st_transform(crs_working) |>
st_simplify(dTolerance = tolerance_m, preserveTopology = TRUE) |>
st_transform(crs_nsw) |>
st_make_valid()
stopifnot(all(!st_is_empty(poa_nsw)))
stopifnot(all(st_geometry_type(poa_nsw) != "GEOMETRYCOLLECTION"))
Expand Down
Binary file added data/act.rda
Binary file not shown.
Binary file added data/jbt.rda
Binary file not shown.
Binary file modified data/lga_nsw.rda
Binary file not shown.
Binary file added data/lhi.rda
Binary file not shown.
Binary file modified data/nsw.rda
Binary file not shown.
Binary file modified data/poa_nsw.rda
Binary file not shown.
Binary file modified man/figures/README-cartographer-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 29 additions & 26 deletions man/nsw.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions man/nsw_admin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6ab6942

Please sign in to comment.