Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4ef8422
fix(map): QGIS and ArcGIS imports of picture markers note an expressi…
jgregoriorincon Nov 25, 2026
4ffce51
fix(map): an esriPMS height that isn't a number sizes nothing, said o…
jgregoriorincon Nov 26, 2026
e3830dc
fix(map): an encoded :// in a file address is a name; a negative heig…
jgregoriorincon Nov 26, 2026
c5b359b
fix(map): a picture marker's circle of no size is RustGIS's, said; a …
jgregoriorincon Nov 26, 2026
492664d
fix(map): an esriPMS height that isn't a number isn't lost silently i…
jgregoriorincon Nov 26, 2026
077baa8
fix(map): a relative file name with an encoded :// is refused for its…
jgregoriorincon Nov 26, 2026
3932592
fix(map): a file address is trimmed once decoded, before it is checke…
jgregoriorincon Nov 26, 2026
3adf936
fix(map): the circle of an image that doesn't draw says each size it …
jgregoriorincon Nov 26, 2026
7ca9058
fix(map): a tile archive with an encoded drive colon is pinned to its…
jgregoriorincon Nov 26, 2026
5aed041
fix(map): a delimitedtext address with an encoded drive colon is on t…
jgregoriorincon Nov 26, 2026
86717b8
fix(map): a picture marker that draws says a width or height it can't…
jgregoriorincon Nov 26, 2026
63b8947
style(map): format the csv source's struct literal (#2986)
jgregoriorincon Nov 26, 2026
c348df5
fix(map): an image address that joins a root project folder into a ne…
jgregoriorincon Nov 26, 2026
5aaf604
fix(map): unreadable marker sizes are said as left out, a negative he…
jgregoriorincon Nov 26, 2026
2f0662f
test(map): a plain assertion for a single height, a clearer name in t…
jgregoriorincon Nov 26, 2026
9a564c8
fix(map): the circle of an image that doesn't draw says it has no siz…
jgregoriorincon Nov 26, 2026
7504d8a
test(map): a circle's size below 0 is pinned as no size; the height f…
jgregoriorincon Nov 26, 2026
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
175 changes: 162 additions & 13 deletions crates/map/src/arcgis_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,26 +491,46 @@ fn symbol(s: &Value, g: GeometryType, picture: Option<Rgba>, pictures: &mut Pict
// Sized by its width, as a picture marker is: its height follows the image's own
// proportion, which a service draws its symbol at. Without a width above 0, its
// height stands in as its width, said, since an image that isn't square is then
// drawn that wide, not that tall; with neither, RustGIS's size does.
// drawn that wide, not that tall; with neither (a height of 0 is none), RustGIS's
// size does. A height of 0 beside a width is said: the width alone draws it.
Ok(p) => {
// A side that isn't a number is said as the circle says it, whether this uses it or not.
say_unreadable_sizes(s, notes);
let wide = s.get("width").and_then(Value::as_f64).is_some_and(|w| w.is_finite() && w > 0.0);
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
if !wide {
notes.add(if s.get("height").is_some_and(|h| !h.is_null()) {
"picture markers with no width, drawn with their height as their width"
} else {
"picture markers with no size, drawn at RustGIS's"
});
}
let size = size(s.get(if wide { "width" } else { "height" }), base.size, notes);
let height = s.get("height").filter(|h| !h.is_null());
let no_height = height.and_then(Value::as_f64).is_some_and(|h| h <= 0.0);
let sized_by = if wide {
if no_height {
notes.add("picture markers of no height, drawn as tall as their image is");
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
}
s.get("width")
} else if height.and_then(Value::as_f64).is_some_and(|h| h > 0.0) {
notes.add("picture markers with no width, drawn with their height as their width");
height
} else {
notes.add("picture markers with no size, drawn at RustGIS's");
None
};
let size = size(sized_by, base.size, notes);
return Some((Symbol { fill, size, marker: Marker::Picture(p), ..base }, None));
}
Err(why) => notes.add(why),
}
// As a circle, the larger of its width and height, so that one past the largest is
// said once.
let points = |k: &str| s.get(k).and_then(Value::as_f64).filter(|v| v.is_finite()).unwrap_or(f64::NEG_INFINITY);
let larger = if points("height") > points("width") { s.get("height") } else { s.get("width") };
let size = size(larger, base.size, notes);
// said once; each side that isn't a number is said, as `size()` says one it can't read.
let num = |k: &str| s.get(k).and_then(Value::as_f64).filter(|v| v.is_finite());
say_unreadable_sizes(s, notes);
let top = match (num("height"), num("width")) {
(Some(h), Some(w)) => Some(h.max(w)),
(h, w) => h.or(w),
};
let larger = if num("height") > num("width") { s.get("height") } else { s.get("width") };
// With no size above 0 (a size of 0 isn't shown), or none given, RustGIS's, said as the drawn one is.
let none = top.is_none_or(|t| t <= 0.0);
if none {
notes.add("picture markers with no size, drawn at RustGIS's");
}
let size = size(if none { None } else { larger }, base.size, notes);
Some((Symbol { fill, size, ..base }, None))
}
("esriPFS", GeometryType::Polygon) => {
Expand Down Expand Up @@ -621,6 +641,14 @@ fn size(v: Option<&Value>, default: f32, notes: &mut Notes) -> f32 {
})
}

/// Says a picture marker's `width` or `height` that is given but isn't a number, once for either or both.
fn say_unreadable_sizes(s: &Value, notes: &mut Notes) {
let unreadable = |k: &str| s.get(k).is_some_and(|v| !v.is_null()) && !s.get(k).and_then(Value::as_f64).is_some_and(f64::is_finite);
if unreadable("width") || unreadable("height") {
notes.add("marker sizes RustGIS can't read, left out");
}
}

/// A symbol's style (`style`), `None` when it names none; one that isn't text is noted and taken as
/// none (ArcGIS's default style).
fn style<'a>(s: &'a Value, notes: &mut Notes) -> Option<&'a str> {
Expand Down Expand Up @@ -782,6 +810,58 @@ mod tests {
assert_eq!(notes.text(), "markers' angles and offsets, left out");
}

/// A picture marker with a height of 0 isn't drawn at 0 (not shown) under a note saying it is
/// drawn as wide as its height: a height of 0 is no height.
#[test]
fn a_picture_marker_of_no_height_is_said_so() {
let image = "iVBORw0KGgoSIMPLE=";
let styled_pms = |width: Value, height: Value| {
let info = json!({"renderer": {"type": "simple", "symbol": {"type": "esriPMS", "imageData": image, "width": width, "height": height}}});
let (l, notes) = styled(GeometryType::Point, info);
let Renderer::Single(s) = l.renderer else { panic!("a single symbol") };
(s, notes.text())
};
let Renderer::Single(base) = layer(GeometryType::Point).renderer else { panic!("a single symbol") };
// With no width above 0 either, it has no size: RustGIS's.
let cases = [(json!(null), json!(0)), (json!(0), json!(0)), (json!(0), json!(-4))];
for (width, height) in cases {
let (s, text) = styled_pms(width.clone(), height.clone());
assert_eq!(s.size, base.size, "width {width}, height {height}");
assert_eq!(text, "picture markers with no size, drawn at RustGIS's", "width {width}, height {height}");
}
// A side that isn't a number can't size it either, and is said, as the circle says it.
for (width, height) in [(json!(null), json!("18")), (json!(0), json!("abc"))] {
let (s, text) = styled_pms(width.clone(), height.clone());
assert_eq!(s.size, base.size, "width {width}, height {height}");
assert_eq!(
text, "marker sizes RustGIS can't read, left out; picture markers with no size, drawn at RustGIS's",
"width {width}, height {height}"
);
}
// So is one a width makes no use of, and a width that isn't a number beside a height that is.
let (s, text) = styled_pms(json!(15), json!("abc"));
assert_eq!(s.size, 15.0);
assert_eq!(text, "marker sizes RustGIS can't read, left out");
let (s, text) = styled_pms(json!("abc"), json!(18));
assert_eq!(s.size, 18.0);
assert_eq!(
text,
"marker sizes RustGIS can't read, left out; picture markers with no width, drawn with their height as their width"
);
// With a width, it is drawn by it, and the height's 0 said.
let (s, text) = styled_pms(json!(15), json!(0));
assert_eq!(s.size, 15.0);
assert_eq!(text, "picture markers of no height, drawn as tall as their image is");
// A height below 0 is no height either: the width alone draws it, and the height is said.
let (s, text) = styled_pms(json!(15), json!(-4));
assert_eq!(s.size, 15.0);
assert_eq!(text, "picture markers of no height, drawn as tall as their image is");
// A height above 0 says nothing of the kind.
let (s, text) = styled_pms(json!(15), json!(18));
assert_eq!(s.size, 15.0);
assert!(text.is_empty(), "{text}");
}

#[test]
fn a_picture_marker_rustgis_cant_draw_is_a_grey_circle_of_its_size_and_said_why() {
let circle = |symbol: Value| {
Expand All @@ -804,6 +884,75 @@ mod tests {
// Its image only at its `url`, which RustGIS doesn't fetch.
let url = json!({"type": "esriPMS", "url": "4d1f6b3c", "width": 15, "height": 18});
assert_eq!(circle(url), "picture markers whose image is only at a URL, drawn as circles");
// A height that isn't a number, with no width, isn't lost silently: size() says it can't read it.
let (l, notes) = styled(
GeometryType::Point,
json!({"renderer": {"type": "simple", "symbol": {"type": "esriPMS", "imageData": gif, "width": null, "height": "18"}}}),
);
let Renderer::Single(s) = l.renderer else { panic!("a single symbol") };
let Renderer::Single(base) = layer(GeometryType::Point).renderer else { panic!("a single symbol") };
assert_eq!(s.size, base.size);
assert_eq!(
notes.text(),
"picture markers whose image isn't a PNG, JPEG or SVG RustGIS reads, drawn as circles; marker sizes RustGIS can't read, left out; picture markers with no size, drawn at RustGIS's"
);
// Each side that isn't a number is said, whichever one the circle takes its size from.
for (width, height, size, text) in [
(
json!("abc"),
json!(18),
18.0,
"picture markers whose image isn't a PNG, JPEG or SVG RustGIS reads, drawn as circles; marker sizes RustGIS can't read, left out",
),
(
json!(0),
json!("abc"),
0.0,
"picture markers whose image isn't a PNG, JPEG or SVG RustGIS reads, drawn as circles; marker sizes RustGIS can't read, left out; picture markers with no size, drawn at RustGIS's",
),
// A size below 0 is no size (not drawn at 0, not shown), as it is for the drawn picture.
(
json!(-5),
json!(null),
0.0,
"picture markers whose image isn't a PNG, JPEG or SVG RustGIS reads, drawn as circles; picture markers with no size, drawn at RustGIS's",
),
// With neither side given at all, it has no size, as the drawn picture has none.
(
json!(null),
json!(null),
0.0,
"picture markers whose image isn't a PNG, JPEG or SVG RustGIS reads, drawn as circles; picture markers with no size, drawn at RustGIS's",
),
(
json!("abc"),
json!("abc"),
0.0,
"picture markers whose image isn't a PNG, JPEG or SVG RustGIS reads, drawn as circles; marker sizes RustGIS can't read, left out; picture markers with no size, drawn at RustGIS's",
),
] {
let (l, notes) = styled(
GeometryType::Point,
json!({"renderer": {"type": "simple", "symbol": {"type": "esriPMS", "imageData": gif, "width": width, "height": height}}}),
);
let Renderer::Single(s) = l.renderer else { panic!("a single symbol") };
let Renderer::Single(base) = layer(GeometryType::Point).renderer else { panic!("a single symbol") };
let expected = if size == 0.0 { base.size } else { size };
assert_eq!(s.size, expected, "width {width}, height {height}");
assert_eq!(notes.text(), text, "width {width}, height {height}");
}
// With no size above 0 either, the circle is RustGIS's size (not 0, not shown), said.
let (l, notes) = styled(
GeometryType::Point,
json!({"renderer": {"type": "simple", "symbol": {"type": "esriPMS", "imageData": gif, "width": 0, "height": 0}}}),
);
let Renderer::Single(s) = l.renderer else { panic!("a single symbol") };
let Renderer::Single(base) = layer(GeometryType::Point).renderer else { panic!("a single symbol") };
assert_eq!((s.marker, s.size), (Marker::Circle, base.size));
assert_eq!(
notes.text(),
"picture markers whose image isn't a PNG, JPEG or SVG RustGIS reads, drawn as circles; picture markers with no size, drawn at RustGIS's"
);
assert_eq!(Picture::kept(gif), None, "an image that isn't drawn isn't kept");
}

Expand Down
42 changes: 32 additions & 10 deletions crates/map/src/qgis/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,24 @@ fn file_url_path(url: &str) -> Option<&str> {
Some(if drive { path.get(1..).unwrap_or(path) } else { path })
}

/// A `file:` address's path (see [`file_url_path`]) decoded as any address's parts are; `None` for any
/// other address and for one with a host.
pub(super) fn file_address_path(url: &str) -> Option<String> {
// Trimmed: what `absolute` trims after the checks must not decide them (`%20%2F%2Fhost` is `//host`).
let path = rustgis_data::address::percent_decode(file_url_path(url)?).trim().to_string();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
// A drive's colon may be encoded (`/C%3A/x`): the drive form is recognized once decoded.
let b = path.as_bytes();
let drive = b.first() == Some(&b'/') && b.get(1).is_some_and(u8::is_ascii_alphabetic) && b.get(2) == Some(&b':');
Some(if drive { path.get(1..).unwrap_or_default().to_string() } else { path })
}

/// A tile archive's path: a `file://` address (`file:../x` when relative) as its path, a relative
/// one from the project's folder; a web address as it is.
fn archive_path(url: &str, dir: &str) -> String {
let url = url.trim();
match file_url_path(url) {
match file_address_path(url) {
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
// (Its parts are encoded as in any address.)
Some(path) => absolute(&rustgis_data::address::percent_decode(path), dir),
Some(path) => absolute(&path, dir),
None if url.contains("://") => url.to_string(),
None => absolute(url, dir),
}
Expand Down Expand Up @@ -887,16 +898,11 @@ fn select_all(query: &str) -> Option<(String, Option<String>)> {
fn csv(datasource: &str, dir: &str) -> Source {
let (path, q) = datasource.split_once('?').unwrap_or((datasource, ""));
// file:///absolute/path, or a relative one as file:./path.
let path = file_url_path(path).unwrap_or(path);
// A `file:` address is its path decoded, a drive's colon encoded or not; anything else is decoded as it is.
let path = file_address_path(path).unwrap_or_else(|| rustgis_data::address::percent_decode(path));
let q = query(q);
let get = |k: &str| q.iter().find(|(n, _)| n == k).map(|(_, v)| v.clone()).filter(|v| !v.is_empty());
Source::Csv {
path: absolute(&rustgis_data::address::percent_decode(path), dir),
x: get("xField"),
y: get("yField"),
wkt: get("wktField"),
crs: get("crs"),
}
Source::Csv { path: absolute(&path, dir), x: get("xField"), y: get("yField"), wkt: get("wktField"), crs: get("crs") }
}

/// The most `&`-joined parts of a web source, or of an address's query, read; the rest are
Expand Down Expand Up @@ -1386,6 +1392,9 @@ mod tests {
);
let Source::Csv { path, .. } = read("delimitedtext", "file:///C:/maps/p.csv?xField=x", dir) else { panic!() };
assert_eq!(path, "C:/maps/p.csv");
// A drive's colon may be encoded, as an image's and an archive's is.
let Source::Csv { path, .. } = read("delimitedtext", "file:///C%3A/maps/p.csv?xField=x", dir) else { panic!() };
assert_eq!(path, "C:/maps/p.csv");
// An encoded file address is decoded once (QGIS encodes the address again as a parameter).
assert_eq!(
read("mbtilesvectortiles", "type=mbtiles&url=file:///maps/my%2520tiles.mbtiles", dir),
Expand Down Expand Up @@ -1817,4 +1826,17 @@ mod tests {
assert_eq!(filtered("").as_deref(), Some(r#""kind" = 'a'"#));
assert!(matches!(unnamed("pts"), Some(VirtualFrom::Missing(_))));
}

/// A tile archive at a `file:` address whose drive's colon is encoded is on that drive, as a
/// picture marker's image is (`file:///C%3A/…` is `C:/…`, not `/C:/…`).
#[test]
fn a_tile_archive_with_an_encoded_drive_colon_is_on_that_drive() {
for (url, path) in [
("file:///C%3A/maps/t.mbtiles", "C:/maps/t.mbtiles"),
("file:///C:/maps/t.mbtiles", "C:/maps/t.mbtiles"),
("file:///maps/t.mbtiles", "/maps/t.mbtiles"),
] {
assert_eq!(archive_path(url, "/p"), path, "{url}");
}
}
}
Loading
Loading