Skip to content

Commit 4beb9a4

Browse files
author
Jon Vegard Venås
committed
Enable custom boundary background map instead of the default coastlines (through a .geojson file location provided by the keyword argument map_boundary_file in the GUI-function).
1 parent ce9e1c1 commit 4beb9a4

2 files changed

Lines changed: 32 additions & 21 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Enhancements
1010

1111
* Enabled exporting topo axis to bmp, tif, tiff, jpg, jpeg, and png file format.
12+
* Enable custom boundary background map instead of the default coastlines (through a `.geojson` file location provided by the keyword argument `map_boundary_file` in the `GUI`-function).
1213

1314
### Adjustments
1415

src/setup_GUI.jl

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ to the old EnergyModelsX `case` dictionary.
5151
(instead of multiple lines for multiple transmission modes) in the topology design.
5252
- **`simplify_all_levels::Bool=false`** toggles whether or not to use simplified connection
5353
plotting for all hierarchical levels.
54+
- **`map_boundary_file::String=""`** is the path to a .geojson file containing
55+
geographical boundary data for plotting to be used instead of the default coastlines.
5456
5557
!!! warning "Reading model results from CSV-files"
5658
Reading model results from a directory (*i.e.*, `model::String` implying that the results
@@ -84,6 +86,7 @@ function GUI(
8486
pre_plot_sub_components::Bool = true,
8587
simplified_connection_plotting::Bool = false,
8688
simplify_all_levels::Bool = false,
89+
map_boundary_file::String = "",
8790
)
8891
# Generate the system topology:
8992
@info raw"Setting up the topology design structure"
@@ -130,6 +133,7 @@ function GUI(
130133
:simplified_connection_plotting => simplified_connection_plotting,
131134
:simplify_all_levels => simplify_all_levels,
132135
:marker_to_box_ratio => 0.4, # Ratio between marker size and `Node` box size
136+
:map_boundary_file => map_boundary_file,
133137
:autolimits => Dict(
134138
:results_op => true,
135139
:results_sc => true,
@@ -325,28 +329,34 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
325329
alignmode = Inside(),
326330
)
327331

328-
if vars[:coarse_coast_lines] # Use low resolution coast lines
329-
countries = GeoMakie.land()
330-
else # Use high resolution coast lines
331-
# Define the URL and the local file path
332-
resolution::String = "10m" # "10m", "50m", "110m"
333-
url::String = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_$(resolution)_land.geojson"
334-
temp_dir::String = tempdir() # Get the system's temporary directory
335-
filename_countries::String = "EnergyModelsGUI_countries.geojson"
336-
local_file_path::String = joinpath(temp_dir, filename_countries)
337-
338-
# Download the file if it doesn't exist in the temporary directory
339-
if !isfile(local_file_path)
340-
HTTP.download(url, local_file_path)
332+
if isempty(vars[:map_boundary_file])
333+
# Plot coast lines
334+
if vars[:coarse_coast_lines] # Use low resolution coast lines
335+
boundary = GeoMakie.land()
336+
else # Use high resolution coast lines
337+
# Define the URL and the local file path
338+
resolution::String = "10m" # "10m", "50m", "110m"
339+
url::String = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_$(resolution)_land.geojson"
340+
temp_dir::String = tempdir() # Get the system's temporary directory
341+
filename_countries::String = "EnergyModelsGUI_countries.geojson"
342+
local_file_path::String = joinpath(temp_dir, filename_countries)
343+
344+
# Download the file if it doesn't exist in the temporary directory
345+
if !isfile(local_file_path)
346+
HTTP.download(url, local_file_path)
347+
end
348+
349+
# Now read the data from the file
350+
boundary_geo_json = GeoJSON.read(read(local_file_path, String))
351+
352+
# Create GeoMakie plotable object
353+
boundary = GeoMakie.to_multipoly(boundary_geo_json.geometry)
341354
end
342-
343-
# Now read the data from the file
344-
countries_geo_json = GeoJSON.read(read(local_file_path, String))
345-
346-
# Create GeoMakie plotable object
347-
countries = GeoMakie.to_multipoly(countries_geo_json.geometry)
355+
else
356+
boundary_geo_json = GeoJSON.read(read(vars[:map_boundary_file], String))
357+
boundary = GeoMakie.to_multipoly(boundary_geo_json.geometry)
348358
end
349-
countries_plot = poly!(
359+
poly!(
350360
ax,
351361
countries;
352362
color = :honeydew,
@@ -358,7 +368,7 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
358368
stroke_depth_shift = 1.0f0 - 3.0f-5,
359369
)
360370
ocean_coords = [(180, -90), (-180, -90), (-180, 90), (180, 90)]
361-
ocean = poly!(
371+
poly!(
362372
ax,
363373
ocean_coords,
364374
color = :lightblue1,

0 commit comments

Comments
 (0)