@vectoriahq/quac 0.1.0 → 0.3.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -3
- package/dist/generate/externalStacCatalogue.d.ts +4 -4
- package/dist/generate/externalStacCatalogue.js +9 -11
- package/dist/generate/fileLayerCollection.d.ts +2 -1
- package/dist/generate/fileLayerCollection.js +4 -2
- package/dist/generate/folderStacCatalogue.d.ts +6 -0
- package/dist/generate/folderStacCatalogue.js +10 -2
- package/dist/generate/normalizedProject.d.ts +5 -4
- package/dist/generate/normalizedProject.js +44 -92
- package/dist/generate/ogcFeaturesStacCatalogue.js +1 -1
- package/dist/generate/stacCatalogue.js +23 -21
- package/dist/generate/wmsStacCatalogue.js +5 -16
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/model/QgsProject.d.ts +54 -9
- package/dist/model/Stac.d.ts +8 -6
- package/dist/model/Stac.js +1 -1
- package/dist/model/featureFilter.d.ts +1 -1
- package/dist/model/fieldIconAddress.d.ts +1 -1
- package/dist/model/fieldIconAddress.js +1 -1
- package/dist/model/ogcFeatures.d.ts +3 -3
- package/dist/model/ogcFeatures.js +2 -2
- package/dist/model/quacExtension.d.ts +1 -1
- package/dist/model/quacExtension.js +1 -1
- package/dist/model/stacAssetRoles.d.ts +1 -1
- package/dist/model/stacAssetRoles.js +1 -1
- package/dist/model/stacHref.d.ts +3 -3
- package/dist/model/stacHref.js +3 -3
- package/dist/model/stacPmtiles.d.ts +1 -1
- package/dist/model/stacWms.d.ts +1 -1
- package/dist/model/stacWms.js +1 -1
- package/dist/model/wfs.d.ts +1 -1
- package/dist/parse/geometrySiblings.d.ts +1 -1
- package/dist/parse/geometrySiblings.js +1 -1
- package/dist/parse/parseBrandColour.d.ts +3 -3
- package/dist/parse/parseBrandColour.js +3 -3
- package/dist/parse/parseDataDefinedEditable.js +2 -2
- package/dist/parse/parseLayers.d.ts +5 -2
- package/dist/parse/parseLayers.js +148 -97
- package/dist/parse/parseMeasurement.d.ts +2 -3
- package/dist/parse/parseMeasurement.js +3 -4
- package/dist/parse/parseMergin.d.ts +3 -3
- package/dist/parse/parseMergin.js +8 -5
- package/dist/parse/parseQgsXml.js +10 -3
- package/dist/parse/projectNotes.d.ts +26 -0
- package/dist/parse/projectNotes.js +52 -0
- package/dist/parse/qgisExpression.d.ts +19 -4
- package/dist/parse/qgisExpression.js +58 -13
- package/dist/parse/qtDateFormat.d.ts +3 -3
- package/dist/parse/qtDateFormat.js +3 -3
- package/dist/parse/qtRegex.d.ts +2 -2
- package/dist/parse/qtRegex.js +2 -2
- package/dist/sources/stacItems.d.ts +1 -1
- package/dist/sources/stacItems.js +2 -2
- package/dist/util/devLog.d.ts +1 -2
- package/dist/util/devLog.js +1 -2
- package/dist/util/nonBlankText.d.ts +2 -0
- package/dist/util/nonBlankText.js +4 -0
- package/dist/util/wfsVersions.js +1 -1
- package/package.json +10 -2
- package/src/schema/quac.schema.json +5 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vectoriahq/quac
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Writes and reads [QUAC](https://github.com/vectoriahq/quac), which adds map layer settings to STAC 1.1.0 catalogues: how each layer is shown, how its fields are filled in and checked, and how its layers relate.
|
|
4
4
|
|
|
5
5
|
The package writes QUAC catalogues from QGIS projects and other sources, and reads them back. It makes no network request: it builds a catalogue from what an application has already fetched, such as a QGIS project's text or a QGIS Server GetProjectSettings response.
|
|
6
6
|
|
|
@@ -21,10 +21,17 @@ import { parseQgsXml, generateStacCatalogue } from '@vectoriahq/quac'
|
|
|
21
21
|
|
|
22
22
|
globalThis.DOMParser = DOMParser
|
|
23
23
|
|
|
24
|
-
const project = parseQgsXml(await readFile('project.qgs', 'utf8'))
|
|
25
|
-
const catalogue = generateStacCatalogue(project
|
|
24
|
+
const project = parseQgsXml(await readFile('survey/project.qgs', 'utf8'))
|
|
25
|
+
const catalogue = generateStacCatalogue(project, [], {
|
|
26
|
+
selfHref: 'https://data.example.test/survey/',
|
|
27
|
+
projectPath: 'project.qgs'
|
|
28
|
+
})
|
|
26
29
|
```
|
|
27
30
|
|
|
31
|
+
`selfHref` is the address of the folder the project is published in, and `projectPath` is the project file's path inside that folder. A layer's data files and styles are addressed relative to them, so a catalogue to be published or saved apart from the project needs both. Without `projectPath`, each style's address names no file, and only an application already holding the project can read it; without `selfHref`, the catalogue's relative addresses have no folder to start from.
|
|
32
|
+
|
|
33
|
+
`project.notes` lists the project's settings that the catalogue does not carry, such as a widget it does not read or an expression it cannot read. Each note gives the layer, the field where there is one, a reason code and the setting's own text where it helps; the `ProjectNoteReason` type lists the codes and what each means. The notes are not written into the catalogue.
|
|
34
|
+
|
|
28
35
|
The JSON Schema that checks a catalogue's `quac:` fields is exported as `@vectoriahq/quac/schema`.
|
|
29
36
|
|
|
30
37
|
## Documentation
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { StacCatalog, StacCollection } from '../model/Stac.ts';
|
|
2
2
|
/**
|
|
3
|
-
* Converts a STAC document fetched from somewhere else to the
|
|
4
|
-
* profile (`packages/quac/spec/README.md`), so
|
|
5
|
-
* whatever the source.
|
|
3
|
+
* Converts a STAC document fetched from somewhere else to the QUAC
|
|
4
|
+
* profile (`packages/quac/spec/README.md`), so everything downstream reads one
|
|
5
|
+
* shape whatever the source.
|
|
6
6
|
*
|
|
7
7
|
* Everything the source declared is kept — this fills gaps, it never
|
|
8
8
|
* overwrites. Three gaps get filled:
|
|
@@ -16,7 +16,7 @@ import type { StacCatalog, StacCollection } from '../model/Stac.ts';
|
|
|
16
16
|
*
|
|
17
17
|
* That last one is the fallback the profile allows: an external catalogue
|
|
18
18
|
* cannot be expected to have our vendor fields, so its `data` asset href is
|
|
19
|
-
* sniffed instead. Catalogues
|
|
19
|
+
* sniffed instead. Catalogues this package generates have the fields, and the
|
|
20
20
|
* sniff never runs on them.
|
|
21
21
|
*
|
|
22
22
|
* Children linked as separate documents (`rel: "child"`) are not followed
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { listQuacExtension } from "../model/quacExtension.js";
|
|
2
2
|
import { STAC_VERSION } from "../model/Stac.js";
|
|
3
3
|
import { readDataAsset } from "../model/stacAssetRoles.js";
|
|
4
|
+
import { readNonBlank } from "../util/nonBlankText.js";
|
|
4
5
|
/**
|
|
5
|
-
* Converts a STAC document fetched from somewhere else to the
|
|
6
|
-
* profile (`packages/quac/spec/README.md`), so
|
|
7
|
-
* whatever the source.
|
|
6
|
+
* Converts a STAC document fetched from somewhere else to the QUAC
|
|
7
|
+
* profile (`packages/quac/spec/README.md`), so everything downstream reads one
|
|
8
|
+
* shape whatever the source.
|
|
8
9
|
*
|
|
9
10
|
* Everything the source declared is kept — this fills gaps, it never
|
|
10
11
|
* overwrites. Three gaps get filled:
|
|
@@ -18,7 +19,7 @@ import { readDataAsset } from "../model/stacAssetRoles.js";
|
|
|
18
19
|
*
|
|
19
20
|
* That last one is the fallback the profile allows: an external catalogue
|
|
20
21
|
* cannot be expected to have our vendor fields, so its `data` asset href is
|
|
21
|
-
* sniffed instead. Catalogues
|
|
22
|
+
* sniffed instead. Catalogues this package generates have the fields, and the
|
|
22
23
|
* sniff never runs on them.
|
|
23
24
|
*
|
|
24
25
|
* Children linked as separate documents (`rel: "child"`) are not followed
|
|
@@ -55,8 +56,8 @@ function normalizeCollection(collection) {
|
|
|
55
56
|
extent: normalizeExtent(collection.extent),
|
|
56
57
|
links: collection.links ?? []
|
|
57
58
|
};
|
|
58
|
-
const declaresWfsFields =
|
|
59
|
-
&&
|
|
59
|
+
const declaresWfsFields = readNonBlank(collection['quac:wfs_endpoint'])
|
|
60
|
+
&& readNonBlank(collection['quac:wfs_type_name']);
|
|
60
61
|
if (!declaresWfsFields) {
|
|
61
62
|
const sniffed = parseWfsGetFeatureUrl(readDataAsset(collection)?.href ?? '');
|
|
62
63
|
if (sniffed) {
|
|
@@ -106,8 +107,8 @@ function wrapAsCatalog(root) {
|
|
|
106
107
|
* name".
|
|
107
108
|
*/
|
|
108
109
|
export function resolveWfsCollectionSource(collection) {
|
|
109
|
-
const endpoint =
|
|
110
|
-
const typeName =
|
|
110
|
+
const endpoint = readNonBlank(collection['quac:wfs_endpoint']);
|
|
111
|
+
const typeName = readNonBlank(collection['quac:wfs_type_name']);
|
|
111
112
|
if (endpoint && typeName)
|
|
112
113
|
return { endpoint, typeName };
|
|
113
114
|
return parseWfsGetFeatureUrl(readDataAsset(collection)?.href ?? '');
|
|
@@ -140,6 +141,3 @@ export function parseWfsGetFeatureUrl(href) {
|
|
|
140
141
|
return null;
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
|
-
function readNonEmptyString(value) {
|
|
144
|
-
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
145
|
-
}
|
|
@@ -29,7 +29,8 @@ export interface LinkedFileCollectionOptions {
|
|
|
29
29
|
* Generates the Collection for one dropped file: a `data` asset naming the file
|
|
30
30
|
* and its media type, `created` set to the drop time, and the world extent, which
|
|
31
31
|
* a Collection with no declared box takes. The file is not opened, so nothing
|
|
32
|
-
* here describes its contents
|
|
32
|
+
* here describes its contents: it declares no title of its own, and its
|
|
33
|
+
* description is `fileLayerDescription`'s, which says only the file's name.
|
|
33
34
|
*
|
|
34
35
|
* Pure function — no side effects, no I/O.
|
|
35
36
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fileLayerDescription } from "./folderStacCatalogue.js";
|
|
1
2
|
import { generateStacFromNormalized, slugify } from "./normalizedProject.js";
|
|
2
3
|
import { QUAC_LAYER_NAME } from "./stacCatalogue.js";
|
|
3
4
|
import { encodeAssetPath } from "../model/stacHref.js";
|
|
@@ -6,7 +7,8 @@ import { declaredMediaTypeForFile, GEOJSON_MEDIA_TYPE } from "../util/catalogueF
|
|
|
6
7
|
* Generates the Collection for one dropped file: a `data` asset naming the file
|
|
7
8
|
* and its media type, `created` set to the drop time, and the world extent, which
|
|
8
9
|
* a Collection with no declared box takes. The file is not opened, so nothing
|
|
9
|
-
* here describes its contents
|
|
10
|
+
* here describes its contents: it declares no title of its own, and its
|
|
11
|
+
* description is `fileLayerDescription`'s, which says only the file's name.
|
|
10
12
|
*
|
|
11
13
|
* Pure function — no side effects, no I/O.
|
|
12
14
|
*/
|
|
@@ -47,7 +49,7 @@ function buildFileCollection(file) {
|
|
|
47
49
|
kind: 'layer',
|
|
48
50
|
id: file.collectionId,
|
|
49
51
|
title: file.name,
|
|
50
|
-
description:
|
|
52
|
+
description: fileLayerDescription(file.name),
|
|
51
53
|
bbox: null,
|
|
52
54
|
geometryType: null,
|
|
53
55
|
tableColumns: [],
|
|
@@ -46,3 +46,9 @@ export interface FolderStacCatalogueOptions {
|
|
|
46
46
|
selfHref?: string;
|
|
47
47
|
}
|
|
48
48
|
export declare function generateStacCatalogueFromFolder(files: FolderCatalogueFile[], options: FolderStacCatalogueOptions): StacCatalog;
|
|
49
|
+
/**
|
|
50
|
+
* The description of a Collection made from one data file, which says nothing
|
|
51
|
+
* of itself: `Layer from roads.geojson.`. The folder's files and a single
|
|
52
|
+
* dropped or linked file share it.
|
|
53
|
+
*/
|
|
54
|
+
export declare function fileLayerDescription(fileName: string): string;
|
|
@@ -35,7 +35,7 @@ function fileToNormalized(file) {
|
|
|
35
35
|
const hasSize = Number.isSafeInteger(file.size) && file.size > 0;
|
|
36
36
|
if (hasSize)
|
|
37
37
|
assets.data[FILE_SIZE_FIELD] = file.size;
|
|
38
|
-
// A style is declared, never embedded —
|
|
38
|
+
// A style is declared, never embedded — a reader fetches it live on every load,
|
|
39
39
|
// the same as a style a project file refers to. Keyed by the style file's name so
|
|
40
40
|
// it reads as one entry in a style set, like every other source's styles.
|
|
41
41
|
if (file.styleRelPath) {
|
|
@@ -54,7 +54,7 @@ function fileToNormalized(file) {
|
|
|
54
54
|
kind: 'layer',
|
|
55
55
|
id: file.relPath,
|
|
56
56
|
title: file.layerName,
|
|
57
|
-
description:
|
|
57
|
+
description: fileLayerDescription(file.name),
|
|
58
58
|
// Both read from the file at load time, not from the listing.
|
|
59
59
|
bbox: null,
|
|
60
60
|
geometryType: null,
|
|
@@ -67,3 +67,11 @@ function fileToNormalized(file) {
|
|
|
67
67
|
editable: null
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* The description of a Collection made from one data file, which says nothing
|
|
72
|
+
* of itself: `Layer from roads.geojson.`. The folder's files and a single
|
|
73
|
+
* dropped or linked file share it.
|
|
74
|
+
*/
|
|
75
|
+
export function fileLayerDescription(fileName) {
|
|
76
|
+
return `Layer from ${fileName}.`;
|
|
77
|
+
}
|
|
@@ -259,7 +259,7 @@ export interface NormalizedProject {
|
|
|
259
259
|
}
|
|
260
260
|
/**
|
|
261
261
|
* Records where a catalogue came from as the Catalog's `self` link, so the
|
|
262
|
-
* document says it rather than
|
|
262
|
+
* document says it rather than a reader holding it alongside. Sources with no
|
|
263
263
|
* address of their own leave it off.
|
|
264
264
|
*/
|
|
265
265
|
export declare function withSelfLink(catalogue: StacCatalog, selfHref: string | undefined): StacCatalog;
|
|
@@ -274,7 +274,7 @@ export declare function generateStacFromNormalized(project: NormalizedProject):
|
|
|
274
274
|
/**
|
|
275
275
|
* The column with `data_type` written beside its `type`, as the Table
|
|
276
276
|
* extension recommends. A `type` outside `TableColumnType`, such as a QGIS
|
|
277
|
-
* Server type name
|
|
277
|
+
* Server type name this package does not map, gets no `data_type`.
|
|
278
278
|
*/
|
|
279
279
|
export declare function withDataType(column: TableColumn): TableColumn;
|
|
280
280
|
/**
|
|
@@ -367,11 +367,12 @@ export declare function readCollectionFieldAttachments(collection: StacCollectio
|
|
|
367
367
|
/**
|
|
368
368
|
* What each column says about changing it, keyed by field name — the
|
|
369
369
|
* counterpart of the `quac:editable`, `quac:default`,
|
|
370
|
-
* `quac:constraints`, `quac:hidden` and
|
|
370
|
+
* `quac:constraints`, `quac:hidden`, `quac:searchable` and
|
|
371
371
|
* `quac:reuse_last_value` writes in `stacCatalogue.ts`. A column
|
|
372
372
|
* declaring none of them is absent from the result.
|
|
373
373
|
*
|
|
374
|
-
* Only `quac:editable: false` makes a field read-only,
|
|
374
|
+
* Only `quac:editable: false` makes a field read-only, only
|
|
375
|
+
* `quac:searchable: false` keeps it out of a search, and only
|
|
375
376
|
* `quac:hidden: true`, `quac:reuse_last_value: true` and `quac:color: true`
|
|
376
377
|
* set theirs. A `quac:icon` that is not an `https://` address is left out, as
|
|
377
378
|
* is a `quac:control` other than `buttons` or `dropdown`.
|
|
@@ -2,6 +2,7 @@ import { readHttpsAddress } from "../model/fieldIconAddress.js";
|
|
|
2
2
|
import { declareQuacExtension } from "../model/quacExtension.js";
|
|
3
3
|
import { STAC_VERSION } from "../model/Stac.js";
|
|
4
4
|
import { collectCatalogueCollections } from "../model/stacTreeWalk.js";
|
|
5
|
+
import { readNonBlank } from "../util/nonBlankText.js";
|
|
5
6
|
/**
|
|
6
7
|
* Source-agnostic intermediate model + the single STAC generator that
|
|
7
8
|
* consumes it.
|
|
@@ -84,7 +85,7 @@ const INITIAL_VIEW_FIELD = 'quac:initial_view';
|
|
|
84
85
|
export const QUAC_ACTIVE_COLLECTION_FIELD = 'quac:active_collection';
|
|
85
86
|
/**
|
|
86
87
|
* Records where a catalogue came from as the Catalog's `self` link, so the
|
|
87
|
-
* document says it rather than
|
|
88
|
+
* document says it rather than a reader holding it alongside. Sources with no
|
|
88
89
|
* address of their own leave it off.
|
|
89
90
|
*/
|
|
90
91
|
export function withSelfLink(catalogue, selfHref) {
|
|
@@ -309,7 +310,7 @@ const DATA_TYPE_BY_COLUMN_TYPE = {
|
|
|
309
310
|
/**
|
|
310
311
|
* The column with `data_type` written beside its `type`, as the Table
|
|
311
312
|
* extension recommends. A `type` outside `TableColumnType`, such as a QGIS
|
|
312
|
-
* Server type name
|
|
313
|
+
* Server type name this package does not map, gets no `data_type`.
|
|
313
314
|
*/
|
|
314
315
|
export function withDataType(column) {
|
|
315
316
|
const type = column.type;
|
|
@@ -357,24 +358,30 @@ export function readCatalogueInitialView(catalog) {
|
|
|
357
358
|
*/
|
|
358
359
|
/** The field the source nominates as the layer's title attribute. */
|
|
359
360
|
export function readCollectionDisplayField(collection) {
|
|
360
|
-
|
|
361
|
-
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
361
|
+
return readNonBlank(collection['quac:display_field']);
|
|
362
362
|
}
|
|
363
|
-
/**
|
|
364
|
-
|
|
363
|
+
/**
|
|
364
|
+
* Each entry of a Collection's `table:columns` that is an object with a
|
|
365
|
+
* non-blank `name`, as `[trimmed name, column]`, in declared order. An entry
|
|
366
|
+
* of any other shape, or a `table:columns` that is not a list, yields nothing.
|
|
367
|
+
*/
|
|
368
|
+
function* declaredColumns(collection) {
|
|
365
369
|
const columns = collection['table:columns'];
|
|
366
370
|
if (!Array.isArray(columns))
|
|
367
|
-
return
|
|
368
|
-
const aliases = {};
|
|
371
|
+
return;
|
|
369
372
|
for (const column of columns) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
373
|
+
const candidate = readObject(column);
|
|
374
|
+
const name = readNonBlank(candidate?.name);
|
|
375
|
+
if (candidate && name)
|
|
376
|
+
yield [name, candidate];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/** Field display labels from STAC Table column titles or descriptions. */
|
|
380
|
+
export function readCollectionFieldAliases(collection) {
|
|
381
|
+
const aliases = {};
|
|
382
|
+
for (const [name, column] of declaredColumns(collection)) {
|
|
383
|
+
const alias = readNonBlank(column.title) ?? readNonBlank(column.description);
|
|
384
|
+
if (alias)
|
|
378
385
|
aliases[name] = alias;
|
|
379
386
|
}
|
|
380
387
|
return aliases;
|
|
@@ -386,32 +393,14 @@ export function readCollectionFieldAliases(collection) {
|
|
|
386
393
|
* `collectFieldNames` does not.
|
|
387
394
|
*/
|
|
388
395
|
export function readCollectionFieldNames(collection) {
|
|
389
|
-
|
|
390
|
-
if (!Array.isArray(columns))
|
|
391
|
-
return [];
|
|
392
|
-
const names = [];
|
|
393
|
-
for (const column of columns) {
|
|
394
|
-
if (!column || typeof column !== 'object')
|
|
395
|
-
continue;
|
|
396
|
-
const name = column.name;
|
|
397
|
-
if (typeof name === 'string' && name.trim())
|
|
398
|
-
names.push(name.trim());
|
|
399
|
-
}
|
|
400
|
-
return names;
|
|
396
|
+
return Array.from(declaredColumns(collection), ([name]) => name);
|
|
401
397
|
}
|
|
402
398
|
/** Each declared column `type`, keyed by field name. A column with no `type` is absent. */
|
|
403
399
|
export function readCollectionFieldTypes(collection) {
|
|
404
|
-
const columns = collection['table:columns'];
|
|
405
|
-
if (!Array.isArray(columns))
|
|
406
|
-
return {};
|
|
407
400
|
const types = {};
|
|
408
|
-
for (const column of
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
const candidate = column;
|
|
412
|
-
const name = typeof candidate.name === 'string' ? candidate.name.trim() : '';
|
|
413
|
-
const type = typeof candidate.type === 'string' ? candidate.type.trim() : '';
|
|
414
|
-
if (name && type)
|
|
401
|
+
for (const [name, column] of declaredColumns(collection)) {
|
|
402
|
+
const type = readNonBlank(column.type);
|
|
403
|
+
if (type)
|
|
415
404
|
types[name] = type;
|
|
416
405
|
}
|
|
417
406
|
return types;
|
|
@@ -422,19 +411,12 @@ export function readCollectionFieldTypes(collection) {
|
|
|
422
411
|
* other kind, is dropped, and a column left with no entries is absent.
|
|
423
412
|
*/
|
|
424
413
|
export function readCollectionFieldValues(collection) {
|
|
425
|
-
const columns = collection['table:columns'];
|
|
426
|
-
if (!Array.isArray(columns))
|
|
427
|
-
return {};
|
|
428
414
|
const picklists = {};
|
|
429
|
-
for (const column of
|
|
430
|
-
if (!column
|
|
431
|
-
continue;
|
|
432
|
-
const candidate = column;
|
|
433
|
-
const name = typeof candidate.name === 'string' ? candidate.name.trim() : '';
|
|
434
|
-
if (!name || !Array.isArray(candidate.values))
|
|
415
|
+
for (const [name, column] of declaredColumns(collection)) {
|
|
416
|
+
if (!Array.isArray(column.values))
|
|
435
417
|
continue;
|
|
436
418
|
const entries = [];
|
|
437
|
-
for (const entry of
|
|
419
|
+
for (const entry of column.values) {
|
|
438
420
|
if (!entry || typeof entry !== 'object')
|
|
439
421
|
continue;
|
|
440
422
|
const { value, label, icon } = entry;
|
|
@@ -457,17 +439,10 @@ export function readCollectionFieldValues(collection) {
|
|
|
457
439
|
* `order_field`, reads as ordered by key.
|
|
458
440
|
*/
|
|
459
441
|
export function readCollectionFieldValueRelations(collection) {
|
|
460
|
-
const columns = collection['table:columns'];
|
|
461
|
-
if (!Array.isArray(columns))
|
|
462
|
-
return {};
|
|
463
442
|
const relations = {};
|
|
464
|
-
for (const column of
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
const candidate = column;
|
|
468
|
-
const name = readTrimmedString(candidate.name);
|
|
469
|
-
const declared = candidate['quac:value_relation'];
|
|
470
|
-
if (!name || !declared || typeof declared !== 'object')
|
|
443
|
+
for (const [name, column] of declaredColumns(collection)) {
|
|
444
|
+
const declared = column['quac:value_relation'];
|
|
445
|
+
if (!declared || typeof declared !== 'object')
|
|
471
446
|
continue;
|
|
472
447
|
const entry = declared;
|
|
473
448
|
const lookup = readTrimmedString(entry.collection);
|
|
@@ -571,17 +546,10 @@ export function readCollectionPrivate(collection) {
|
|
|
571
546
|
* omitted or unrecognised `relative_storage` as absolute.
|
|
572
547
|
*/
|
|
573
548
|
export function readCollectionFieldAttachments(collection) {
|
|
574
|
-
const columns = collection['table:columns'];
|
|
575
|
-
if (!Array.isArray(columns))
|
|
576
|
-
return {};
|
|
577
549
|
const attachments = {};
|
|
578
|
-
for (const column of
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
const candidate = column;
|
|
582
|
-
const name = typeof candidate.name === 'string' ? candidate.name.trim() : '';
|
|
583
|
-
const declared = candidate['quac:attachment'];
|
|
584
|
-
if (!name || !declared || typeof declared !== 'object' || Array.isArray(declared))
|
|
550
|
+
for (const [name, column] of declaredColumns(collection)) {
|
|
551
|
+
const declared = column['quac:attachment'];
|
|
552
|
+
if (!declared || typeof declared !== 'object' || Array.isArray(declared))
|
|
585
553
|
continue;
|
|
586
554
|
const fields = declared;
|
|
587
555
|
attachments[name] = {
|
|
@@ -598,11 +566,12 @@ export function readCollectionFieldAttachments(collection) {
|
|
|
598
566
|
/**
|
|
599
567
|
* What each column says about changing it, keyed by field name — the
|
|
600
568
|
* counterpart of the `quac:editable`, `quac:default`,
|
|
601
|
-
* `quac:constraints`, `quac:hidden` and
|
|
569
|
+
* `quac:constraints`, `quac:hidden`, `quac:searchable` and
|
|
602
570
|
* `quac:reuse_last_value` writes in `stacCatalogue.ts`. A column
|
|
603
571
|
* declaring none of them is absent from the result.
|
|
604
572
|
*
|
|
605
|
-
* Only `quac:editable: false` makes a field read-only,
|
|
573
|
+
* Only `quac:editable: false` makes a field read-only, only
|
|
574
|
+
* `quac:searchable: false` keeps it out of a search, and only
|
|
606
575
|
* `quac:hidden: true`, `quac:reuse_last_value: true` and `quac:color: true`
|
|
607
576
|
* set theirs. A `quac:icon` that is not an `https://` address is left out, as
|
|
608
577
|
* is a `quac:control` other than `buttons` or `dropdown`.
|
|
@@ -614,18 +583,9 @@ export function readCollectionFieldAttachments(collection) {
|
|
|
614
583
|
* with no expression text is left out.
|
|
615
584
|
*/
|
|
616
585
|
export function readCollectionFieldEditRules(collection) {
|
|
617
|
-
const columns = collection['table:columns'];
|
|
618
|
-
if (!Array.isArray(columns))
|
|
619
|
-
return {};
|
|
620
586
|
const relations = readCollectionFieldValueRelations(collection);
|
|
621
587
|
const rules = {};
|
|
622
|
-
for (const
|
|
623
|
-
if (!column || typeof column !== 'object')
|
|
624
|
-
continue;
|
|
625
|
-
const candidate = column;
|
|
626
|
-
const name = typeof candidate.name === 'string' ? candidate.name.trim() : '';
|
|
627
|
-
if (!name)
|
|
628
|
-
continue;
|
|
588
|
+
for (const [name, candidate] of declaredColumns(collection)) {
|
|
629
589
|
const readOnly = candidate['quac:editable'] === false;
|
|
630
590
|
const defaultValue = readColumnDefault(candidate['quac:default']);
|
|
631
591
|
const constraints = readObject(candidate['quac:constraints']);
|
|
@@ -641,13 +601,14 @@ export function readCollectionFieldEditRules(collection) {
|
|
|
641
601
|
const range = readColumnRange(candidate['quac:range']);
|
|
642
602
|
const dateFormat = readNonBlank(candidate['quac:date_format']);
|
|
643
603
|
const colour = candidate['quac:color'] === true;
|
|
604
|
+
const notSearchable = candidate['quac:searchable'] === false;
|
|
644
605
|
const icon = readHttpsAddress(candidate['quac:icon']);
|
|
645
606
|
const control = candidate['quac:control'] === 'buttons' || candidate['quac:control'] === 'dropdown' ? candidate['quac:control'] : null;
|
|
646
607
|
const defaultExpression = readDefaultExpression(candidate['quac:default']);
|
|
647
608
|
const relation = relations[name];
|
|
648
609
|
// A field storing several keys gets no list, so no rule about its blank choice.
|
|
649
610
|
const valueRelation = relation && relation.allow_multi !== true ? { allowNull: relation.allow_null === true, relation } : null;
|
|
650
|
-
if (valueRelation || readOnly || defaultValue || defaultExpression || notNull || unique || constraintExpression || hidden || reuseLastValue || duplicatePolicy || checkbox || range || dateFormat || colour || icon || control) {
|
|
611
|
+
if (valueRelation || readOnly || defaultValue || defaultExpression || notNull || unique || constraintExpression || hidden || reuseLastValue || duplicatePolicy || checkbox || range || dateFormat || colour || notSearchable || icon || control) {
|
|
651
612
|
rules[name] = {
|
|
652
613
|
readOnly, defaultValue, notNull, unique, hidden, reuseLastValue, duplicatePolicy,
|
|
653
614
|
...(constraintExpression ? { constraintExpression } : {}),
|
|
@@ -656,6 +617,7 @@ export function readCollectionFieldEditRules(collection) {
|
|
|
656
617
|
...(range ? { range } : {}),
|
|
657
618
|
...(dateFormat ? { dateFormat } : {}),
|
|
658
619
|
...(colour ? { colour } : {}),
|
|
620
|
+
...(notSearchable ? { notSearchable } : {}),
|
|
659
621
|
...(icon ? { icon } : {}),
|
|
660
622
|
...(control ? { control } : {}),
|
|
661
623
|
...(valueRelation ? { valueRelation } : {})
|
|
@@ -680,14 +642,7 @@ export function readCollectionFormLayout(collection) {
|
|
|
680
642
|
const order = collection[QUAC_FORM_ORDER_FIELD];
|
|
681
643
|
if (!Array.isArray(order))
|
|
682
644
|
return null;
|
|
683
|
-
const columns = new Map();
|
|
684
|
-
const declared = collection['table:columns'];
|
|
685
|
-
for (const column of Array.isArray(declared) ? declared : []) {
|
|
686
|
-
const candidate = readObject(column);
|
|
687
|
-
const name = readNonBlank(candidate?.name);
|
|
688
|
-
if (candidate && name)
|
|
689
|
-
columns.set(name, candidate);
|
|
690
|
-
}
|
|
645
|
+
const columns = new Map(declaredColumns(collection));
|
|
691
646
|
const fields = [];
|
|
692
647
|
const placed = new Set();
|
|
693
648
|
for (const entry of order) {
|
|
@@ -769,9 +724,6 @@ function readObject(value) {
|
|
|
769
724
|
}
|
|
770
725
|
const ATTACHMENT_VIEWERS = ['image', 'web', 'audio', 'video'];
|
|
771
726
|
const ATTACHMENT_RELATIVE_STORAGE = ['absolute', 'project', 'default-root'];
|
|
772
|
-
function readNonBlank(value) {
|
|
773
|
-
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
774
|
-
}
|
|
775
727
|
/** Whether the source declares the layer editable. */
|
|
776
728
|
export function readCollectionEditable(collection) {
|
|
777
729
|
const value = collection['quac:editable'];
|
|
@@ -104,7 +104,7 @@ function buildAssets(itemsUrl, tilesUrl, title) {
|
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* The collection's tile template, absolute, or null where it publishes none
|
|
107
|
-
* this
|
|
107
|
+
* this package reads.
|
|
108
108
|
*
|
|
109
109
|
* Only a `{z}`/`{x}`/`{y}` template counts. A `tiles` link is also how a
|
|
110
110
|
* service points at an OGC API - Tiles tileset document, which describes its
|
|
@@ -10,6 +10,7 @@ import { buildWmsLink, WEB_MAP_LINKS_EXTENSION } from "../model/stacWms.js";
|
|
|
10
10
|
import { buildWmtsLink } from "../model/stacWmts.js";
|
|
11
11
|
import { buildXyzLink } from "../model/stacXyz.js";
|
|
12
12
|
import { findGeometrySiblings, readSiblingShapes, siblingCollectionId } from "../parse/geometrySiblings.js";
|
|
13
|
+
import { findValueRelationLookup, isFilterInProject, isRelationInProject } from "../parse/projectNotes.js";
|
|
13
14
|
import { declaredMediaTypeForFile, isLayerFileOfFormat, PROJECT_DATA_ROLES, QML_STYLE_MEDIA_TYPE } from "../util/catalogueFileFormats.js";
|
|
14
15
|
/**
|
|
15
16
|
* Generates a STAC Catalog tree from a parsed QgsProject.
|
|
@@ -37,7 +38,9 @@ export function generateStacCatalogue(project, companions = [], options = {}) {
|
|
|
37
38
|
// the layers' style assets address into — a path, not an href, so the
|
|
38
39
|
// generator is the one place that escapes it. A caller that doesn't know
|
|
39
40
|
// where the project file sits leaves it off, and the style assets fall back
|
|
40
|
-
// to a bare fragment — see `buildStyleAssets
|
|
41
|
+
// to a bare fragment — see `buildStyleAssets` — which only a reader already
|
|
42
|
+
// holding the project can follow. A catalogue to be published or saved apart
|
|
43
|
+
// from the project needs both `selfHref` and `projectPath`.
|
|
41
44
|
//
|
|
42
45
|
// `projectFileName` is the project file's name for each layer's `via` link
|
|
43
46
|
// alone, where the caller knows it but leaves `projectPath` off, as the drop
|
|
@@ -163,9 +166,10 @@ function qgsProjectToNormalized(project, companions, projectPath, projectFileNam
|
|
|
163
166
|
*/
|
|
164
167
|
function collectFiltersByCollectionId(filters, layersById, collectionIdOf) {
|
|
165
168
|
const byCollectionId = new Map();
|
|
166
|
-
for (const
|
|
167
|
-
if (!layersById
|
|
169
|
+
for (const filter of filters) {
|
|
170
|
+
if (!isFilterInProject(filter, layersById))
|
|
168
171
|
continue;
|
|
172
|
+
const { layerId, field, name } = filter;
|
|
169
173
|
const collectionId = collectionIdOf(layerId);
|
|
170
174
|
byCollectionId.set(collectionId, [...(byCollectionId.get(collectionId) ?? []), { field, name }]);
|
|
171
175
|
}
|
|
@@ -183,7 +187,7 @@ function collectFiltersByCollectionId(filters, layersById, collectionIdOf) {
|
|
|
183
187
|
function collectRelationsByChildLayerId(relations, layersById, collectionIdOf) {
|
|
184
188
|
const byChildLayerId = new Map();
|
|
185
189
|
for (const relation of relations) {
|
|
186
|
-
if (!
|
|
190
|
+
if (!isRelationInProject(relation, layersById))
|
|
187
191
|
continue;
|
|
188
192
|
const childCollectionId = collectionIdOf(relation.childLayerId);
|
|
189
193
|
const forChild = byChildLayerId.get(childCollectionId) ?? [];
|
|
@@ -199,10 +203,8 @@ function collectRelationsByChildLayerId(relations, layersById, collectionIdOf) {
|
|
|
199
203
|
}
|
|
200
204
|
/**
|
|
201
205
|
* Each layer's Value Relation widgets as `quac:value_relation` writes
|
|
202
|
-
* them, keyed by layer id and then field name. The lookup is found
|
|
203
|
-
*
|
|
204
|
-
* (`QgsVectorLayerRef::resolveByIdOrNameOnly`, `src/core/qgsvectorlayerref.cpp`,
|
|
205
|
-
* `qgis/QGIS@master`); its Collection id is its layer id. A widget naming a
|
|
206
|
+
* them, keyed by layer id and then field name. The lookup is found as
|
|
207
|
+
* `findValueRelationLookup` finds it; its Collection id is its layer id. A widget naming a
|
|
206
208
|
* layer the project does not hold writes nothing, since it would point at a
|
|
207
209
|
* Collection this catalogue has no entry for.
|
|
208
210
|
*/
|
|
@@ -211,7 +213,7 @@ function collectValueRelationsByLayerId(layers, layersById, collectionIdOf) {
|
|
|
211
213
|
for (const layer of layers) {
|
|
212
214
|
const relations = {};
|
|
213
215
|
for (const [field, widget] of Object.entries(layer.fieldValueRelations)) {
|
|
214
|
-
const lookup =
|
|
216
|
+
const lookup = findValueRelationLookup(widget, layers, layersById);
|
|
215
217
|
if (lookup)
|
|
216
218
|
relations[field] = valueRelationToJson(collectionIdOf(lookup.id), widget);
|
|
217
219
|
}
|
|
@@ -364,8 +366,8 @@ function qgsLayerToNormalized(layer, context, geometryFilter = geometryFilterOf(
|
|
|
364
366
|
displayField: layer.displayField,
|
|
365
367
|
visibilityChecked: layer.isVisible,
|
|
366
368
|
// An image layer has no features to edit. An ArcGIS layer keeps the
|
|
367
|
-
// project's own Read-only tick:
|
|
368
|
-
// service is
|
|
369
|
+
// project's own Read-only tick: whether edits are written back to the
|
|
370
|
+
// service is left to the application reading the catalogue.
|
|
369
371
|
editable: ds.kind === 'wms' || ds.kind === 'wmts' || ds.kind === 'xyz' ? false : layer.editable,
|
|
370
372
|
identifiable: layer.queryable,
|
|
371
373
|
scaleRange: layer.scaleRange,
|
|
@@ -546,16 +548,11 @@ function buildAssets(layer, geometryFilter) {
|
|
|
546
548
|
}
|
|
547
549
|
};
|
|
548
550
|
}
|
|
549
|
-
//
|
|
550
|
-
//
|
|
551
|
-
// hold a user name and
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
href: '',
|
|
555
|
-
title: `Unsupported source: ${ds.hint ?? 'unknown'}`,
|
|
556
|
-
roles: ['data']
|
|
557
|
-
}
|
|
558
|
-
};
|
|
551
|
+
// A source the catalogue cannot address, such as a database, has no data
|
|
552
|
+
// asset: STAC requires an asset's href, and the source's own address is not
|
|
553
|
+
// written because a database connection string can hold a user name and
|
|
554
|
+
// password. The project's `source` note names the provider.
|
|
555
|
+
return {};
|
|
559
556
|
}
|
|
560
557
|
/**
|
|
561
558
|
* Declares a layer's named styles as `style` assets, one per style the project
|
|
@@ -694,6 +691,9 @@ function unionExtent(layers, layerWgs84Extents) {
|
|
|
694
691
|
* with, that it must not be blank, that the form never
|
|
695
692
|
* shows it, and that a new feature is offered its last
|
|
696
693
|
* value, from QGIS's Attributes Form
|
|
694
|
+
* - **quac:searchable**
|
|
695
|
+
* that a search of the layer's features skips the field,
|
|
696
|
+
* from QGIS's Not searchable in the Fields tab
|
|
697
697
|
* - **quac:color** that the field holds a colour, when QGIS's Color edit
|
|
698
698
|
* widget declares one
|
|
699
699
|
* - **quac:visible_when** / **quac:in_form** / **quac:editable_when**
|
|
@@ -778,6 +778,8 @@ function deriveTableColumns(geojson, fieldNames, fieldAliases, fieldValueMaps =
|
|
|
778
778
|
}
|
|
779
779
|
if (editRule?.hidden)
|
|
780
780
|
column['quac:hidden'] = true;
|
|
781
|
+
if (editRule?.notSearchable)
|
|
782
|
+
column['quac:searchable'] = false;
|
|
781
783
|
if (editRule?.reuseLastValue)
|
|
782
784
|
column['quac:reuse_last_value'] = true;
|
|
783
785
|
if (editRule?.duplicatePolicy)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { slugify, generateStacFromNormalized } from "./normalizedProject.js";
|
|
2
2
|
import { wfsGetFeatureAsset } from "./wfsStacCatalogue.js";
|
|
3
3
|
import { chooseWmsCrs, WEB_MAP_LINKS_EXTENSION, wmsEndpoint } from "../model/stacWms.js";
|
|
4
|
-
import { GEOJSON_MEDIA_TYPE } from "../util/catalogueFileFormats.js";
|
|
5
4
|
export function generateStacCatalogueFromWms(project, options = {}) {
|
|
6
5
|
return generateStacFromNormalized(wmsProjectToNormalized(project, options));
|
|
7
6
|
}
|
|
@@ -87,7 +86,8 @@ function wmsLayerToNormalized(layer, wfsSource) {
|
|
|
87
86
|
/**
|
|
88
87
|
* A GetMap link for a layer QGIS Server publishes only over WMS. The style is
|
|
89
88
|
* left empty, which asks the server for the layer's default style. No version
|
|
90
|
-
* is stated, so the
|
|
89
|
+
* is stated, so an application reading the catalogue asks the server for one
|
|
90
|
+
* when the layer is first shown.
|
|
91
91
|
*/
|
|
92
92
|
function buildQgisServerWmsLink(endpoint, layer) {
|
|
93
93
|
return {
|
|
@@ -144,20 +144,9 @@ function wmsBboxToNormalized(bbox) {
|
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
function buildAssets(layer, wfsSource) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// server-specific and is constructed by the QgisServerAdapter at fetch
|
|
151
|
-
// time, so the asset entry only documents that the data is available.
|
|
152
|
-
return {
|
|
153
|
-
data: {
|
|
154
|
-
href: '',
|
|
155
|
-
type: GEOJSON_MEDIA_TYPE,
|
|
156
|
-
// Text written into the catalogue document, which carries the project's own name.
|
|
157
|
-
title: `WFS GetFeature: ${layer.name}`,
|
|
158
|
-
roles: ['data']
|
|
159
|
-
}
|
|
160
|
-
};
|
|
147
|
+
// A layer with no WFS type name has no address to fetch its features from,
|
|
148
|
+
// and STAC requires an asset's href, so it has no data asset.
|
|
149
|
+
return wfsSource?.typeName ? { data: wfsGetFeatureAsset(wfsSource.endpoint, wfsSource.typeName, layer.name) } : {};
|
|
161
150
|
}
|
|
162
151
|
/**
|
|
163
152
|
* Maps QGIS Qt types from GetProjectSettings into STAC Table extension
|