Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/engine/command-surface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ raster.rotation layer? angle
raster.setDefaultStyle fromLayer? layer? ramp? invert? stretch? low? high? n? resampling? reset?
raster.spectral layer lon? lat? points? zone?
raster.stretch layer? type low? high? n? min? max? like?
raster.symbology layer? type band? ramp? invert? classes? method? azimuth? altitude? zFactor? shadow? sky? fill? ambient? balanced? shadowSoftness? aerial? terrain? rock? grey?
raster.symbology layer? type band? ramp? invert? classes? method? azimuth? altitude? zFactor? shadow? sky? fill? ambient? balanced? shadowSoftness? aerial? terrain? flats? rock? grey?
raster.zarrInfo path url bbox? variable?
report.activate report
report.attachments report? field
Expand Down
33 changes: 30 additions & 3 deletions crates/engine/src/cmd/raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::Arc;
use rustgis_data::raster::{self, Raster};
use rustgis_geom::Extent;
use rustgis_map::raster::{
Normalizer, RasterLayer, RasterMask, RasterRenderer, RasterStyle, Resampling, Rock, Stretch, classify_masked, unique_values,
Flats, Normalizer, RasterLayer, RasterMask, RasterRenderer, RasterStyle, Resampling, Rock, Stretch, classify_masked, unique_values,
};
use rustgis_map::{ClassMethod, Ramp, RasterDefaults};
use serde_json::{Value, json};
Expand Down Expand Up @@ -39,7 +39,7 @@ pub fn commands() -> Vec<C> {
C::new("layer.addDataBytes", "Add Data (from file contents)", "Home › Add", add_bytes::<MAX_UPLOAD_BYTES>).roles(&[]).effects(crate::policy::Effects::NONE)
.params(r#"{"fileName": "name.tif|.tiff|.asc|.grb|.grib|.grb2|.grib2 (GRIB)|.hgt|.dt0|.dt1|.dt2|.geojson|.csv|.zip|.kml|.kmz|.gpx|.parquet|.fgb|.gpkg|.mbtiles|.jp2|.j2k|.dxf|.pdf (JPEG 2000: desktop, through GDAL; PDF: desktop, command line and Python)", "data": base64, "zoom"?: bool, "layer"?: "one layer of a zip, KML or GPX by name, or a PDF's page number (the first when left out or blank)", "name"?: text, "x"?, "y"?, "wkt"?, "crs"?, "delimiter"?, "paperSpace"?, "blocks"?, "stream"?, "as"? (as layer.addData)}"#),
C::new("raster.symbology", "Symbology", "Style › Rendering", symbology).when(need_raster).roles(&[]).effects(crate::policy::Effects::NONE).params(
r#"{"layer"?, "type": "stretch"|"rgb"|"classify"|"unique"|"colormap"|"shadedRelief", "band"?: 1.., "ramp"?, "invert"?: bool, "classes"?: 1..32, "method"?, "azimuth"?, "altitude"?, "zFactor"?, "shadow"?: 0..1 (shadedRelief: how dark the shadows the terrain casts are; left out, kept; 0 casts none), "sky"?: 0..1 (shadedRelief: how much the share of the sky each cell sees dims its ambient light; left out, kept; 0 leaves it whole), "fill"?: 0..1 (shadedRelief: a fill light from the side opposite the sun that lightens the slopes turned toward it; left out, kept; 0 has none), "ambient"?: 0..1|null (shadedRelief: the share of the colour a slope turned fully from the sun keeps; left out, kept; null, the default: 0.25, or 0.5 balanced), "balanced"?: bool (shadedRelief: flat ground keeps the ramp's colour and slopes facing the sun brighten, up to 1.3; left out, kept; false, the default, lights as before), "shadowSoftness"?: 0.5..15|null (shadedRelief: how soft the edges of its cast shadows are, as half the sun's apparent size in degrees; left out, kept; outside 0.5 to 15, refused; null, the default: 5), "aerial"?: 0..1|null (shadedRelief: aerial perspective, low ground on the layer's stretch lit with less contrast and hazed toward #ECECEC, the more the lower; left out, kept; outside 0 to 1, refused; null or 0, the default: none), "terrain"?: -1..1|null (shadedRelief: terrain type, each cell's gradient g reshaped for the sun's light only as tan 30° × (g / tan 30°)^(1 − 0.5 × terrain), steepened at most 8 times: above 0 gentle relief shows, below 0 steep ground stands out; cast shadows, sky, fill light and rock keep the ground's slope; left out, kept; outside -1 to 1, refused; null or 0, the default: lit as before), "rock"?: {"from"?: 0..90, "to"?: 0..90, "color"?: #RRGGBB} | false (shadedRelief: steep slopes tinted toward a rock colour before the light, from the ground's own slope in degrees, without the Z factor: the ramp below from, the colour above to, blended between; left out, kept; an object's missing keys keep the current rock's, or 25, 40 and #B2ACA4; false or null removes it), "grey"?: bool (shadedRelief without its colour ramp)}"#,
r#"{"layer"?, "type": "stretch"|"rgb"|"classify"|"unique"|"colormap"|"shadedRelief", "band"?: 1.., "ramp"?, "invert"?: bool, "classes"?: 1..32, "method"?, "azimuth"?, "altitude"?, "zFactor"?, "shadow"?: 0..1 (shadedRelief: how dark the shadows the terrain casts are; left out, kept; 0 casts none), "sky"?: 0..1 (shadedRelief: how much the share of the sky each cell sees dims its ambient light; left out, kept; 0 leaves it whole), "fill"?: 0..1 (shadedRelief: a fill light from the side opposite the sun that lightens the slopes turned toward it; left out, kept; 0 has none), "ambient"?: 0..1|null (shadedRelief: the share of the colour a slope turned fully from the sun keeps; left out, kept; null, the default: 0.25, or 0.5 balanced), "balanced"?: bool (shadedRelief: flat ground keeps the ramp's colour and slopes facing the sun brighten, up to 1.3; left out, kept; false, the default, lights as before), "shadowSoftness"?: 0.5..15|null (shadedRelief: how soft the edges of its cast shadows are, as half the sun's apparent size in degrees; left out, kept; outside 0.5 to 15, refused; null, the default: 5), "aerial"?: 0..1|null (shadedRelief: aerial perspective, low ground on the layer's stretch lit with less contrast and hazed toward #ECECEC, the more the lower; left out, kept; outside 0 to 1, refused; null or 0, the default: none), "terrain"?: -1..1|null (shadedRelief: terrain type, each cell's gradient g reshaped for the sun's light only as tan 30° × (g / tan 30°)^(1 − 0.5 × terrain), steepened at most 8 times: above 0 gentle relief shows, below 0 steep ground stands out; cast shadows, sky, fill light and rock keep the ground's slope; left out, kept; outside -1 to 1, refused; null or 0, the default: lit as before), "flats"?: {"amount"?: 0..1, "size"?: 1..32} | false (shadedRelief: flat ground's detail, each cell's direct light moved by its height above the mean within size cells around it, 40 per unit of height (a metre on most DEMs) within 80, times amount, fading out by 4° of slope; best on a terrain model, as a surface model's trees and roads show too; left out, kept; an object's missing keys keep the current one's, or 1 and 6; amount 0, false or null: none, the default; outside, refused), "rock"?: {"from"?: 0..90, "to"?: 0..90, "color"?: #RRGGBB} | false (shadedRelief: steep slopes tinted toward a rock colour before the light, from the ground's own slope in degrees, without the Z factor: the ramp below from, the colour above to, blended between; left out, kept; an object's missing keys keep the current rock's, or 25, 40 and #B2ACA4; false or null removes it), "grey"?: bool (shadedRelief without its colour ramp)}"#,
),
C::new("raster.stretch", "Stretch Type", "Style › Rendering", stretch).inputs(stretch_inputs).roles(&[]).effects(crate::policy::Effects::NONE)
.when(need_raster)
Expand Down Expand Up @@ -1085,7 +1085,10 @@ fn symbology(s: &mut Session, p: &Value) -> CmdResult {
Some(Value::Null) => 0.0,
Some(_) => relief_terrain_type(f(p, "terrain"))?,
},
flats: cur_flats,
flats: match p.get("flats") {
None => cur_flats,
Some(v) => relief_flats(v, cur_flats)?,
},
}
}
other => return Err(format!("unknown raster symbology '{other}'")),
Expand Down Expand Up @@ -1182,6 +1185,30 @@ fn relief_terrain_type(v: Option<f64>) -> Result<f64, String> {
}
}

/// The detail on flat ground of a Shaded Relief's `"flats"` (see `raster.symbology`): `false` or
/// null for none, or an object whose missing keys keep `cur`'s, or else [`Flats::DEFAULT`]'s,
/// read as other keys are (a numeric string is its number). An amount of 0 is none; an amount
/// outside 0 to 1, or a size that isn't a whole number of cells from 1 to [`Flats::MAX_SIZE`], is
/// refused by name.
pub(crate) fn relief_flats(v: &Value, cur: Option<Flats>) -> Result<Option<Flats>, String> {
if v.is_null() || *v == Value::Bool(false) {
return Ok(None);
}
let max = Flats::MAX_SIZE;
let refused = || format!("\"flats\" must be {{\"amount\": 0 to 1, \"size\": 1 to {max} cells}}, or false for none");
if !v.is_object() {
return Err(refused());
}
let was = cur.unwrap_or(Flats::DEFAULT);
let given = |k: &str| v.get(k).filter(|x| !x.is_null()).map(|_| f(v, k).ok_or_else(refused)).transpose();
let amount = given("amount")?.unwrap_or(was.amount);
let size = given("size")?.unwrap_or(f64::from(was.size));
if !(0.0..=1.0).contains(&amount) || size.fract() != 0.0 || !(1.0..=f64::from(max)).contains(&size) {
return Err(refused());
}
Ok((amount > 0.0).then_some(Flats { amount, size: size as u32 }))
}

/// The rock of a Shaded Relief's `"rock"` (see `raster.symbology`): `false` or null for none, or
/// an object whose missing keys keep `cur`'s, or else [`Rock::DEFAULT`]'s.
fn relief_rock(v: &Value, cur: Option<Rock>) -> Result<Option<Rock>, String> {
Expand Down
36 changes: 36 additions & 0 deletions crates/engine/src/project_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,25 @@ const COMMAND_CAPABILITIES: &[(&str, CommandCheck)] = &[
("shaded-relief-shadow-softness", command_sets_shadow_softness),
("shaded-relief-aerial", command_sets_aerial),
("shaded-relief-terrain-type", command_sets_terrain_type),
("shaded-relief-flats", command_sets_flats),
];

/// A saved `raster.symbology` that sets a Shaded Relief's detail on flat ground (#3143): an older
/// reader runs it without the key, saying nothing, so flat ground would be drawn even. Read as the
/// command reads it, with its parser (an object's missing amount is the default's, 1): `false`,
/// `null` and an amount of 0 ask for none, and another renderer reads no flats. The current
/// setting isn't known here, so an object is read against none.
fn command_sets_flats(id: &str, params: &Value) -> bool {
match id {
"raster.symbology" => {
crate::cmd::raster::symbology_is_relief(params)
&& params.get("flats").is_some_and(|v| matches!(crate::cmd::raster::relief_flats(v, None), Ok(Some(_))))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
"script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_sets_flats)),
_ => false,
}
}

/// A saved `layout.publication` that leaves out or sets up its grid, scale bar or north arrow
/// (#3094): an older reader ignores `grid` and `scaleBar`, making the default sheet, and refuses
/// any `northArrow` object. `null`, and a grid or scale bar object giving nothing, ask for the
Expand Down Expand Up @@ -1777,6 +1794,18 @@ mod tests {
// Read as the command reads it: a numeric string is its number, so "0" is none too.
(&[], "raster.symbology", json!({"type": "shadedRelief", "aerial": "0"})),
(&["shaded-relief-aerial"], "raster.symbology", json!({"type": "shadedRelief", "aerial": "0.5"})),
// Flat ground's detail, read with the command's parser: an object's missing amount is
// the default's; false, null and an amount of 0 are the none an older reader draws, and
// a refused one is never saved.
(&["shaded-relief-flats"], "raster.symbology", json!({"type": "shadedRelief", "flats": {"amount": 0.5, "size": 4}})),
(&["shaded-relief-flats"], "raster.symbology", json!({"type": "shadedRelief", "flats": {}})),
(&["shaded-relief-flats"], "raster.symbology", json!({"type": "hillshade", "flats": {"amount": "0.5"}})),
(&[], "raster.symbology", json!({"type": "shadedRelief", "flats": {"amount": 0}})),
(&[], "raster.symbology", json!({"type": "shadedRelief", "flats": {"amount": "0"}})),
(&[], "raster.symbology", json!({"type": "shadedRelief", "flats": false})),
(&[], "raster.symbology", json!({"type": "shadedRelief", "flats": null})),
(&[], "raster.symbology", json!({"type": "shadedRelief", "flats": {"amount": 2}})),
(&[], "raster.symbology", json!({"type": "stretch", "flats": {"amount": 0.5}})),
// Only a Shaded Relief draws them, its type read as the command reads it: left out, the
// command draws a stretch, which an older reader draws the same.
(&[], "raster.symbology", json!({"type": "stretch", "aerial": 0.6, "shadowSoftness": 1.5})),
Expand Down Expand Up @@ -1829,6 +1858,13 @@ mod tests {
let script = format!(r#"raster.symbology {{"type": "{kind}", "terrain": "{terrain}"}}"#);
assert_eq!(command_sets_terrain_type("script.run", &json!({ "script": script })), needs, "{kind} {terrain}");
}
for (value, needs) in [(r#"{"amount": "0"}"#, false), (r#"{"amount": "0.5"}"#, true)] {
for kind in ["shadedRelief", "stretch"] {
let (key, uses) = ("flats", command_sets_flats);
let script = format!(r#"raster.symbology {{"type": "{kind}", "{key}": {value}}}"#);
assert_eq!(uses("script.run", &json!({ "script": script })), needs && kind == "shadedRelief", "{kind} {key} {value}");
}
}
}

/// `report.existingTemplate` imports a layout file as `layout.import` does, so a step of it
Expand Down
Loading
Loading