Skip to content

Commit

Permalink
Update to activate NDVI functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
StevePem committed Feb 21, 2024
1 parent be5a02b commit cf619d7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
12 changes: 6 additions & 6 deletions NetworkGenerator.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ makeNetwork<-function(city, outputSubdirectory = "generated_network"){
# (only supported for Victoria at this stage)
# • demFile: if 'addElevation=T', digital elevation model raster file (must be
# in same coordinate system as network)
# • ndviFile: if 'addNDVI=T', raster file with NDVI values (must be in same
# coordinate system as network)
# • ndviFile: if 'addNDVI=T', raster file with NDVI values
# • gtfs_feed: if 'addGtfs=T' or 'addDestinationLayer=T, zip file containing
# GTFS data (and, if 'addGtfs=T', also set start and end dates in GTFS section)

Expand All @@ -33,7 +32,7 @@ makeNetwork<-function(city, outputSubdirectory = "generated_network"){
unconfiguredSqlite = "./output/bendigo_network_unconfigured.sqlite"
cropAreaPoly = "" # must set 'crop2Area=F'
demFile = "./data/dem_bendigo.tif"
# ndviFile = "" # must set 'addNDVI=F'
ndviFile = "./data/NDVI_Bendigo_2023.tif"
gtfs_feed = "./data/gtfs.zip"

} else if (city == "Melbourne") {
Expand All @@ -43,7 +42,7 @@ makeNetwork<-function(city, outputSubdirectory = "generated_network"){
unconfiguredSqlite = "./output/melbourne_network_unconfigured.sqlite"
cropAreaPoly = "city-of-melbourne_victoria"
demFile = "./data/dem_melbourne.tif"
# ndviFile = "./data/NDVI_1600mBuffer_Melbourne_reprojected.tif"
ndviFile = "./data/NDVI_Melbourne_2023.tif"
gtfs_feed = "./data/gtfs.zip"

} else {
Expand Down Expand Up @@ -92,7 +91,7 @@ makeNetwork<-function(city, outputSubdirectory = "generated_network"){

# NDVI
# A flag for whether to add NDVI or not
addNDVI=F
addNDVI=T
# Buffer distance for finding average NDVI for links
ndviBuffDist=30

Expand Down Expand Up @@ -284,7 +283,8 @@ makeNetwork<-function(city, outputSubdirectory = "generated_network"){
if(addNDVI) {
system.time(networkDensified[[2]] <- addNDVI2Links(networkDensified[[2]],
ndviFile,
ndviBuffDist))
ndviBuffDist,
outputCrs))
}

# adding destinations layer
Expand Down
6 changes: 4 additions & 2 deletions data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Download the following files for the relevant network location.
|--------------------------|---------------------------------------------------|
| greater_bendigo.sqlite | Boundary of the Greater Bendigo Local Government Area |
| dem_bendigo.tif | Digital elevation model data for the Greater Bendigo area |
| [to come] | [NDVI] data for the Greater Bendigo area |
| NDVI_Bendigo_2023.tif | NDVI data for the Greater Bendigo area |
| gtfs.zip | GTFS feed for Victoria as at 20 October 2023 |


Expand All @@ -20,7 +20,7 @@ Download the following files for the relevant network location.
|--------------------------|---------------------------------------------------|
| greater_melbourne.sqlite | Boundary of the Greater Melbourne Greater Capital City Statistical Area |
| dem_melbourne.tif | Digital elevation model data for the Greater Melbourne area |
| [to come] | [NDVI] data for the Greater Melbourne area |
| NDVI_Melbourne_2023.tif | NDVI data for the Greater Melbourne area |
| gtfs.zip | GTFS feed for Victoria as at 20 October 2023 |


Expand All @@ -38,3 +38,5 @@ The file `data/data prep tools.R` contains:
* the script used to extract the region boundary files from the LGA and GCCSA files above, and
* the script used to crop the digital elevation files from a DEM file for the whole of Victoria (available for download from https://discover.data.vic.gov.au/dataset/vicmap-elevation-dem-10m, 9.3 GB).
Those scripts may also be useful to generate similar data input files for other locations if required.

The NDVI files were created from Sentinel 2 data using Google Earth Engine at https://code.earthengine.google.com/.
11 changes: 6 additions & 5 deletions functions/addNDVI.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# function to add NDVI to links, where NDVI is the average of the NDVI
# values within a 30m buffer of the links

addNDVI2Links <- function(links, ndviFile, ndviBuffDist) {
addNDVI2Links <- function(links, ndviFile, ndviBuffDist, outputCrs) {

# links = networkDensified[[2]]
# ndviFile = "./data/NDVI_1600mBuffer_Melbourne_reprojected.tif"
# ndviFile = "./data/NDVI_Bendigo_2023.tif"
# ndviBuffDist = 30

echo("Reading in the NDVI file\n")
echo("Reading in the NDVI file and reprojecting if necessary\n")

# read in NDVI file
# read in NDVI file, and convert to outputCrs if necessary
ndvi <- rast(ndviFile)

if (!same.crs(ndvi, outputCrs)) ndvi <- project(ndvi, outputCrs)

# buffer each link
links.buffered <- st_buffer(links, 30)

Expand Down

0 comments on commit cf619d7

Please sign in to comment.