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
13 changes: 13 additions & 0 deletions apps/rustgis-python/python/rustgis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,19 @@ def set_transparency(self, value: float) -> "Layer":
self.session.run("layer.transparency", layer=self.id, value=value)
return self

def set_credit(self, credit: Optional[str]) -> "Layer":
"""Sets who the layer's data is from, shown in the map's credits and map exports.

Args:
credit: Text of at most 500 characters; ``""`` for none; None for what the file
says (a GeoTIFF's copyright).

Returns:
The layer.
"""
self.session.run("layer.credit", layer=self.id, credit=credit)
return self

def filter(self, where: Optional[str]) -> "Layer":
"""Shows only the features matching a SQL where clause (a definition query).

Expand Down
4 changes: 2 additions & 2 deletions crates/data/src/loss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ loss_codes! {
DroppedCopyright => (
"dropped.copyright",
Dropped,
"Copyright text could not be read or written in a raster's tag, or differs from the first input's and was not kept in the mosaic.",
"Keep the source credits and include the required attribution when sharing the raster."
"Copyright text could not be read or written in a raster's tag, or differs from the first input's and was not kept in the mosaic, or a credit was left out of a map's credit line.",
"Keep the source credits and include the required attribution when sharing the raster or map; shorten long layer credits (`layer.credit`) so the credit line holds them all."
),
DroppedValue => (
"dropped.value",
Expand Down
1 change: 1 addition & 0 deletions crates/engine/command-surface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ layer.clearDiagram layer?
layer.color layer? color
layer.copy layer? group?
layer.copyPath layer?
layer.credit layer? credit
layer.defineProjection layer? crs
layer.definitionQuery layer? where
layer.diagram layer? kind fields size? startAngle? labels? background? outline?
Expand Down
23 changes: 23 additions & 0 deletions crates/engine/src/cmd/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,27 @@ pub fn commands() -> Vec<C> {
}).roles(&[]).effects(crate::policy::Effects::NONE)
.when(need_layer)
.params(r#"{"layer"?, "value": 0..100}"#),
C::new("layer.credit", "Credit", "Layer Properties › Source", |s, p| {
let credit = match p.get("credit") {
None => return Err("credit is required: text, \"\" for none, or null for what the file says".into()),
Some(Value::Null) => None,
Some(Value::String(t)) => {
let t = t.trim();
let n = t.chars().count();
if n > rustgis_map::MAX_CREDIT {
return Err(format!("credit is {n} characters; a layer's credit is at most {}", rustgis_map::MAX_CREDIT));
}
Some(t.to_string())
}
Some(_) => return Err("credit is text, \"\" for none, or null for what the file says".into()),
};
let id = s.layer_id(p)?;
let l = s.map_mut().layer_mut(id).ok_or("no such layer")?;
l.credit = credit;
Ok(json!({"credit": l.credit_shown()}))
}).roles(&[]).effects(crate::policy::Effects::NONE)
.when(need_layer)
.params(r#"{"layer"?, "credit": text (at most 500 characters: who the data is from, shown in the map's credit line, map exports and layout map frames) | "" (none) | null (what the file says, such as a GeoTIFF's copyright)} → the credit the layer now shows"#),
C::new("layer.scaleRange", "Visibility Range", "Style › Visibility Range", |s, p| {
let min = f(p, "min").filter(|v| *v > 0.0);
let max = f(p, "max").filter(|v| *v > 0.0);
Expand Down Expand Up @@ -7165,6 +7186,8 @@ pub(crate) fn read_window_raster(asked: &WindowAsked, stop: &std::sync::atomic::
.map_err(|e| named(e.to_string()))?;
r.white_is_zero = layout.white_is_zero;
r.sample_bits = layout.sample_bits;
// Its credit, as when the file is read whole.
r.copyright.clone_from(&layout.copyright);
if rounded.iter().any(|n| *n > 0) {
r.rounded = rounded;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/cmd/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ fn export_within(s: &mut Session, i: usize, format: &str, dpi: f64, out: super::
}))
};
let before = revision(s);
// The frames whose tile credits the pages cut off, each named by its page ([`page_credited`]).
// The frames whose credits the pages cut off, each named by its page ([`page_credited`]).
let mut credits = Vec::new();
let result = super::share::saying_shadows(s, "The presentation", |s| export_bytes_inner(s, i, format, dpi, out, &mut credits));
let (bytes, pages) = before.finish_revision(revision(s), Some(result), "could not draw the presentation")??;
Expand All @@ -542,7 +542,7 @@ fn export_within(s: &mut Session, i: usize, format: &str, dpi: f64, out: super::
Ok((bytes, pages))
}

/// `f`, drawing page `k` of presentation `i`, and the map frames of it whose tile credits were cut
/// `f`, drawing page `k` of presentation `i`, and the map frames of it whose credits were cut
/// off, added to `kept` named by their page: each page is a layout of its own, its elements
/// numbered from 1 and its name its title, which two pages can share, so only the page's number
/// tells the frames apart. A page drawn twice (a vector page too large, redrawn as a picture) is
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/cmd/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ fn say_report_pictures(s: &mut Session, pages: &[rustgis_render::report::Page],
}

/// What a page drew that its report says: legends under a fit still cut, charts, and map frames
/// whose tile credits are cut off.
/// whose credits are cut off.
struct Listed {
legends: Vec<rustgis_render::layout::UnfittedLegend>,
charts: Vec<rustgis_render::layout::DrawnChart>,
Expand Down Expand Up @@ -1555,7 +1555,7 @@ fn say_report_charts(s: &mut Session, kept: &[(usize, rustgis_render::layout::Dr
}
}

/// Says the map frames whose tile credits [`keep_drawn`] kept as cut off, each named with its
/// Says the map frames whose credits [`keep_drawn`] kept as cut off, each named with its
/// layout, as a layout's export says its own: one notice however many layouts have one.
fn say_report_credits(s: &mut Session, kept: &[(usize, rustgis_render::layout::CutCredit)]) {
let found: Vec<_> = kept.iter().map(|(_, c)| c.clone()).collect();
Expand Down
10 changes: 7 additions & 3 deletions crates/engine/src/cmd/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,6 @@ pub(crate) fn cog_tiles_to_rasters(m: &mut rustgis_map::Map) {
// `Session::notice_landed_rasters`).
let plain = rustgis_map::TileLayer::new(&t.name, TileKind::Cog, file);
let mut dropped = Vec::new();
if !t.attribution.trim().is_empty() {
dropped.push("attribution");
}
if !t.legends.is_empty() {
dropped.push("legend");
}
Expand Down Expand Up @@ -788,6 +785,13 @@ pub(crate) fn cog_tiles_to_rasters(m: &mut rustgis_map::Map) {
// anonymous plugin command added takes no saved login, as before.
l.connection = t.connection.clone();
l.anonymous = t.anonymous;
// Its credit, the layer's own and whole: it stands in for the file's. A layer keeps a
// credit of any length it is given by a file, as a project keeps a hand-edited one; one
// too long for the credit line is left out of it and said there.
let credit = t.attribution.trim();
if !credit.is_empty() {
l.credit = Some(credit.to_string());
}
}
// Just over the layer it was drawn over, in its group; under them all without one.
let group = t.over.and_then(|o| m.group_of(o).map(|g| g.id));
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub const CAPABILITIES: &[&str] = &[
"svg-markers",
"label-duplicates",
"layer-raster-mask",
"layer-credit",
"unique-keep-order",
"tile-resampling",
"layout-page-color",
Expand Down
20 changes: 19 additions & 1 deletion crates/engine/src/project_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ fn merge_opened(required: &mut Vec<&'static str>, opened: RefCell<Vec<&'static s
type CommandCheck = fn(&str, &Value) -> bool;
const COMMAND_CAPABILITIES: &[(&str, CommandCheck)] = &[
("slope-percent", command_uses_percent_slope),
("layer-credit", command_sets_layer_credit),
("tabulate-intersection-unit", command_uses_tabulate_unit),
("tabulate-intersection-empty-zones", command_uses_tabulate_empty_zones),
("layout-element-background", command_uses_element_background),
Expand Down Expand Up @@ -619,6 +620,16 @@ fn command_sets_generalize(id: &str, params: &Value) -> bool {
}
}

/// A saved `layer.credit` step, whatever it sets (text, none or the file's): an older reader has no
/// such command, so the step would fail where it runs.
fn command_sets_layer_credit(id: &str, params: &Value) -> bool {
match id {
"layer.credit" => true,
"script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_sets_layer_credit)),
_ => false,
}
}

/// A saved `layer.mask` that masks by a raster's values (#3147): an older reader refuses the
/// object, so the step fails where it would mask.
fn command_masks_by_raster(id: &str, params: &Value) -> bool {
Expand Down Expand Up @@ -1972,6 +1983,8 @@ fn layer_capabilities(layer: &Layer) -> Vec<&'static str> {
(zarr_window(layer), "zarr-window"),
// Masked by a raster's values (#3147): an older reader would draw it whole and save it so.
(layer.raster_mask.is_some(), "layer-raster-mask"),
// A credit of its own: an older reader would show the file's, or none, and save it so.
(layer.credit.is_some(), "layer-credit"),
(keeps_class_order(&layer.renderer), UNIQUE_KEEP_ORDER),
(label_guide(layer), "label-guide"),
(label_weight(layer), "label-weight"),
Expand Down Expand Up @@ -2004,7 +2017,7 @@ fn map_capabilities<'a>(maps: impl IntoIterator<Item = &'a Map>) -> Vec<&'static
mut on_top,
mut grid_color,
) = (false, false, false, false, false, false, false, false, false, false, false, false, false, false, false);
let (mut polygon, mut svg, mut raster_mask, mut class_order, mut shared) = (false, false, false, false, false);
let (mut polygon, mut svg, mut raster_mask, mut class_order, mut shared, mut credit) = (false, false, false, false, false, false);
let (mut offline_area_id, mut paper, mut native, mut guided, mut weighed, mut cleared, mut deduped) =
(false, false, false, false, false, false, false);
let mut obstructing = false;
Expand Down Expand Up @@ -2062,6 +2075,7 @@ fn map_capabilities<'a>(maps: impl IntoIterator<Item = &'a Map>) -> Vec<&'static
zarr |= map.layers.iter().any(zarr_window);
native |= map.layers.iter().any(|layer| held_natively(&layer.dataset));
raster_mask |= map.layers.iter().any(|layer| layer.raster_mask.is_some());
credit |= map.layers.iter().any(|layer| layer.credit.is_some());
class_order |= map.layers.iter().any(|layer| keeps_class_order(&layer.renderer));
shared |= shares_embedded_files(map);
legends |= map.tiles.iter().any(|tile| {
Expand Down Expand Up @@ -2091,6 +2105,7 @@ fn map_capabilities<'a>(maps: impl IntoIterator<Item = &'a Map>) -> Vec<&'static
(svg, "svg-markers"),
(zarr, "zarr-window"),
(raster_mask, "layer-raster-mask"),
(credit, "layer-credit"),
(class_order, UNIQUE_KEEP_ORDER),
(guided, "label-guide"),
(weighed, "label-weight"),
Expand Down Expand Up @@ -3314,6 +3329,9 @@ mod tests {
(&["layer-raster-mask"], "layer.mask", json!({"mask": {"raster": "Slope", "min": 25}})),
(&[], "layer.mask", json!({"mask": "Countries"})),
(&[], "layer.mask", json!({"mask": null})),
(&["layer-credit"], "layer.credit", json!({"credit": "Example Agency"})),
(&["layer-credit"], "layer.credit", json!({"credit": ""})),
(&["layer-credit"], "layer.credit", json!({"credit": null})),
// An SVG image is a picture marker as well, in a node as in a saved command.
(&["picture-markers", "svg-markers"], "layer.marker", json!({"image": svg})),
(&[], "buffer", json!({"input": "Cities", "distance": 1})),
Expand Down
8 changes: 6 additions & 2 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ mod layout_panel_cut;
#[path = "tests/layout_chart_notices.rs"]
mod layout_chart_notices;

#[path = "tests/layer_credit.rs"]
mod layer_credit;
#[path = "tests/layout_credits.rs"]
mod layout_credits;
#[path = "tests/layout_page_scale.rs"]
Expand Down Expand Up @@ -37693,7 +37695,9 @@ fn cog_tile_layers_of_older_projects_open_as_rasters() {
assert_eq!(names[names.len() - 2..], ["Scene", "Aerial"], "{names:?}");
assert_eq!(t.map().tiles.iter().map(|x| x.name.as_str()).collect::<Vec<_>>(), ["Series"]);
// Scene's settings a raster layer hasn't are said to be dropped, once; Aerial had none.
let said = |t: &Session| t.notices.iter().filter(|n| n.text.contains("which have no attribution, legend, overlay, zoom range")).count();
// Its attribution is the raster layer's credit now, kept rather than dropped.
assert_eq!(t.map().layers.iter().find(|l| l.name == "Scene").unwrap().credit.as_deref(), Some("© Example"));
let said = |t: &Session| t.notices.iter().filter(|n| n.text.contains("which have no legend, overlay, zoom range")).count();
assert_eq!(said(&t), 1, "{:?}", t.notices.last());
assert!(t.notices.iter().any(|n| n.text.contains("not kept for Scene") && !n.text.contains("Aerial")), "{:?}", t.notices.last());
t.run("map.zoomIn", &Value::Null).unwrap();
Expand Down Expand Up @@ -37721,7 +37725,7 @@ fn a_cog_tile_layer_added_this_session_stays_one_until_the_project_opens_again()
s.run("map.import", &json!({"text": serde_json::to_string(&other).unwrap()})).unwrap();
assert_eq!(scene(&s), Some((TileKind::Cog, "© Example".to_string())), "converted by a repair");
assert!(s.project.maps[0].layer_by_name("Scene").is_none());
assert!(!s.notices.iter().any(|n| n.text.contains("which have no attribution")), "{:?}", s.notices);
assert!(!s.notices.iter().any(|n| n.text.contains("raster layers read in place, which have no")), "{:?}", s.notices);
// An older map file's plain COG tile layer opens as a raster layer read in place as it is
// imported.
let mut old = serde_json::to_value(rustgis_map::Map::new("Old")).unwrap();
Expand Down
Loading
Loading