Get Energex Map Data from REST services

Last update: 13 May 2023

Saved data when last run - 11 Jan 2023 to folder

Reduce Noosa LGA bounding box buffer to 1km (down from 10km)

Use bounding box for all entities - so we just grab the Noosa ones

Can set mygeometry = “” to get all data

References

Ergon services are also available

I used this Blog post to write code to access the ArcGIS REST services

https://community.esri.com/t5/gis-blog/accessing-arcgis-rest-services-using-r/ba-p/898451

This blog post was also useful, although I couldn’t get the code to work

https://kdvdecisions-blog.netlify.app/2020/04/18/obtaining-spatial-data-from-esri-rest-apis-in-r/

The author suggests that you start by trying out any query first

e.g. check out this page for the 132kV Sub-Tranmission Line(ID:4) service scroll down to the bootom of the page to Supported Operations and click on Query to get following URL

https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/4/query

Practice on the REST service here, usually just using Where: & Input Geometry: fields

Note if you just use an Input Geometry, you should make the where clause something like 1 = 1

Refactoring to be done
  • check if file exits before st_write()

  • when reading via the REST services, the results should be saved using st_write(), instead of saveRDS

  • then when reading back the stored data in this Rmd, use st_read()

The following feature service numbers are from https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer

  • use these numbers for the ArcGIS REST service call

Zone Substations (0)

Distribution Substations (1)

Poles (2)

Pillars (3)

132kV Sub-Transmission Line (4)

132kV Sub-Transmission Cable (5)

110kV Sub-Transmission Line (6)

110kV Sub-Transmission Cable (7)

33kV Sub-Transmission Line (8)

33kV Sub-Transmission Cable (9)

11kV High Voltage Line (10)

11kV High Voltage Cable (11)

Low Voltage Line (12)

Low Voltage Cable (13)

ZoneSub_query = "0"
Substations_query = "1"
Poles_query = "2"
Pillars_query = "3"
OH_132kV_query = "4"
UG_132kV_query = "5"
OH_110kV_query = "6"
UG_110kV_query = "7"
OH_33kV_query = "8"
UG_33kV_query = "9"
OH_11kV_query = "10"
UG_11kV_query = "11"
OH_LV_query = "12"
UG_LV_query = "13"

base_energex_url <- parse_url("https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services")
FeatureServer_url <- "Network_Energex/FeatureServer" 

# define some global variables for folders
base_folder <- getwd()
maps_folder <- paste(base_folder,"/Energex_maps/",sep = "")

tmap_mode(mode = "view")
## tmap mode set to interactive viewing
# set up so we just get data for Noosa LGA 
myLGA <- readRDS(file=paste0(maps_folder,"Queensland_LGA_map.rds"))

#myLGA <- readRDS(file=paste0(maps_folder,"Queensland_LGA_map.rds"))
# just get Gympie=3620, Noosa=5740 & Sunshine Coast=6720
JustNoosaLGA <- myLGA %>% filter(LGA_CODE == '5740')
# NoosaLGA <- myLGA %>% filter(LGA_CODE %in% c('3620','5740','6720'))

# create a bounding box around a 10km buffer around Noosa LGA
# reduce this to 1km
bbNoosaLGA <- st_bbox(st_buffer(JustNoosaLGA, 1000))
mygeometry = toString(bbNoosaLGA)

# ===================== F U N C T I O N ==================
get_Energex_map <- function(service_query, where_clause, my_geometry) {
  myurl <- base_energex_url
  myurl$path <- paste(myurl$path,FeatureServer_url ,service_query,"query", sep = "/")
  myurl$query <- list(where = where_clause,
                      geometry = my_geometry,
                      outfields = "*",
                      returnGeometry = "true",
                      f = "geojson")
  myrequest <- build_url(myurl)
  myMapData <- st_read(myrequest)
  
  return(myMapData)
}
# ==============================================================

Get and save objects

Zone Substations (0) - write

# Zone Substations (0)
myZoneSub <- get_Energex_map(ZoneSub_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/0/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 9 features and 8 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: 152.7778 ymin: -26.48281 xmax: 153.0689 ymax: -26.31804
## Geodetic CRS:  WGS 84
# tm_shape(myZoneSub)+tm_dots()

shp_filename = paste(maps_folder,"EnegexZoneSub.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myZoneSub,shp_filename )
## Writing layer `EnegexZoneSub' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/EnegexZoneSub.shp' using driver `ESRI Shapefile'
## Writing 9 features with 8 fields and geometry type Point.

Get Subtransmission

# OH_132kV_query = "4"
myOH_132kV <- get_Energex_map(OH_132kV_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/4/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 10 features and 8 fields
## Geometry type: MULTILINESTRING
## Dimension:     XY
## Bounding box:  xmin: 152.6817 ymin: -26.60983 xmax: 153.0689 ymax: -26.1962
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Enegex_OH_132kV.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myOH_132kV, shp_filename)
## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Writing layer `Enegex_OH_132kV' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Enegex_OH_132kV.shp' using driver `ESRI Shapefile'
## Writing 10 features with 8 fields and geometry type Multi Line String.
# UG_132kV_query = "5"
myUG_132kV <- get_Energex_map(UG_132kV_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/5/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 0 features and 0 fields
## Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Enegex_UG_132kV.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myUG_132kV, shp_filename)
## Writing layer `Enegex_UG_132kV' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Enegex_UG_132kV.shp' using driver `ESRI Shapefile'
## Writing 0 features with 0 fields and geometry type Unknown (any).
# OH_110kV_query = "6"
myOH_110kV <- get_Energex_map(OH_110kV_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/6/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 0 features and 0 fields
## Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_OH_110kV.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myOH_110kV, shp_filename)
## Writing layer `Energex_OH_110kV' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_OH_110kV.shp' using driver `ESRI Shapefile'
## Writing 0 features with 0 fields and geometry type Unknown (any).
# UG_110kV_query = "7"
myUG_110kV <- get_Energex_map(UG_110kV_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/7/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 0 features and 0 fields
## Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_UG_110kV.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myUG_110kV, shp_filename)
## Writing layer `Energex_UG_110kV' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_UG_110kV.shp' using driver `ESRI Shapefile'
## Writing 0 features with 0 fields and geometry type Unknown (any).
# tm_shape(myOH_132kV)+tm_lines(col='red', lwd=10) +
# # tm_shape(read132UG)+tm_lines(col='orange',lwd=10)+   nothing to display !
# tm_shape(myOH_110kV)+tm_lines(col='blue',lwd=8)+
# tm_shape(myUG_110kV)+tm_lines(col='green',lwd=8) +
# tm_shape(myZoneSub)+tm_dots(size = 0.1)

Read back shape files to check and display

# now check save
# readZoneSub <- st_read(dsn = paste0(maps_folder,"EnegexZoneSub.shp"))
# read132OH <- st_read(dsn = paste0(maps_folder,"Enegex_OH_132kV.shp"))
# read132UG <- st_read(dsn = paste0(maps_folder,"Energex_UG_132kV.shp"))
# read110OH <- st_read(dsn = paste0(maps_folder,"Energex_OH_110kV.shp"))
# read110UG <- st_read(dsn = paste0(maps_folder,"Energex_UG_110kV.shp"))
# 
# tm_shape(read132OH)+tm_lines(col='red', lwd=10) +
# # tm_shape(read132UG)+tm_lines(col='orange',lwd=10)+   nothing to display !
# tm_shape(read110OH)+tm_lines(col='blue',lwd=8)+
# tm_shape(read110UG)+tm_lines(col='green',lwd=8) +
# tm_shape(readZoneSub)+tm_dots(size = 0.1)

Get 33kV

# OH_33kV_query = "8"
myOH_33kV <- get_Energex_map(OH_33kV_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/8/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 7 features and 8 fields
## Geometry type: MULTILINESTRING
## Dimension:     XY
## Bounding box:  xmin: 152.655 ymin: -26.55456 xmax: 153.0827 ymax: -26.1966
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_OH_33kV.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myOH_33kV, shp_filename)
## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Writing layer `Energex_OH_33kV' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_OH_33kV.shp' using driver `ESRI Shapefile'
## Writing 7 features with 8 fields and geometry type Multi Line String.
# UG_33kV_query = "9"
myUG_33kV <- get_Energex_map(UG_33kV_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/9/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 5 features and 8 fields
## Geometry type: MULTILINESTRING
## Dimension:     XY
## Bounding box:  xmin: 152.9228 ymin: -26.55537 xmax: 153.0827 ymax: -26.40837
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_UG_33kV.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myUG_33kV, shp_filename)
## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Writing layer `Energex_UG_33kV' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_UG_33kV.shp' using driver `ESRI Shapefile'
## Writing 5 features with 8 fields and geometry type Multi Line String.
# tm_shape(read132OH)+tm_lines(col='red', lwd=10) +
# # tm_shape(read132UG)+tm_lines(col='orange',lwd=10)+   nothing to display !
# tm_shape(read110OH)+tm_lines(col='blue',lwd=8)+
# tm_shape(read110UG)+tm_lines(col='green',lwd=8) +
# 
# tm_shape(myOH_33kV)+tm_lines(col='purple',lwd=4) +
# tm_shape(myUG_33kV)+tm_lines(col='pink',lwd=4) +
# 
# tm_shape(readZoneSub)+tm_dots(size=0.1)

Get 11kV

# OH_11kV_query = "10"
myOH_11kV <- get_Energex_map(OH_11kV_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/10/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 48 features and 8 fields
## Geometry type: MULTILINESTRING
## Dimension:     XY
## Bounding box:  xmin: 152.5071 ymin: -26.60354 xmax: 153.1134 ymax: -26.00146
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_OH_11kV.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myOH_11kV, shp_filename)
## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Writing layer `Energex_OH_11kV' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_OH_11kV.shp' using driver `ESRI Shapefile'
## Writing 48 features with 8 fields and geometry type Multi Line String.
# UG_11kV_query = "11"
myUG_11kV <- get_Energex_map(UG_11kV_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/11/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 48 features and 8 fields
## Geometry type: MULTILINESTRING
## Dimension:     XY
## Bounding box:  xmin: 152.7026 ymin: -26.55708 xmax: 153.1127 ymax: -26.27735
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_UG_11kV.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myUG_11kV, shp_filename)
## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Writing layer `Energex_UG_11kV' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_UG_11kV.shp' using driver `ESRI Shapefile'
## Writing 48 features with 8 fields and geometry type Multi Line String.
# tm_shape(read132OH)+tm_lines(col='red', lwd=10) +
# # tm_shape(read132UG)+tm_lines(col='orange',lwd=10)+   nothing to display !
# tm_shape(read110OH)+tm_lines(col='blue',lwd=8)+
# tm_shape(read110UG)+tm_lines(col='green',lwd=8) +
# 
# tm_shape(myOH_33kV)+tm_lines(col='purple',lwd=4) +
# tm_shape(myUG_33kV)+tm_lines(col='pink',lwd=4) +
# 
# tm_shape(myOH_11kV)+tm_lines(col='black',lwd=2) +
# tm_shape(myUG_11kV)+tm_lines(col='brown',lwd=2) +
#   
# tm_shape(readZoneSub)+tm_dots(size=0.1)

Get LV & substations - but best if just display for an LGA + buffer

similar for substations, pillars & poles

say do Noosa LGA, Sunshine Coast & Gympie first……

# myLGA <- readRDS(file=paste0(maps_folder,"Queensland_LGA_map.rds"))
# 
# #myLGA <- readRDS(file=paste0(maps_folder,"Queensland_LGA_map.rds"))
# # just get Gympie=3620, Noosa=5740 & Sunshine Coast=6720
# JustNoosaLGA <- myLGA %>% filter(LGA_CODE == '5740')
# # NoosaLGA <- myLGA %>% filter(LGA_CODE %in% c('3620','5740','6720'))
# 
# # create a bounding box around a 10km buffer around Noosa LGA
# bbNoosaLGA <- st_bbox(st_buffer(JustNoosaLGA, 10000))
# mygeometry = toString(bbNoosaLGA)

# OH_LV_query = "12"
myOH_LV <- get_Energex_map(OH_LV_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/12/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 1427 features and 8 fields
## Geometry type: MULTILINESTRING
## Dimension:     XY
## Bounding box:  xmin: 152.7429 ymin: -26.51472 xmax: 153.1136 ymax: -26.12227
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_OH_LV_Noosa.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myOH_LV, shp_filename)
## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Writing layer `Energex_OH_LV_Noosa' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_OH_LV_Noosa.shp' using driver `ESRI Shapefile'
## Writing 1427 features with 8 fields and geometry type Multi Line String.
# UG_LV_query = "13"
myUG_LV <- get_Energex_map(UG_LV_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/13/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 1006 features and 8 fields
## Geometry type: MULTILINESTRING
## Dimension:     XY
## Bounding box:  xmin: 152.7254 ymin: -26.98637 xmax: 153.1341 ymax: -25.94297
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_UG_LV_Noosa.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myUG_LV, shp_filename)
## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Writing layer `Energex_UG_LV_Noosa' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_UG_LV_Noosa.shp' using driver `ESRI Shapefile'
## Writing 1006 features with 8 fields and geometry type Multi Line String.
# Substations_query = "1"
mySubstations <- get_Energex_map(Substations_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/1/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 2534 features and 11 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: 152.7519 ymin: -26.5109 xmax: 153.1133 ymax: -26.1256
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_Substations_Noosa.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(mySubstations, shp_filename)
## Writing layer `Energex_Substations_Noosa' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_Substations_Noosa.shp' using driver `ESRI Shapefile'
## Writing 2534 features with 11 fields and geometry type Point.

Now Poles & Pillars

# Poles_query = "2"
myPoles <- get_Energex_map(Poles_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/2/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 24154 features and 7 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: 152.7515 ymin: -26.51113 xmax: 153.1136 ymax: -26.12542
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_Poles_Noosa.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myPoles, shp_filename)
## Writing layer `Energex_Poles_Noosa' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_Poles_Noosa.shp' using driver `ESRI Shapefile'
## Writing 24154 features with 7 fields and geometry type Point.
# Pillars_query = "3"
myPillars <- get_Energex_map(Pillars_query, "1 = 1",mygeometry)
## Reading layer `OGRGeoJSON' from data source 
##   `https://services.arcgis.com/bfVzktoY0OhzQCDj/ArcGIS/rest/services/Network_Energex/FeatureServer/3/query?where=1%20%3D%201&geometry=152.751494855992%2C%20-26.5111382451014%2C%20153.132524288454%2C%20-26.1253462960282&outfields=%2A&returnGeometry=true&f=geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 8879 features and 7 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: 152.7649 ymin: -26.51108 xmax: 153.1137 ymax: -26.1488
## Geodetic CRS:  WGS 84
shp_filename = paste(maps_folder,"Energex_Pillars_Noosa.shp",sep = "")
if(file.exists(shp_filename)) {
    file.remove(shp_filename)
}
## [1] TRUE
st_write(myPillars, shp_filename)
## Writing layer `Energex_Pillars_Noosa' to data source 
##   `/Users/geremida/Dropbox/ZENE/R/EQld_NetworkMaps/Energex_maps/Energex_Pillars_Noosa.shp' using driver `ESRI Shapefile'
## Writing 8879 features with 7 fields and geometry type Point.

ok now display them

but best to use just 11kV???? -> LV???? feeders within “mygeometry”

LOOKS LIKE FOLLOWING CODE IS REDUNDANT - ERROR IN COMMENT ABOVE…..

# my_filtered_list <- st_intersects(myOH_LV, st_buffer(JustNoosaLGA, 10000),sparse = FALSE)
# Noosa_myOH_LV <- myOH_LV[my_filtered_list, ]
# 
# my_filtered_list <- st_intersects(myUG_LV, st_buffer(JustNoosaLGA, 10000),sparse = FALSE)
# Noosa_myUG_LV <- myUG_LV[my_filtered_list, ]

display the map

tm_shape(JustNoosaLGA) + tm_polygons(col = "MAP_COLORS", alpha = 0.2, border.col = "darkmagenta") +
tm_shape(myOH_132kV)+tm_lines(col='red', lwd=12) +
# tm_shape(myUG_132kV)+tm_lines(col='orange',lwd=10)+   nothing to display !

# - don't display as none for Noosa LGA  
# tm_shape(myOH_110kV)+tm_lines(col='blue',lwd=10)+
# tm_shape(myUG_110kV)+tm_lines(col='green',lwd=10) +

tm_shape(myOH_33kV)+tm_lines(col='purple',lwd=8) +
tm_shape(myUG_33kV)+tm_lines(col='pink',lwd=8) +

tm_shape(myOH_11kV)+tm_lines(col='black',lwd=4) +
tm_shape(myUG_11kV)+tm_lines(col='brown',lwd=4) +
  
tm_shape(myZoneSub)+tm_dots(size=0.1) +
  
# tm_shape(Noosa_myOH_LV)+tm_lines(col='red',lwd=2) +
# tm_shape(Noosa_myUG_LV)+tm_lines(col='orange',lwd=2) +
tm_shape(myOH_LV)+tm_lines(col='red',lwd=2) +
tm_shape(myUG_LV)+tm_lines(col='orange',lwd=2) +
tm_shape(mySubstations)+tm_dots(size=0.04)
# leave out as got error displaying - just temporary :-)
#+
# tm_shape(myPillars) +tm_dots(size=0,06, col = 'pink')