@vectoriahq/quac 0.4.0-next.1 → 0.4.0

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.
Files changed (2) hide show
  1. package/README.md +35 -4
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -10,16 +10,47 @@ The package writes QUAC catalogues from QGIS projects and other sources, and rea
10
10
  npm install @vectoriahq/quac
11
11
  ```
12
12
 
13
- ## Example
13
+ ## Read a Collection
14
14
 
15
- Build a catalogue from a QGIS project file. The parsers use the standard `DOMParser`, which a browser provides; in Node, supply one, such as [linkedom](https://www.npmjs.com/package/linkedom)'s.
15
+ Each `readCollection…` function takes one Collection and returns one kind of setting, keyed by field name where it is a field's. It needs nothing else from the catalogue, so an application can read a Collection as it opens it. This reads the trees layer of [the demo catalogue](https://vectoriahq.github.io/quac/demo/catalog.json):
16
+
17
+ ```js
18
+ import {
19
+ readCollectionFieldAliases,
20
+ readCollectionFieldEditRules,
21
+ readCollectionFieldValues,
22
+ readCollectionFormLayout
23
+ } from '@vectoriahq/quac'
24
+
25
+ const response = await fetch('https://vectoriahq.github.io/quac/demo/collections/trees.json')
26
+ const trees = await response.json()
27
+
28
+ readCollectionFieldAliases(trees).height
29
+ // 'Height'
30
+ readCollectionFieldEditRules(trees).height
31
+ // { range: { min: 0, max: 40, step: 0.5, precision: 1, suffix: ' m' },
32
+ // constraintExpression: { expression: '"height" < 40', description: 'Taller than any tree on this street', strength: 'warn' },
33
+ // readOnly: false, notNull: null, … }
34
+ readCollectionFieldValues(trees).condition
35
+ // [{ value: 'G', label: 'Good' }, { value: 'F', label: 'Fair' }, …]
36
+ readCollectionFormLayout(trees).fields.at(-1)
37
+ // { name: 'removal_reason', visibleWhen: ['"condition" = \'D\''] }
38
+ ```
39
+
40
+ A Value Relation names the Collection its choices come from (`readCollectionFieldValueRelations`), and a child layer names its parent (`readCollectionRelatedTo`). Reading those choices or records means reading that Collection's data too.
41
+
42
+ ## Build a catalogue
43
+
44
+ Build a catalogue from a QGIS project file. The parsers use the standard `DOMParser` and `XMLSerializer`, which a browser provides. In Node, supply both, such as [jsdom](https://www.npmjs.com/package/jsdom)'s:
16
45
 
17
46
  ```js
18
47
  import { readFile } from 'node:fs/promises'
19
- import { DOMParser } from 'linkedom'
48
+ import { JSDOM } from 'jsdom'
20
49
  import { parseQgsXml, generateStacCatalogue } from '@vectoriahq/quac'
21
50
 
22
- globalThis.DOMParser = DOMParser
51
+ const { window } = new JSDOM()
52
+ globalThis.DOMParser = window.DOMParser
53
+ globalThis.XMLSerializer = window.XMLSerializer
23
54
 
24
55
  const project = parseQgsXml(await readFile('survey/project.qgs', 'utf8'))
25
56
  const catalogue = generateStacCatalogue(project, [], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriahq/quac",
3
- "version": "0.4.0-next.1",
3
+ "version": "0.4.0",
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.",