From cdbf06524cce0f419d84639e99c058234c391d4d Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 23 Nov 2026 11:18:45 +0100 Subject: [PATCH 1/3] feat(crs): compare data and project CRS on their horizontal part Heights are a label of each data. A data in EPSG:2193 and a project in EPSG:2193+7839 place X and Y the same: the project no longer flags it, follows it as one CRS, and puts it under the basemap. Registered compound CRS are compared through the horizontal parts the back lists. The store keeps the vertical CRS, the compoundable CRS and the horizontal parts from the geographic list, still loaded once. Refs Geode-solutions/Vease#873 Co-Authored-By: Claude Opus 5.5 --- app/stores/basemap_helpers/georeferenced.ts | 3 +- app/stores/crs.ts | 24 +++++++++++++--- app/utils/crs.ts | 31 ++++++++++++++++++++- tests/unit/stores/crs.nuxt.test.ts | 16 +++++++++++ tests/unit/utils/crs.nuxt.test.ts | 30 +++++++++++++++++++- 5 files changed, 96 insertions(+), 8 deletions(-) diff --git a/app/stores/basemap_helpers/georeferenced.ts b/app/stores/basemap_helpers/georeferenced.ts index f329ad457..fc9ec5370 100644 --- a/app/stores/basemap_helpers/georeferenced.ts +++ b/app/stores/basemap_helpers/georeferenced.ts @@ -1,6 +1,5 @@ import { type Extent, boxesExtent } from "./extent.js"; import type { ComputedRef } from "vue"; -import { sameCrs } from "@ogw_front/utils/crs"; import { useCrsStore } from "@ogw_front/stores/crs"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; @@ -21,7 +20,7 @@ function useGeoreferenced(): Georeferenced { function georeferencedIds(): string[] { return crsStore.crsItems - .filter((item) => sameCrs(item.crs, crsStore.projectCrs)) + .filter((item) => crsStore.sameProjectCrs(item.crs, crsStore.projectCrs)) .map((item) => item.data_id); } diff --git a/app/stores/crs.ts b/app/stores/crs.ts index 66412becf..89118194e 100644 --- a/app/stores/crs.ts +++ b/app/stores/crs.ts @@ -1,4 +1,4 @@ -import { oldestCrs, sameCrs } from "@ogw_front/utils/crs"; +import { oldestCrs, sameHorizontalCrs } from "@ogw_front/utils/crs"; import type { CRS } from "@geode/opengeodeweb-back/schema_types"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; @@ -18,6 +18,15 @@ export const useCrsStore = defineStore("crs", () => { const crsItems = dataStore.refCrsItems(); const projectCrs = ref(undefined); const projectCrsEditRequest = ref(false); + // From the geographic list: the heights a CRS can take, and the X/Y part of compound CRS + const verticalList = shallowRef([]); + const compoundable = shallowRef([]); + const horizontalParts = shallowRef>({}); + + // Heights are a label of each data: the project compares the X/Y part only + function sameProjectCrs(left: CRS | undefined, right: CRS | undefined): boolean { + return sameHorizontalCrs(left, right, horizontalParts.value); + } // The project follows its data: once every georeferenced data is in one CRS, it is the project // CRS. Data already mixed before any project CRS: the oldest one is the reference @@ -28,13 +37,13 @@ export const useCrsStore = defineStore("crs", () => { if (first === undefined) { return undefined; } - if (georeferenced.every((item) => sameCrs(item.crs, first.crs))) { + if (georeferenced.every((item) => sameProjectCrs(item.crs, first.crs))) { return first.crs; } return projectCrs.value ?? oldestCrs(georeferenced); }, (reference) => { - if (reference !== undefined && !sameCrs(reference, projectCrs.value)) { + if (reference !== undefined && !sameProjectCrs(reference, projectCrs.value)) { projectCrs.value = reference; } }, @@ -46,7 +55,7 @@ export const useCrsStore = defineStore("crs", () => { const project = projectCrs.value; const mismatched = new Map(); for (const item of crsItems.value) { - if (project !== undefined && !sameCrs(item.crs, project)) { + if (project !== undefined && !sameProjectCrs(item.crs, project)) { mismatched.set(item.data_id, item.crs); } } @@ -60,6 +69,9 @@ export const useCrsStore = defineStore("crs", () => { params: { geode_object_type: geodeObjectType }, }); if (response?.crs_list !== undefined) { + verticalList.value = response.vertical_list; + compoundable.value = response.compoundable; + horizontalParts.value = response.horizontal_parts; return response.crs_list; } } catch { @@ -119,6 +131,10 @@ export const useCrsStore = defineStore("crs", () => { return { crsItems, geographicList, + verticalList, + compoundable, + horizontalParts, + sameProjectCrs, crsEditEnabled, enableCrsEdit, crsEditRequest, diff --git a/app/utils/crs.ts b/app/utils/crs.ts index 4ac1f6dd1..24338631e 100644 --- a/app/utils/crs.ts +++ b/app/utils/crs.ts @@ -21,6 +21,27 @@ function sameCrs(left: CRS | undefined, right: CRS | undefined): boolean { ); } +// The X/Y part of a CRS: "A" for a compound "A+B" code, the horizontal part of a registered +// Compound CRS given by the back (e.g. "EPSG:5698" -> "EPSG:2154"), the CRS itself otherwise +function horizontalCode(crs: CRS, horizontalParts: Record = {}): string { + const key = `${crs.authority}:${crs.code}`; + const [horizontal = crs.code] = crs.code.split("+"); + return horizontalParts[key] ?? `${crs.authority}:${horizontal}`; +} + +// Heights are a label of each data: two CRS place X and Y the same when their horizontal parts do +function sameHorizontalCrs( + left: CRS | undefined, + right: CRS | undefined, + horizontalParts: Record = {}, +): boolean { + return ( + left !== undefined && + right !== undefined && + horizontalCode(left, horizontalParts) === horizontalCode(right, horizontalParts) + ); +} + // Same CRS, or both still in local coordinates function sameCrsState(left: CRS | undefined, right: CRS | undefined): boolean { return (left === undefined && right === undefined) || sameCrs(left, right); @@ -38,4 +59,12 @@ function oldestCrs( ?.crs; } -export { formatCrs, formatCrsCode, oldestCrs, sameCrs, sameCrsState }; +export { + formatCrs, + formatCrsCode, + horizontalCode, + oldestCrs, + sameCrs, + sameCrsState, + sameHorizontalCrs, +}; diff --git a/tests/unit/stores/crs.nuxt.test.ts b/tests/unit/stores/crs.nuxt.test.ts index d8d1bb3b0..02cbd210d 100644 --- a/tests/unit/stores/crs.nuxt.test.ts +++ b/tests/unit/stores/crs.nuxt.test.ts @@ -141,6 +141,22 @@ describe("project crs", () => { ]); }); + test("data in the horizontal part of a compound project crs are in the project crs", () => { + const nztm = { authority: "EPSG", code: "2193", name: "NZGD2000 / NZTM 2000" }; + const nztmNzvd = { authority: "EPSG", code: "2193+7839", name: "NZTM 2000 + NZVD2016 height" }; + mockItems( + mockAs([ + { data_id: "model", created_at: "1", crs: nztmNzvd }, + { data_id: "map", created_at: "2", crs: nztm }, + ]), + ); + const crsStore = useCrsStore(); + crsStore.setProjectCrs(nztmNzvd); + // Heights are a label of each data: they do not set them apart from the project + expect(crsStore.mismatchedCrs.size).toBe(0); + expect(crsStore.projectCrs).toStrictEqual(nztmNzvd); + }); + test("is exported and imported with the project", () => { mockItems(mockAs([{ data_id: "a", created_at: "1", crs: LAMBERT }])); const crsStore = useCrsStore(); diff --git a/tests/unit/utils/crs.nuxt.test.ts b/tests/unit/utils/crs.nuxt.test.ts index 19e6d11c4..72846bea9 100644 --- a/tests/unit/utils/crs.nuxt.test.ts +++ b/tests/unit/utils/crs.nuxt.test.ts @@ -1,5 +1,12 @@ import { describe, expect, test, vi } from "vitest"; -import { formatCrs, formatCrsCode, oldestCrs, sameCrs, sameCrsState } from "@ogw_front/utils/crs"; +import { + formatCrs, + formatCrsCode, + oldestCrs, + sameCrs, + sameCrsState, + sameHorizontalCrs, +} from "@ogw_front/utils/crs"; import type { DataItem } from "@ogw_front/stores/data"; import { mockAs } from "@ogw_tests/utils"; @@ -36,6 +43,27 @@ describe("same crs", () => { }); }); +const NZTM = { authority: "EPSG", code: "2193", name: "NZGD2000 / NZTM 2000" }; +const NZTM_NZVD = { authority: "EPSG", code: "2193+7839", name: "NZTM 2000 + NZVD2016 height" }; +const LAMBERT_NGF = { + authority: "EPSG", + code: "5698", + name: "RGF93 v1 / Lambert-93 + NGF-IGN69 height", +}; + +describe("same horizontal crs", () => { + test("a compound code is in the crs of its horizontal part, even before the list loads", () => { + expect(sameHorizontalCrs(NZTM, NZTM_NZVD)).toBe(true); + expect(sameHorizontalCrs(LAMBERT, NZTM_NZVD)).toBe(false); + expect(sameHorizontalCrs(undefined, NZTM)).toBe(false); + }); + + test("a registered compound crs is in the crs of its horizontal part", () => { + expect(sameHorizontalCrs(LAMBERT, LAMBERT_NGF, { "EPSG:5698": "EPSG:2154" })).toBe(true); + expect(sameHorizontalCrs(LAMBERT, LAMBERT_NGF)).toBe(false); + }); +}); + describe("oldest crs", () => { test("is the crs of the oldest georeferenced data", () => { const items = mockAs([ From b0723294ede85efb944fcab1daf87c9f9a112a26 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 23 Nov 2026 11:20:14 +0100 Subject: [PATCH 2/3] feat(crs): pick optional heights to compose a CRS Under the CRS list, a "Heights (optional)" field lists the vertical CRS by name. Once a CRS without heights is selected (projected or geographic 2D), choosing heights emits the compound CRS, e.g. EPSG:2193+7839 "NZGD2000 / NZTM 2000 + NZVD2016 height". Selecting a CRS that already has heights clears them and disables the field. Refs Geode-solutions/Vease#873 Co-Authored-By: Claude Opus 5.5 --- app/components/CrsSelector.vue | 63 ++++++++++++++++++- .../unit/components/CrsSelector.nuxt.test.ts | 39 ++++++++++++ 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/app/components/CrsSelector.vue b/app/components/CrsSelector.vue index c1fcf7390..4174fff66 100644 --- a/app/components/CrsSelector.vue +++ b/app/components/CrsSelector.vue @@ -24,13 +24,53 @@ function crs_key(crs: CRS): string { return `${crs.authority}:${crs.code}`; } +// The row picked in the table, and the optional heights that complete it +const horizontal_crs = ref(undefined); +const heights_crs = ref(undefined); + +// Projected and geographic 2D CRS have no heights: only these take a vertical CRS +const heights_enabled = computed( + () => + horizontal_crs.value !== undefined && + crsStore.compoundable.includes(crs_key(horizontal_crs.value)), +); + +function heights_title(crs: CRS): string { + return `${crs.name} (${crs_key(crs)})`; +} + +// "A+B": EPSG has no single code for most projected + height pairs +function emit_selection(): void { + const horizontal = horizontal_crs.value; + const heights = heights_crs.value; + if (horizontal === undefined || heights === undefined) { + selectedCrs.value = horizontal; + return; + } + selectedCrs.value = { + authority: horizontal.authority, + code: `${horizontal.code}+${heights.code}`, + name: `${horizontal.name} + ${heights.name}`, + }; +} + // A click on the row selects it: no checkbox column. Enter does the same once the row is focused function select_crs(crs: CRS): void { - selectedCrs.value = crs; + horizontal_crs.value = crs; + if (!heights_enabled.value) { + heights_crs.value = undefined; + } + emit_selection(); +} + +function select_heights(crs: CRS | undefined | null): void { + heights_crs.value = crs ?? undefined; + emit_selection(); } function row_props({ item }: { item: CRS }): Record { - const selected = selectedCrs.value !== undefined && crs_key(item) === crs_key(selectedCrs.value); + const selected = + horizontal_crs.value !== undefined && crs_key(item) === crs_key(horizontal_crs.value); return { class: ["crs-row", { "bg-primary": selected }], tabindex: 0, @@ -111,6 +151,25 @@ onMounted(async () => { +