@vectoriahq/quac 0.4.0 → 0.6.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/dist/generate/arcgisStacCatalogue.js +1 -1
- package/dist/generate/normalizedProject.d.ts +1 -1
- package/dist/generate/normalizedProject.js +25 -16
- package/dist/generate/serverStacCatalogue.js +6 -4
- package/dist/generate/stacCatalogue.js +1 -1
- package/dist/model/Stac.d.ts +1 -1
- package/dist/model/quacExtension.d.ts +1 -1
- package/dist/model/quacExtension.js +1 -1
- package/dist/model/stacTreeWalk.d.ts +12 -2
- package/dist/model/stacTreeWalk.js +42 -8
- package/dist/parse/parseQgsXml.d.ts +2 -1
- package/dist/parse/parseQgsXml.js +8 -1
- package/dist/parse/qgisExpression.d.ts +16 -6
- package/dist/parse/qgisExpression.js +40 -12
- package/package.json +1 -2
- package/src/schema/quac.schema.json +28 -1
|
@@ -165,7 +165,7 @@ function fieldToColumn(field) {
|
|
|
165
165
|
if (field.type && Object.hasOwn(ESRI_COLUMN_TYPES, field.type))
|
|
166
166
|
column.type = ESRI_COLUMN_TYPES[field.type];
|
|
167
167
|
if (field.codedValues)
|
|
168
|
-
column
|
|
168
|
+
column['quac:values'] = field.codedValues.map(({ code, name }) => ({ value: code, label: name }));
|
|
169
169
|
// A range on a date field is in epoch milliseconds, which is no number a form could limit.
|
|
170
170
|
if (field.range && (column.type === 'int' || column.type === 'long' || column.type === 'double')) {
|
|
171
171
|
column['quac:range'] = { min: field.range.min, max: field.range.max };
|
|
@@ -313,7 +313,7 @@ export declare function readCollectionFieldNames(collection: StacCollection): st
|
|
|
313
313
|
/** Each declared column `type`, keyed by field name. A column with no `type` is absent. */
|
|
314
314
|
export declare function readCollectionFieldTypes(collection: StacCollection): Record<string, string>;
|
|
315
315
|
/**
|
|
316
|
-
* Each column's `values` picklist, keyed by field name. A value is returned as
|
|
316
|
+
* Each column's `quac:values` picklist, keyed by field name. A value is returned as
|
|
317
317
|
* stored, string or number. An entry with no label, or with a value of any
|
|
318
318
|
* other kind, is dropped, and a column left with no entries is absent.
|
|
319
319
|
*/
|
|
@@ -106,7 +106,7 @@ export function withSelfLink(catalogue, selfHref) {
|
|
|
106
106
|
* layer nodes → Collections
|
|
107
107
|
*/
|
|
108
108
|
export function generateStacFromNormalized(project) {
|
|
109
|
-
const { collections, catalogs, links } = walkNodes(project.nodes, project.providers ?? []);
|
|
109
|
+
const { collections, catalogs, links } = walkNodes(project.nodes, project.providers ?? [], './');
|
|
110
110
|
const catalog = {
|
|
111
111
|
type: 'Catalog',
|
|
112
112
|
stac_version: STAC_VERSION,
|
|
@@ -139,23 +139,31 @@ export function generateStacFromNormalized(project) {
|
|
|
139
139
|
}
|
|
140
140
|
return declareQuacExtension(catalog);
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Every relative href in the catalogue starts from the top-level document, the
|
|
144
|
+
* one document that holds the whole tree. `folder` is where the Catalog
|
|
145
|
+
* holding `nodes` would sit as a file of its own, relative to that document:
|
|
146
|
+
* `./` for the top level and `./catalogs/<id>/` for a group, nested group by
|
|
147
|
+
* group.
|
|
148
|
+
*/
|
|
149
|
+
function walkNodes(nodes, defaultProviders, folder) {
|
|
143
150
|
const collections = [];
|
|
144
151
|
const catalogs = [];
|
|
145
152
|
const links = [];
|
|
146
153
|
for (const node of nodes) {
|
|
147
154
|
if (node.kind === 'layer') {
|
|
148
|
-
const collection = buildCollection(node, defaultProviders);
|
|
155
|
+
const collection = buildCollection(node, defaultProviders, folder);
|
|
149
156
|
collections.push(collection);
|
|
150
157
|
links.push({
|
|
151
158
|
rel: 'child',
|
|
152
|
-
href:
|
|
159
|
+
href: `${folder}collections/${collection.id}.json`,
|
|
153
160
|
type: 'application/json',
|
|
154
161
|
title: collection.title
|
|
155
162
|
});
|
|
156
163
|
}
|
|
157
164
|
else {
|
|
158
|
-
const
|
|
165
|
+
const groupFolder = `${folder}catalogs/${node.id}/`;
|
|
166
|
+
const sub = walkNodes(node.children, defaultProviders, groupFolder);
|
|
159
167
|
const subCatalog = {
|
|
160
168
|
type: 'Catalog',
|
|
161
169
|
stac_version: STAC_VERSION,
|
|
@@ -163,9 +171,9 @@ function walkNodes(nodes, defaultProviders) {
|
|
|
163
171
|
title: node.title || undefined,
|
|
164
172
|
description: node.description,
|
|
165
173
|
links: [
|
|
166
|
-
{ rel: 'self', href:
|
|
167
|
-
{ rel: 'parent', href:
|
|
168
|
-
{ rel: 'root', href: '
|
|
174
|
+
{ rel: 'self', href: `${groupFolder}catalog.json` },
|
|
175
|
+
{ rel: 'parent', href: `${folder}catalog.json` },
|
|
176
|
+
{ rel: 'root', href: './catalog.json' },
|
|
169
177
|
...sub.links
|
|
170
178
|
]
|
|
171
179
|
};
|
|
@@ -178,7 +186,7 @@ function walkNodes(nodes, defaultProviders) {
|
|
|
178
186
|
catalogs.push(subCatalog);
|
|
179
187
|
links.push({
|
|
180
188
|
rel: 'child',
|
|
181
|
-
href:
|
|
189
|
+
href: `${groupFolder}catalog.json`,
|
|
182
190
|
type: 'application/json',
|
|
183
191
|
title: node.title
|
|
184
192
|
});
|
|
@@ -186,7 +194,7 @@ function walkNodes(nodes, defaultProviders) {
|
|
|
186
194
|
}
|
|
187
195
|
return { collections, catalogs, links };
|
|
188
196
|
}
|
|
189
|
-
function buildCollection(layer, defaultProviders) {
|
|
197
|
+
function buildCollection(layer, defaultProviders, folder) {
|
|
190
198
|
const stacExtensions = [...(layer.extensions ?? [])];
|
|
191
199
|
if (layer.tableColumns.length > 0) {
|
|
192
200
|
stacExtensions.push(TABLE_EXTENSION);
|
|
@@ -212,9 +220,9 @@ function buildCollection(layer, defaultProviders) {
|
|
|
212
220
|
summaries: Object.keys(summaries).length > 0 ? summaries : undefined,
|
|
213
221
|
assets: layer.assets,
|
|
214
222
|
links: [
|
|
215
|
-
{ rel: 'self', href:
|
|
216
|
-
{ rel: 'parent', href:
|
|
217
|
-
{ rel: 'root', href: '
|
|
223
|
+
{ rel: 'self', href: `${folder}collections/${layer.id}.json` },
|
|
224
|
+
{ rel: 'parent', href: `${folder}catalog.json` },
|
|
225
|
+
{ rel: 'root', href: './catalog.json' },
|
|
218
226
|
...(layer.links ?? [])
|
|
219
227
|
]
|
|
220
228
|
};
|
|
@@ -409,17 +417,18 @@ export function readCollectionFieldTypes(collection) {
|
|
|
409
417
|
return types;
|
|
410
418
|
}
|
|
411
419
|
/**
|
|
412
|
-
* Each column's `values` picklist, keyed by field name. A value is returned as
|
|
420
|
+
* Each column's `quac:values` picklist, keyed by field name. A value is returned as
|
|
413
421
|
* stored, string or number. An entry with no label, or with a value of any
|
|
414
422
|
* other kind, is dropped, and a column left with no entries is absent.
|
|
415
423
|
*/
|
|
416
424
|
export function readCollectionFieldValues(collection) {
|
|
417
425
|
const picklists = {};
|
|
418
426
|
for (const [name, column] of declaredColumns(collection)) {
|
|
419
|
-
|
|
427
|
+
const declared = column['quac:values'];
|
|
428
|
+
if (!Array.isArray(declared))
|
|
420
429
|
continue;
|
|
421
430
|
const entries = [];
|
|
422
|
-
for (const entry of
|
|
431
|
+
for (const entry of declared) {
|
|
423
432
|
if (!entry || typeof entry !== 'object')
|
|
424
433
|
continue;
|
|
425
434
|
const { value, label, icon } = entry;
|
|
@@ -5,6 +5,7 @@ import { wfsGetFeatureAsset } from "./wfsStacCatalogue.js";
|
|
|
5
5
|
import { mapQtTypeToStacTableType } from "./wmsStacCatalogue.js";
|
|
6
6
|
import { declareQuacExtension, QUAC_SCHEMA_URL } from "../model/quacExtension.js";
|
|
7
7
|
import { PROJECTION_EXTENSION } from "../model/stacProjection.js";
|
|
8
|
+
import { catalogueFolder } from "../model/stacTreeWalk.js";
|
|
8
9
|
import { chooseWmsCrs, WEB_MAP_LINKS_EXTENSION, WMS_REQUEST_PARAMETERS } from "../model/stacWms.js";
|
|
9
10
|
/**
|
|
10
11
|
* The catalogue a QGIS Server would serve for a project: the QUAC plugin's
|
|
@@ -85,7 +86,7 @@ export function generateServerStacCatalogue(project, options) {
|
|
|
85
86
|
const serveCatalog = (node) => {
|
|
86
87
|
const collections = (node.collections ?? []).filter((collection) => servedIds.has(collection.id)).map((collection) => serveCollection(collection, context));
|
|
87
88
|
const catalogs = (node.catalogs ?? []).filter((child) => !restricted.has(child.title ?? '')).map(serveCatalog);
|
|
88
|
-
const served = { ...node, links: [...node.links.filter((link) => link.rel !== 'child'), ...childLinks(collections, catalogs)] };
|
|
89
|
+
const served = { ...node, links: [...node.links.filter((link) => link.rel !== 'child'), ...childLinks(catalogueFolder(node) ?? './', collections, catalogs)] };
|
|
89
90
|
delete served.collections;
|
|
90
91
|
delete served.catalogs;
|
|
91
92
|
delete served.stac_extensions;
|
|
@@ -154,10 +155,11 @@ export function serverWmsCrsList(project) {
|
|
|
154
155
|
crsList.push('EPSG:3857');
|
|
155
156
|
return crsList;
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
+
/** A served Catalog's child links, from the top-level document as every relative href is: `folder` is the Catalog's own. */
|
|
159
|
+
function childLinks(folder, collections, catalogs) {
|
|
158
160
|
return [
|
|
159
|
-
...collections.map((collection) => ({ rel: 'child', href:
|
|
160
|
-
...catalogs.map((catalog) => ({ rel: 'child', href:
|
|
161
|
+
...collections.map((collection) => ({ rel: 'child', href: `${folder}collections/${encodeURIComponent(collection.id)}.json`, type: 'application/json', title: collection.title })),
|
|
162
|
+
...catalogs.map((catalog) => ({ rel: 'child', href: `${folder}catalogs/${encodeURIComponent(catalog.id)}/catalog.json`, type: 'application/json', title: catalog.title }))
|
|
161
163
|
];
|
|
162
164
|
}
|
|
163
165
|
/** The fields of a layer QGIS Server hides from either service. */
|
|
@@ -765,7 +765,7 @@ function deriveTableColumns(geojson, fieldNames, fieldAliases, fieldValueMaps =
|
|
|
765
765
|
column.title = alias;
|
|
766
766
|
const values = fieldValueMaps[name];
|
|
767
767
|
if (values)
|
|
768
|
-
column
|
|
768
|
+
column['quac:values'] = values;
|
|
769
769
|
const valueRelation = fieldValueRelations[name];
|
|
770
770
|
if (valueRelation)
|
|
771
771
|
column['quac:value_relation'] = valueRelation;
|
package/dist/model/Stac.d.ts
CHANGED
|
@@ -143,7 +143,7 @@ export interface TableColumn {
|
|
|
143
143
|
data_type?: TableColumnDataType;
|
|
144
144
|
description?: string;
|
|
145
145
|
/** The values the source restricts the field to: a QGIS ValueMap widget or an ArcGIS coded-value domain. */
|
|
146
|
-
values?: TableColumnValue[];
|
|
146
|
+
'quac:values'?: TableColumnValue[];
|
|
147
147
|
/** Declares that the column holds a file's path rather than a value of its own. */
|
|
148
148
|
'quac:attachment'?: TableColumnAttachment;
|
|
149
149
|
/** Declares that the column's choices are the records of another Collection of the same catalogue. */
|
|
@@ -4,7 +4,7 @@ import type { StacCatalog, StacCollection } from './Stac.ts';
|
|
|
4
4
|
* `stac_extensions` to say which QUAC it follows. Written from this one
|
|
5
5
|
* constant, so the address changes in one place when the schema moves.
|
|
6
6
|
*/
|
|
7
|
-
export declare const QUAC_SCHEMA_URL = "https://vectoriahq.github.io/quac/v0.
|
|
7
|
+
export declare const QUAC_SCHEMA_URL = "https://vectoriahq.github.io/quac/v0.3.0/schema.json";
|
|
8
8
|
/**
|
|
9
9
|
* The QUAC version a document declares, such as `0.1.0`, read from the QUAC
|
|
10
10
|
* schema address in its `stac_extensions`. Null where it lists none.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* `stac_extensions` to say which QUAC it follows. Written from this one
|
|
4
4
|
* constant, so the address changes in one place when the schema moves.
|
|
5
5
|
*/
|
|
6
|
-
export const QUAC_SCHEMA_URL = 'https://vectoriahq.github.io/quac/v0.
|
|
6
|
+
export const QUAC_SCHEMA_URL = 'https://vectoriahq.github.io/quac/v0.3.0/schema.json';
|
|
7
7
|
// A QUAC schema address is a folder named for its version, holding the
|
|
8
8
|
// schema file `QUAC_SCHEMA_URL` names. Only the path is matched, not the host.
|
|
9
9
|
const QUAC_SCHEMA_FILE = QUAC_SCHEMA_URL.slice(QUAC_SCHEMA_URL.lastIndexOf('/'));
|
|
@@ -6,8 +6,10 @@ import type { StacCatalog, StacCollection } from './Stac.ts';
|
|
|
6
6
|
*
|
|
7
7
|
* A Catalog holds its child Collections and child Catalogs in two separate
|
|
8
8
|
* arrays, so the interleaving is read back from the `rel: "child"` links,
|
|
9
|
-
* which the generator writes in source order
|
|
10
|
-
*
|
|
9
|
+
* which the generator writes in source order, from the top-level document:
|
|
10
|
+
* `{folder}collections/{id}.json` for a Collection and
|
|
11
|
+
* `{folder}catalogs/{id}/catalog.json` for a group, where `{folder}` is the
|
|
12
|
+
* Catalog's own, as `catalogueFolder` reads it. A child whose link
|
|
11
13
|
* cannot be matched — an external document with its own link shapes — is
|
|
12
14
|
* appended after the linked ones, so nothing is dropped and external
|
|
13
15
|
* catalogues degrade to "Collections first, then groups" order.
|
|
@@ -34,3 +36,11 @@ export type CatalogueChild = {
|
|
|
34
36
|
* describes. The basemap picker offers these as its choices.
|
|
35
37
|
*/
|
|
36
38
|
export declare function listCatalogueChildren(catalog: StacCatalog): CatalogueChild[];
|
|
39
|
+
/**
|
|
40
|
+
* Where a Catalog would sit as a file of its own, relative to the top-level
|
|
41
|
+
* document, read from its `self` link: `./` for `./catalog.json`, and
|
|
42
|
+
* `./catalogs/roads/` for `./catalogs/roads/catalog.json`. Null where the
|
|
43
|
+
* `self` link is absent or names some other file, such as a catalogue another
|
|
44
|
+
* application published.
|
|
45
|
+
*/
|
|
46
|
+
export declare function catalogueFolder(catalog: StacCatalog): string | null;
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
*
|
|
6
6
|
* A Catalog holds its child Collections and child Catalogs in two separate
|
|
7
7
|
* arrays, so the interleaving is read back from the `rel: "child"` links,
|
|
8
|
-
* which the generator writes in source order
|
|
9
|
-
*
|
|
8
|
+
* which the generator writes in source order, from the top-level document:
|
|
9
|
+
* `{folder}collections/{id}.json` for a Collection and
|
|
10
|
+
* `{folder}catalogs/{id}/catalog.json` for a group, where `{folder}` is the
|
|
11
|
+
* Catalog's own, as `catalogueFolder` reads it. A child whose link
|
|
10
12
|
* cannot be matched — an external document with its own link shapes — is
|
|
11
13
|
* appended after the linked ones, so nothing is dropped and external
|
|
12
14
|
* catalogues degrade to "Collections first, then groups" order.
|
|
@@ -29,12 +31,13 @@ export function collectCatalogueCollections(catalog) {
|
|
|
29
31
|
export function listCatalogueChildren(catalog) {
|
|
30
32
|
const collections = catalog.collections ?? [];
|
|
31
33
|
const catalogs = catalog.catalogs ?? [];
|
|
34
|
+
const folder = catalogueFolder(catalog);
|
|
32
35
|
const visited = new Set();
|
|
33
36
|
const out = [];
|
|
34
37
|
for (const link of catalog.links ?? []) {
|
|
35
38
|
if (link.rel !== 'child')
|
|
36
39
|
continue;
|
|
37
|
-
const collectionId =
|
|
40
|
+
const collectionId = matchChildId(link.href, folder, 'collections/', '.json');
|
|
38
41
|
if (collectionId !== null) {
|
|
39
42
|
const collection = firstUnvisited(collections, collectionId, visited);
|
|
40
43
|
if (collection) {
|
|
@@ -43,7 +46,7 @@ export function listCatalogueChildren(catalog) {
|
|
|
43
46
|
continue;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
|
-
const catalogId =
|
|
49
|
+
const catalogId = matchChildId(link.href, folder, 'catalogs/', '/catalog.json');
|
|
47
50
|
if (catalogId !== null) {
|
|
48
51
|
const child = firstUnvisited(catalogs, catalogId, visited);
|
|
49
52
|
if (child) {
|
|
@@ -69,8 +72,39 @@ function firstUnvisited(items, id, visited) {
|
|
|
69
72
|
}
|
|
70
73
|
return null;
|
|
71
74
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Where a Catalog would sit as a file of its own, relative to the top-level
|
|
77
|
+
* document, read from its `self` link: `./` for `./catalog.json`, and
|
|
78
|
+
* `./catalogs/roads/` for `./catalogs/roads/catalog.json`. Null where the
|
|
79
|
+
* `self` link is absent or names some other file, such as a catalogue another
|
|
80
|
+
* application published.
|
|
81
|
+
*/
|
|
82
|
+
export function catalogueFolder(catalog) {
|
|
83
|
+
const self = (catalog.links ?? []).find((link) => link.rel === 'self')?.href;
|
|
84
|
+
if (!self || (self !== 'catalog.json' && !self.endsWith('/catalog.json')))
|
|
85
|
+
return null;
|
|
86
|
+
return self.slice(0, self.length - 'catalog.json'.length);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The id in a child link written as `{folder}{prefix}{id}{suffix}`. Ids are
|
|
90
|
+
* written into hrefs verbatim, and an id can hold a `/`, such as a folder
|
|
91
|
+
* source's path, so the id is what lies between the Catalog's own folder and
|
|
92
|
+
* the suffix. An href outside that folder, such as another application's, is
|
|
93
|
+
* matched from its first `/{prefix}` instead.
|
|
94
|
+
*/
|
|
95
|
+
function matchChildId(href, folder, prefix, suffix) {
|
|
96
|
+
if (!href.endsWith(suffix))
|
|
97
|
+
return null;
|
|
98
|
+
let start;
|
|
99
|
+
if (folder !== null && href.startsWith(`${folder}${prefix}`)) {
|
|
100
|
+
start = folder.length + prefix.length;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const at = href.indexOf(`/${prefix}`);
|
|
104
|
+
if (at < 0)
|
|
105
|
+
return null;
|
|
106
|
+
start = at + 1 + prefix.length;
|
|
107
|
+
}
|
|
108
|
+
const id = href.slice(start, href.length - suffix.length);
|
|
109
|
+
return start <= href.length - suffix.length && id ? id : null;
|
|
76
110
|
}
|
|
@@ -9,7 +9,8 @@ import type { QgsProject } from '../model/QgsProject.ts';
|
|
|
9
9
|
* 3. Each sub-parser handles one concern and isolates its own failures —
|
|
10
10
|
* a malformed legend tree shouldn't take down the layer list, etc.
|
|
11
11
|
*
|
|
12
|
-
* Throws only when
|
|
12
|
+
* Throws only when `XMLSerializer` is missing, or the XML itself is
|
|
13
|
+
* unparseable or has no <qgis> root.
|
|
13
14
|
* Sub-parser failures yield empty / null fields rather than exceptions.
|
|
14
15
|
*/
|
|
15
16
|
export declare function parseQgsXml(xmlText: string): QgsProject;
|
|
@@ -21,10 +21,17 @@ import { devLog } from "../util/devLog.js";
|
|
|
21
21
|
* 3. Each sub-parser handles one concern and isolates its own failures —
|
|
22
22
|
* a malformed legend tree shouldn't take down the layer list, etc.
|
|
23
23
|
*
|
|
24
|
-
* Throws only when
|
|
24
|
+
* Throws only when `XMLSerializer` is missing, or the XML itself is
|
|
25
|
+
* unparseable or has no <qgis> root.
|
|
25
26
|
* Sub-parser failures yield empty / null fields rather than exceptions.
|
|
26
27
|
*/
|
|
27
28
|
export function parseQgsXml(xmlText) {
|
|
29
|
+
// Each layer keeps its own XML through `XMLSerializer`. Without one, every
|
|
30
|
+
// layer would fail on its own and be skipped, leaving a project with no
|
|
31
|
+
// layers and no error.
|
|
32
|
+
if (typeof XMLSerializer === 'undefined') {
|
|
33
|
+
throw new Error('parseQgsXml needs XMLSerializer as well as DOMParser. A browser provides both; in Node, supply both from one library, such as jsdom.');
|
|
34
|
+
}
|
|
28
35
|
const parser = new DOMParser();
|
|
29
36
|
const doc = parser.parseFromString(xmlText, 'text/xml');
|
|
30
37
|
// DOMParser surfaces XML errors as a <parsererror> node in the document.
|
|
@@ -78,18 +78,28 @@ export declare const EXPRESSION_VARIABLE = "expression_variable";
|
|
|
78
78
|
export declare const LOOKUP_AGGREGATES: readonly ["count", "min", "max", "concatenate"];
|
|
79
79
|
/**
|
|
80
80
|
* One read of another layer of the project: the features of `layer`, named by
|
|
81
|
-
* its name or its QGIS id, that the record's shape lies within or meets,
|
|
82
|
-
* by `filter` and cut to `limit`,
|
|
83
|
-
*
|
|
84
|
-
*
|
|
81
|
+
* its name or its QGIS id, that the record's shape lies within or meets, or
|
|
82
|
+
* that are nearest to it (`predicate`), kept by `filter` and cut to `limit`,
|
|
83
|
+
* each giving the value of `expression`. The answer is the list of those
|
|
84
|
+
* values, in the order the caller works out: nearest first for `nearest`;
|
|
85
|
+
* otherwise by `sortByOverlap` where it is given, and else as the caller
|
|
86
|
+
* chooses. `key` tells one read from another.
|
|
87
|
+
*
|
|
88
|
+
* `sortByOverlap` is QGIS's `sort_by_intersection_size` of `overlay_intersects`:
|
|
89
|
+
* the features ordered by the size of the intersection, the largest first for
|
|
90
|
+
* `descending`. `maxDistance` is `overlay_nearest`'s `max_distance`. Each is
|
|
91
|
+
* left out where the expression does not give it. A `limit` of null keeps
|
|
92
|
+
* every feature; `overlay_nearest` keeps one, as QGIS does, where none is given.
|
|
85
93
|
*/
|
|
86
94
|
export interface LayerLookup {
|
|
87
95
|
key: string;
|
|
88
96
|
layer: string;
|
|
89
|
-
predicate: 'within' | 'intersects';
|
|
97
|
+
predicate: 'within' | 'intersects' | 'nearest';
|
|
90
98
|
expression: ExpressionNode;
|
|
91
99
|
filter: ExpressionNode | null;
|
|
92
100
|
limit: number | null;
|
|
101
|
+
sortByOverlap?: 'descending' | 'ascending';
|
|
102
|
+
maxDistance?: number;
|
|
93
103
|
}
|
|
94
104
|
/**
|
|
95
105
|
* The `fnName` of the GeoStyler `custom` function that stands for a
|
|
@@ -130,7 +140,7 @@ export declare function isQgisConditionFilter(filter: unknown): filter is {
|
|
|
130
140
|
* evaluator adds it to a date or takes it away. QGIS reads an interval
|
|
131
141
|
* elsewhere too, which the evaluator does not.
|
|
132
142
|
*
|
|
133
|
-
* `overlay_within`, `overlay_intersects` and `aggregate` read another layer,
|
|
143
|
+
* `overlay_within`, `overlay_intersects`, `overlay_nearest` and `aggregate` read another layer,
|
|
134
144
|
* and are read only where the caller says `lookups`: the caller then answers
|
|
135
145
|
* each `LayerLookup` before it evaluates (a default value). See
|
|
136
146
|
* `areLookupsReadable` for the forms read.
|
|
@@ -59,7 +59,8 @@ const QGIS_ONLY_FUNCTIONS = {
|
|
|
59
59
|
array_first: [1, 1],
|
|
60
60
|
array_get: [2, 2],
|
|
61
61
|
overlay_within: [1, 5],
|
|
62
|
-
overlay_intersects: [1,
|
|
62
|
+
overlay_intersects: [1, 9],
|
|
63
|
+
overlay_nearest: [1, 6],
|
|
63
64
|
aggregate: [3, 6],
|
|
64
65
|
geometry: [1, 1],
|
|
65
66
|
intersects: [2, 2],
|
|
@@ -199,14 +200,19 @@ const REGEXP_FUNCTIONS = ['regexp_match', 'regexp_replace', 'regexp_substr'];
|
|
|
199
200
|
*/
|
|
200
201
|
const NAMED_PARAMETERS = {
|
|
201
202
|
make_interval: { names: ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds'], omitted: { kind: 'number', value: 0 } },
|
|
202
|
-
// QGIS's own lists go on
|
|
203
|
-
//
|
|
203
|
+
// QGIS's own lists go on past the ones that are read (`min_overlap`,
|
|
204
|
+
// `min_inscribed_circle_radius` and `return_details` of `overlay_intersects`);
|
|
205
|
+
// a value for any of those leaves the expression unread.
|
|
204
206
|
overlay_within: { names: ['layer', 'expression', 'filter', 'limit', 'cache'], omitted: { kind: 'null' } },
|
|
205
|
-
overlay_intersects: {
|
|
207
|
+
overlay_intersects: {
|
|
208
|
+
names: ['layer', 'expression', 'filter', 'limit', 'cache', 'min_overlap', 'min_inscribed_circle_radius', 'return_details', 'sort_by_intersection_size'],
|
|
209
|
+
omitted: { kind: 'null' }
|
|
210
|
+
},
|
|
211
|
+
overlay_nearest: { names: ['layer', 'expression', 'filter', 'limit', 'max_distance', 'cache'], omitted: { kind: 'null' } },
|
|
206
212
|
aggregate: { names: ['layer', 'aggregate', 'expression', 'filter', 'concatenator', 'order_by'], omitted: { kind: 'null' } }
|
|
207
213
|
};
|
|
208
214
|
/** The calls that read another layer of the project: `LayerLookup`. */
|
|
209
|
-
const LOOKUPS = ['overlay_within', 'overlay_intersects', 'aggregate'];
|
|
215
|
+
const LOOKUPS = ['overlay_within', 'overlay_intersects', 'overlay_nearest', 'aggregate'];
|
|
210
216
|
/**
|
|
211
217
|
* What `aggregate` reads the filter `intersects($geometry, geometry(@parent))`
|
|
212
218
|
* through, which stand nowhere else.
|
|
@@ -280,7 +286,7 @@ export function isQgisConditionFilter(filter) {
|
|
|
280
286
|
* evaluator adds it to a date or takes it away. QGIS reads an interval
|
|
281
287
|
* elsewhere too, which the evaluator does not.
|
|
282
288
|
*
|
|
283
|
-
* `overlay_within`, `overlay_intersects` and `aggregate` read another layer,
|
|
289
|
+
* `overlay_within`, `overlay_intersects`, `overlay_nearest` and `aggregate` read another layer,
|
|
284
290
|
* and are read only where the caller says `lookups`: the caller then answers
|
|
285
291
|
* each `LayerLookup` before it evaluates (a default value). See
|
|
286
292
|
* `areLookupsReadable` for the forms read.
|
|
@@ -798,8 +804,8 @@ function findAddedIntervals(node) {
|
|
|
798
804
|
}
|
|
799
805
|
/**
|
|
800
806
|
* Whether an expression's reads of other layers are ones the caller can answer.
|
|
801
|
-
* With `allowed` false, it holds none. Otherwise each `overlay_within
|
|
802
|
-
* `overlay_intersects` gives an expression and is the array that
|
|
807
|
+
* With `allowed` false, it holds none. Otherwise each `overlay_within`,
|
|
808
|
+
* `overlay_intersects` or `overlay_nearest` gives an expression and is the array that
|
|
803
809
|
* `array_first` or a whole-number `[index]` reads; each `aggregate` is a
|
|
804
810
|
* `count`, `min`, `max` or `concatenate` of the features its filter
|
|
805
811
|
* `intersects($geometry, geometry(@parent))` keeps, with no `order_by`; the
|
|
@@ -863,23 +869,45 @@ function isReadableLookup(call) {
|
|
|
863
869
|
&& (args.concatenator.kind === 'null' || args.concatenator.kind === 'text')
|
|
864
870
|
&& args.order_by.kind === 'null';
|
|
865
871
|
}
|
|
866
|
-
|
|
872
|
+
const isReadableOverlay = (args.filter.kind === 'null' || readsTargetFieldsOnly(args.filter))
|
|
867
873
|
&& (args.limit.kind === 'null' || isWholeNumber(args.limit))
|
|
868
874
|
&& (args.cache.kind === 'null' || args.cache.kind === 'boolean');
|
|
875
|
+
if (call.name === 'overlay_nearest') {
|
|
876
|
+
return isReadableOverlay && (args.max_distance.kind === 'null' || (args.max_distance.kind === 'number' && args.max_distance.value >= 0));
|
|
877
|
+
}
|
|
878
|
+
if (call.name === 'overlay_intersects') {
|
|
879
|
+
const sort = args.sort_by_intersection_size;
|
|
880
|
+
return isReadableOverlay
|
|
881
|
+
&& args.min_overlap.kind === 'null'
|
|
882
|
+
&& args.min_inscribed_circle_radius.kind === 'null'
|
|
883
|
+
&& args.return_details.kind === 'null'
|
|
884
|
+
&& (sort.kind === 'null' || (sort.kind === 'text' && OVERLAP_SORTS.has(sort.value.trim().toLowerCase())));
|
|
885
|
+
}
|
|
886
|
+
return isReadableOverlay;
|
|
869
887
|
}
|
|
888
|
+
/** The values of `sort_by_intersection_size` that QGIS takes: `des` for the largest overlap first, `asc` for the smallest. */
|
|
889
|
+
const OVERLAP_SORTS = new Map([['des', 'descending'], ['asc', 'ascending']]);
|
|
870
890
|
/** The `LayerLookup` a readable lookup call makes. */
|
|
871
891
|
function toLayerLookup(call) {
|
|
872
892
|
const args = lookupArguments(call);
|
|
873
893
|
const isAggregate = call.name === 'aggregate';
|
|
874
894
|
const layer = args.layer;
|
|
875
895
|
const limit = args.limit;
|
|
896
|
+
const isNearest = call.name === 'overlay_nearest';
|
|
897
|
+
const sort = args.sort_by_intersection_size;
|
|
898
|
+
const maxDistance = args.max_distance;
|
|
876
899
|
const lookup = {
|
|
877
900
|
layer: layer.kind === 'text' ? layer.value.trim() : '',
|
|
878
|
-
predicate: call.name === 'overlay_within' ? 'within' : 'intersects',
|
|
901
|
+
predicate: call.name === 'overlay_within' ? 'within' : isNearest ? 'nearest' : 'intersects',
|
|
879
902
|
expression: args.expression,
|
|
880
903
|
filter: isAggregate || args.filter.kind === 'null' ? null : args.filter,
|
|
881
|
-
|
|
904
|
+
// `overlay_nearest` gives the one nearest feature unless it is given a limit, and every one for a limit of -1.
|
|
905
|
+
limit: isAggregate ? null : limit?.kind === 'number' ? (limit.value >= 0 ? limit.value : null) : isNearest ? 1 : null
|
|
882
906
|
};
|
|
907
|
+
if (sort?.kind === 'text')
|
|
908
|
+
lookup.sortByOverlap = OVERLAP_SORTS.get(sort.value.trim().toLowerCase());
|
|
909
|
+
if (maxDistance?.kind === 'number')
|
|
910
|
+
lookup.maxDistance = maxDistance.value;
|
|
883
911
|
return { key: JSON.stringify(lookup), ...lookup };
|
|
884
912
|
}
|
|
885
913
|
/**
|
|
@@ -1004,7 +1032,7 @@ export function expressionToGeoStylerFunction(node) {
|
|
|
1004
1032
|
return { name: 'custom', fnName: '||', args };
|
|
1005
1033
|
if (Object.hasOwn(GEOMETRY_VALUES, node.name))
|
|
1006
1034
|
return { name: 'custom', fnName: node.name, args: [node.factor ?? null] };
|
|
1007
|
-
if (node.name === 'overlay_within' || node.name === 'overlay_intersects')
|
|
1035
|
+
if (node.name === 'overlay_within' || node.name === 'overlay_intersects' || node.name === 'overlay_nearest')
|
|
1008
1036
|
return { name: 'custom', fnName: LAYER_LOOKUP, args: [toLayerLookup(node).key] };
|
|
1009
1037
|
if (node.name === 'aggregate') {
|
|
1010
1038
|
const { aggregate, concatenator } = lookupArguments(node);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectoriahq/quac",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-next.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Writes and reads QUAC, which adds map layer settings to STAC catalogues.",
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@cfworker/json-schema": "4.1.1",
|
|
51
51
|
"jsdom": "30.1.3",
|
|
52
|
-
"linkedom": "0.18.13",
|
|
53
52
|
"typescript": "5.9.3",
|
|
54
53
|
"vite": "8.3.4",
|
|
55
54
|
"vitest": "5.0.5"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
-
"$id": "https://vectoriahq.github.io/quac/v0.
|
|
3
|
+
"$id": "https://vectoriahq.github.io/quac/v0.3.0/schema.json",
|
|
4
4
|
"title": "QUAC: Quite Useful Additions for Catalogs",
|
|
5
5
|
"description": "The fields of QUAC (Quite Useful Additions for Catalogs): the fields a STAC catalogue carries under the quac: prefix to say how a layer is drawn, edited and set up, as a source such as a QGIS project declares it. Validates a Catalog with its inlined collections and catalogs, or a single Collection. Only quac: fields are checked: any other field passes, and a quac: field this schema does not define fails. A field is written only when the source declares it, so an absent field means the source said nothing.",
|
|
6
6
|
"type": "object",
|
|
@@ -578,6 +578,33 @@
|
|
|
578
578
|
"dropdown"
|
|
579
579
|
]
|
|
580
580
|
},
|
|
581
|
+
"quac:values": {
|
|
582
|
+
"description": "The values the field takes, each with the label a form shows for it, in the source's order. Written from a QGIS Value Map widget or an ArcGIS coded-value domain.",
|
|
583
|
+
"type": "array",
|
|
584
|
+
"minItems": 1,
|
|
585
|
+
"items": {
|
|
586
|
+
"type": "object",
|
|
587
|
+
"required": [
|
|
588
|
+
"value",
|
|
589
|
+
"label"
|
|
590
|
+
],
|
|
591
|
+
"properties": {
|
|
592
|
+
"value": {
|
|
593
|
+
"description": "The value the field stores. An empty string is QGIS's blank choice.",
|
|
594
|
+
"type": [
|
|
595
|
+
"string",
|
|
596
|
+
"number"
|
|
597
|
+
]
|
|
598
|
+
},
|
|
599
|
+
"label": {
|
|
600
|
+
"description": "The label shown for the value.",
|
|
601
|
+
"type": "string",
|
|
602
|
+
"minLength": 1
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
"additionalProperties": false
|
|
606
|
+
}
|
|
607
|
+
},
|
|
581
608
|
"quac:value_relation": {
|
|
582
609
|
"$ref": "#/definitions/value_relation"
|
|
583
610
|
},
|