@ignfab/geocontext 0.9.3 → 0.9.5
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 +46 -28
- package/dist/gpf/adminexpress.js +7 -27
- package/dist/gpf/adminexpress.js.map +1 -1
- package/dist/gpf/parcellaire-express.js +13 -33
- package/dist/gpf/parcellaire-express.js.map +1 -1
- package/dist/gpf/urbanisme.d.ts +4 -2
- package/dist/gpf/urbanisme.js +20 -61
- package/dist/gpf/urbanisme.js.map +1 -1
- package/dist/gpf/wfs.d.ts +2 -2
- package/dist/gpf/wfs.js +17 -71
- package/dist/gpf/wfs.js.map +1 -1
- package/dist/helpers/distance.d.ts +4 -2
- package/dist/helpers/distance.js +20 -5
- package/dist/helpers/distance.js.map +1 -1
- package/dist/helpers/http.d.ts +4 -0
- package/dist/helpers/http.js +103 -1
- package/dist/helpers/http.js.map +1 -1
- package/dist/helpers/jsonSchema.d.ts +3 -0
- package/dist/helpers/jsonSchema.js +8 -0
- package/dist/helpers/jsonSchema.js.map +1 -0
- package/dist/helpers/schemas.d.ts +13 -0
- package/dist/helpers/schemas.js +18 -0
- package/dist/helpers/schemas.js.map +1 -0
- package/dist/helpers/wfs.d.ts +27 -0
- package/dist/helpers/wfs.js +55 -0
- package/dist/helpers/wfs.js.map +1 -0
- package/dist/helpers/wfs_internal/compile.d.ts +46 -0
- package/dist/helpers/wfs_internal/compile.js +595 -0
- package/dist/helpers/wfs_internal/compile.js.map +1 -0
- package/dist/helpers/wfs_internal/request.d.ts +38 -0
- package/dist/helpers/wfs_internal/request.js +92 -0
- package/dist/helpers/wfs_internal/request.js.map +1 -0
- package/dist/helpers/wfs_internal/response.d.ts +21 -0
- package/dist/helpers/wfs_internal/response.js +29 -0
- package/dist/helpers/wfs_internal/response.js.map +1 -0
- package/dist/helpers/wfs_internal/schema.d.ts +167 -0
- package/dist/helpers/wfs_internal/schema.js +81 -0
- package/dist/helpers/wfs_internal/schema.js.map +1 -0
- package/dist/index.js +47 -25
- package/dist/index.js.map +1 -1
- package/dist/tools/AdminexpressTool.d.ts +52 -2
- package/dist/tools/AdminexpressTool.js +11 -14
- package/dist/tools/AdminexpressTool.js.map +1 -1
- package/dist/tools/AltitudeTool.d.ts +2 -2
- package/dist/tools/AltitudeTool.js +4 -13
- package/dist/tools/AltitudeTool.js.map +1 -1
- package/dist/tools/AssietteSupTool.d.ts +55 -3
- package/dist/tools/AssietteSupTool.js +12 -15
- package/dist/tools/AssietteSupTool.js.map +1 -1
- package/dist/tools/CadastreTool.d.ts +52 -2
- package/dist/tools/CadastreTool.js +13 -15
- package/dist/tools/CadastreTool.js.map +1 -1
- package/dist/tools/GeocodeTool.d.ts +2 -2
- package/dist/tools/GeocodeTool.js +6 -4
- package/dist/tools/GeocodeTool.js.map +1 -1
- package/dist/tools/GpfWfsDescribeTypeTool.d.ts +16 -16
- package/dist/tools/GpfWfsDescribeTypeTool.js +4 -3
- package/dist/tools/GpfWfsDescribeTypeTool.js.map +1 -1
- package/dist/tools/GpfWfsGetFeaturesTool.d.ts +170 -44
- package/dist/tools/GpfWfsGetFeaturesTool.js +161 -114
- package/dist/tools/GpfWfsGetFeaturesTool.js.map +1 -1
- package/dist/tools/GpfWfsSearchTypesTool.d.ts +8 -2
- package/dist/tools/GpfWfsSearchTypesTool.js +12 -9
- package/dist/tools/GpfWfsSearchTypesTool.js.map +1 -1
- package/dist/tools/UrbanismeTool.d.ts +53 -3
- package/dist/tools/UrbanismeTool.js +9 -15
- package/dist/tools/UrbanismeTool.js.map +1 -1
- package/package.json +8 -7
- package/dist/resources/WfsCqlFilterResource.d.ts +0 -10
- package/dist/resources/WfsCqlFilterResource.js +0 -23
- package/dist/resources/WfsCqlFilterResource.js.map +0 -1
- package/dist/resources/content/wfs-cql-filter.md +0 -215
- package/dist/tools/GpfWfsListTypesTool.d.ts +0 -22
- package/dist/tools/GpfWfsListTypesTool.js +0 -26
- package/dist/tools/GpfWfsListTypesTool.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"distance.js","sourceRoot":"","sources":["../../src/helpers/distance.js"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,+CAA+C,CAAA;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,iDAAiD,CAAA;AAE5E
|
|
1
|
+
{"version":3,"file":"distance.js","sourceRoot":"","sources":["../../src/helpers/distance.js"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,+CAA+C,CAAA;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,iDAAiD,CAAA;AAE5E,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAC,KAAK,IAAI,SAAS,EAAC,MAAM,eAAe,CAAA;AAEhD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,EAAE,EAAE;IACnC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;IACzC,MAAM,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjC,MAAM,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEjC;;;;;OAKG;IACH,MAAM,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,IAAK,aAAa,CAAC,MAAM,KAAK,CAAC,EAAG,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACvE,CAAC;IAED;;OAEG;IACH,OAAO,YAAY,CACf,SAAS,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnD,SAAS,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnD,EAAE,KAAK,EAAE,QAAQ,EAAE,CACtB,CAAC;AACN,CAAC"}
|
package/dist/helpers/http.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
export function parseJsonResponse(res: any): Promise<any>;
|
|
1
2
|
/**
|
|
3
|
+
* Fetches and parses a JSON response from a URL
|
|
4
|
+
* TODO : Add a timeout
|
|
2
5
|
*
|
|
3
6
|
* @param {string} url
|
|
4
7
|
* @returns {Promise<any>}
|
|
5
8
|
*/
|
|
6
9
|
export function fetchJSON(url: string): Promise<any>;
|
|
10
|
+
export function fetchJSONPost(url: any, body?: string, headers?: {}): Promise<any>;
|
package/dist/helpers/http.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
|
+
import { parseXml, XmlElement } from '@rgrove/parse-xml';
|
|
2
3
|
import logger from "../logger.js";
|
|
3
4
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
4
5
|
const fetchOpts = {
|
|
@@ -10,15 +11,116 @@ const fetchOpts = {
|
|
|
10
11
|
if (process.env.HTTP_PROXY) {
|
|
11
12
|
fetchOpts.agent = new HttpsProxyAgent(process.env.HTTP_PROXY);
|
|
12
13
|
}
|
|
14
|
+
function getChild(element, localName) {
|
|
15
|
+
return element.children.find((child) => child instanceof XmlElement && child.name.split(":").pop() === localName) || null;
|
|
16
|
+
}
|
|
17
|
+
// Tente d'extraire un message d'erreur d'une réponse XML de type OGC WFS
|
|
18
|
+
function extractXmlError(text) {
|
|
19
|
+
try {
|
|
20
|
+
const root = parseXml(text).children.find((child) => child instanceof XmlElement);
|
|
21
|
+
const rootName = root?.name.split(":").pop();
|
|
22
|
+
if (rootName !== "ExceptionReport" && rootName !== "ServiceExceptionReport") {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const exception = getChild(root, "Exception") || getChild(root, "ServiceException");
|
|
26
|
+
if (!exception) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const code = exception.attributes?.exceptionCode || exception.attributes?.code;
|
|
30
|
+
const message = getChild(exception, "ExceptionText")?.text?.trim() || exception.text?.trim() || "";
|
|
31
|
+
const errorMessage = [code, message].filter(Boolean).join(": ");
|
|
32
|
+
return errorMessage ? new Error(errorMessage) : null;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function previewBody(text) {
|
|
39
|
+
const trimmed = text.trim();
|
|
40
|
+
if (!trimmed) {
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
return trimmed.replace(/\s+/g, " ").slice(0, 200);
|
|
44
|
+
}
|
|
45
|
+
export async function parseJsonResponse(res) {
|
|
46
|
+
const contentType = (res.headers?.get?.("content-type") || "").toLowerCase();
|
|
47
|
+
const text = await res.text();
|
|
48
|
+
const looksLikeXml = contentType.includes("xml") || text.trim().startsWith("<");
|
|
49
|
+
const responseLabel = [res.status, res.statusText].filter(Boolean).join(" ") || "réponse HTTP";
|
|
50
|
+
const hasValidStatus = Number.isFinite(res.status);
|
|
51
|
+
const isOk = typeof res.ok === "boolean"
|
|
52
|
+
? res.ok
|
|
53
|
+
: hasValidStatus && res.status >= 200 && res.status < 300;
|
|
54
|
+
if (text.trim() === "") {
|
|
55
|
+
throw new Error(`Réponse vide du service (${responseLabel})`);
|
|
56
|
+
}
|
|
57
|
+
if (looksLikeXml) {
|
|
58
|
+
const xmlError = extractXmlError(text);
|
|
59
|
+
if (xmlError) {
|
|
60
|
+
if (!isOk) {
|
|
61
|
+
throw new Error(`Erreur HTTP du service (${responseLabel}): ${xmlError.message}`);
|
|
62
|
+
}
|
|
63
|
+
throw xmlError;
|
|
64
|
+
}
|
|
65
|
+
const details = [`content-type=${contentType || "inconnu"}`];
|
|
66
|
+
const bodyPreview = previewBody(text);
|
|
67
|
+
if (bodyPreview) {
|
|
68
|
+
details.push(`extrait=${bodyPreview}`);
|
|
69
|
+
}
|
|
70
|
+
throw new Error(`Réponse XML non exploitable du service (${responseLabel}, ${details.join(", ")})`);
|
|
71
|
+
}
|
|
72
|
+
let json;
|
|
73
|
+
try {
|
|
74
|
+
json = JSON.parse(text);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
const details = [`content-type=${contentType || "inconnu"}`];
|
|
78
|
+
const bodyPreview = previewBody(text);
|
|
79
|
+
if (bodyPreview) {
|
|
80
|
+
details.push(`extrait=${bodyPreview}`);
|
|
81
|
+
}
|
|
82
|
+
throw new Error(`Réponse JSON invalide du service (${responseLabel}, ${details.join(", ")})`);
|
|
83
|
+
}
|
|
84
|
+
if (!isOk) {
|
|
85
|
+
const errorMessage = json?.message
|
|
86
|
+
|| json?.error
|
|
87
|
+
|| json?.errorMessage
|
|
88
|
+
|| json?.msg
|
|
89
|
+
|| json?.title
|
|
90
|
+
|| json?.detail
|
|
91
|
+
|| (typeof json === "string" ? json : previewBody(JSON.stringify(json)));
|
|
92
|
+
throw new Error(`Erreur HTTP du service (${responseLabel}): ${errorMessage}`);
|
|
93
|
+
}
|
|
94
|
+
return json;
|
|
95
|
+
}
|
|
13
96
|
/**
|
|
97
|
+
* Fetches and parses a JSON response from a URL
|
|
98
|
+
* TODO : Add a timeout
|
|
14
99
|
*
|
|
15
100
|
* @param {string} url
|
|
16
101
|
* @returns {Promise<any>}
|
|
17
102
|
*/
|
|
18
103
|
export async function fetchJSON(url) {
|
|
19
104
|
logger.info(`[HTTP] GET ${url} ...`);
|
|
20
|
-
const result = await fetch(url, fetchOpts).then(
|
|
105
|
+
const result = await fetch(url, fetchOpts).then(parseJsonResponse);
|
|
21
106
|
logger.debug(`[HTTP] GET ${url} : ${JSON.stringify(result)}`);
|
|
22
107
|
return result;
|
|
23
108
|
}
|
|
109
|
+
function buildFetchOptions(method, body, headers) {
|
|
110
|
+
return {
|
|
111
|
+
...fetchOpts,
|
|
112
|
+
method,
|
|
113
|
+
headers: new Headers({
|
|
114
|
+
...Object.fromEntries(fetchOpts.headers.entries()),
|
|
115
|
+
...(headers || {})
|
|
116
|
+
}),
|
|
117
|
+
...(body !== undefined ? { body } : {})
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export async function fetchJSONPost(url, body = "", headers = {}) {
|
|
121
|
+
logger.info(`[HTTP] POST ${url} ...`);
|
|
122
|
+
const result = await fetch(url, buildFetchOptions("POST", body, headers)).then(parseJsonResponse);
|
|
123
|
+
logger.debug(`[HTTP] POST ${url} : ${JSON.stringify(result)}`);
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
24
126
|
//# sourceMappingURL=http.js.map
|
package/dist/helpers/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/helpers/http.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/helpers/http.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,SAAS,GAAG;IACd,OAAO,EAAE,IAAI,OAAO,CAAC;QACjB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,YAAY;KAC7B,CAAC;CACL,CAAC;AAEF,IAAK,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;IAC1B,SAAS,CAAC,KAAK,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,QAAQ,CAAC,OAAO,EAAE,SAAS;IAChC,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,YAAY,UAAU,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,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AAK,CAAC,GAAG,EAAE,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAClG,MAAM,CAAC,KAAK,CAAC,eAAe,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { toJsonSchemaCompat } from "@modelcontextprotocol/sdk/server/zod-json-schema-compat.js";
|
|
2
|
+
export function generatePublishedInputSchema(schema) {
|
|
3
|
+
return toJsonSchemaCompat(schema, {
|
|
4
|
+
strictUnions: true,
|
|
5
|
+
pipeStrategy: "input",
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=jsonSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonSchema.js","sourceRoot":"","sources":["../../src/helpers/jsonSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4DAA4D,CAAC;AAEhG,MAAM,UAAU,4BAA4B,CAAC,MAAW;IACtD,OAAO,kBAAkB,CAAC,MAAM,EAAE;QAChC,YAAY,EAAE,IAAI;QAClB,YAAY,EAAE,OAAO;KACtB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const lonSchema: z.ZodNumber;
|
|
3
|
+
export declare const latSchema: z.ZodNumber;
|
|
4
|
+
export declare const featureRefSchema: z.ZodObject<{
|
|
5
|
+
typename: z.ZodString;
|
|
6
|
+
feature_id: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
typename?: string;
|
|
9
|
+
feature_id?: string;
|
|
10
|
+
}, {
|
|
11
|
+
typename?: string;
|
|
12
|
+
feature_id?: string;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const lonSchema = z
|
|
3
|
+
.number()
|
|
4
|
+
.finite()
|
|
5
|
+
.min(-180)
|
|
6
|
+
.max(180)
|
|
7
|
+
.describe("La longitude du point.");
|
|
8
|
+
export const latSchema = z
|
|
9
|
+
.number()
|
|
10
|
+
.finite()
|
|
11
|
+
.min(-90)
|
|
12
|
+
.max(90)
|
|
13
|
+
.describe("La latitude du point.");
|
|
14
|
+
export const featureRefSchema = z.object({
|
|
15
|
+
typename: z.string().describe("Le `typename` WFS réutilisable pour une requête ultérieure."),
|
|
16
|
+
feature_id: z.string().describe("L'identifiant WFS réutilisable du feature."),
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/helpers/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC;KACvB,MAAM,EAAE;KACR,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,GAAG,CAAC;KACT,GAAG,CAAC,GAAG,CAAC;KACR,QAAQ,CAAC,wBAAwB,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC;KACvB,MAAM,EAAE;KACR,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,EAAE,CAAC;KACR,GAAG,CAAC,EAAE,CAAC;KACP,QAAQ,CAAC,uBAAuB,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6DAA6D,CAAC;IAC5F,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;CAC9E,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch features from a GPF WFS endpoint.
|
|
3
|
+
*
|
|
4
|
+
* @param {string[]} typeNames - fully qualified WFS type names
|
|
5
|
+
* @param {string} cqlFilter - CQL_FILTER value
|
|
6
|
+
* @param {string} errorLabel - service label used in the error message
|
|
7
|
+
* @param {(url: string) => Promise<any>} [fetcher]
|
|
8
|
+
* @returns {Promise<any[]>} raw GeoJSON features array
|
|
9
|
+
*/
|
|
10
|
+
export function fetchWfsFeatures(typeNames: string[], cqlFilter: string, errorLabel: string, fetcher?: (url: string) => Promise<any>): Promise<any[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Builds a GeoJSON Point from longitude and latitude.
|
|
13
|
+
*
|
|
14
|
+
* @param {number} lon
|
|
15
|
+
* @param {number} lat
|
|
16
|
+
* @returns {object} GeoJSON Point
|
|
17
|
+
*/
|
|
18
|
+
export function toGeoJsonPoint(lon: number, lat: number): object;
|
|
19
|
+
/**
|
|
20
|
+
* Maps a raw WFS feature into a flat result object, stripping geometry
|
|
21
|
+
* and resolving a reusable feature_ref from the known type names.
|
|
22
|
+
*
|
|
23
|
+
* @param {object} feature - Raw GeoJSON feature from WFS
|
|
24
|
+
* @param {string[]} knownTypeNames - Fully qualified WFS type names used for feature_ref resolution
|
|
25
|
+
* @returns {object} Flat result with type, id, bbox, optional feature_ref, and spread properties
|
|
26
|
+
*/
|
|
27
|
+
export function mapWfsFeature(feature: object, knownTypeNames: string[]): object;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { fetchJSON } from './http.js';
|
|
2
|
+
const GPF_WFS_BASE_URL = process.env.GPF_WFS_BASE_URL || 'https://data.geopf.fr/wfs';
|
|
3
|
+
/**
|
|
4
|
+
* Fetch features from a GPF WFS endpoint.
|
|
5
|
+
*
|
|
6
|
+
* @param {string[]} typeNames - fully qualified WFS type names
|
|
7
|
+
* @param {string} cqlFilter - CQL_FILTER value
|
|
8
|
+
* @param {string} errorLabel - service label used in the error message
|
|
9
|
+
* @param {(url: string) => Promise<any>} [fetcher]
|
|
10
|
+
* @returns {Promise<any[]>} raw GeoJSON features array
|
|
11
|
+
*/
|
|
12
|
+
export async function fetchWfsFeatures(typeNames, cqlFilter, errorLabel, fetcher = fetchJSON) {
|
|
13
|
+
const url = GPF_WFS_BASE_URL + '?' + new URLSearchParams({
|
|
14
|
+
service: 'WFS',
|
|
15
|
+
request: 'GetFeature',
|
|
16
|
+
typeName: typeNames.join(','),
|
|
17
|
+
outputFormat: 'application/json',
|
|
18
|
+
cql_filter: cqlFilter,
|
|
19
|
+
}).toString();
|
|
20
|
+
const featureCollection = await fetcher(url);
|
|
21
|
+
if (!Array.isArray(featureCollection?.features)) {
|
|
22
|
+
throw new Error(`Le service ${errorLabel} n'a pas retourné de collection d'objets exploitable`);
|
|
23
|
+
}
|
|
24
|
+
return featureCollection.features;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Builds a GeoJSON Point from longitude and latitude.
|
|
28
|
+
*
|
|
29
|
+
* @param {number} lon
|
|
30
|
+
* @param {number} lat
|
|
31
|
+
* @returns {object} GeoJSON Point
|
|
32
|
+
*/
|
|
33
|
+
export function toGeoJsonPoint(lon, lat) {
|
|
34
|
+
return { type: "Point", coordinates: [lon, lat] };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Maps a raw WFS feature into a flat result object, stripping geometry
|
|
38
|
+
* and resolving a reusable feature_ref from the known type names.
|
|
39
|
+
*
|
|
40
|
+
* @param {object} feature - Raw GeoJSON feature from WFS
|
|
41
|
+
* @param {string[]} knownTypeNames - Fully qualified WFS type names used for feature_ref resolution
|
|
42
|
+
* @returns {object} Flat result with type, id, bbox, optional feature_ref, and spread properties
|
|
43
|
+
*/
|
|
44
|
+
export function mapWfsFeature(feature, knownTypeNames) {
|
|
45
|
+
const type = feature.id.split('.')[0];
|
|
46
|
+
const typename = knownTypeNames.find((t) => t.endsWith(`:${type}`));
|
|
47
|
+
return {
|
|
48
|
+
...feature.properties,
|
|
49
|
+
type,
|
|
50
|
+
id: feature.id,
|
|
51
|
+
bbox: feature.bbox,
|
|
52
|
+
...(typename ? { feature_ref: { typename, feature_id: feature.id } } : {}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=wfs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wfs.js","sourceRoot":"","sources":["../../src/helpers/wfs.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,2BAA2B,CAAC;AAErF;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,GAAG,SAAS;IACxF,MAAM,GAAG,GAAG,gBAAgB,GAAG,GAAG,GAAG,IAAI,eAAe,CAAC;QACrD,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,YAAY;QACrB,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;QAC7B,YAAY,EAAE,kBAAkB;QAChC,UAAU,EAAE,SAAS;KACxB,CAAC,CAAC,QAAQ,EAAE,CAAC;IAEd,MAAM,iBAAiB,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,EAAE,QAAQ,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,cAAc,UAAU,sDAAsD,CAAC,CAAC;IACpG,CAAC;IACD,OAAO,iBAAiB,CAAC,QAAQ,CAAC;AACtC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,GAAG,EAAE,GAAG;IACnC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;AACtD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,OAAO,EAAE,cAAc;IACjD,MAAM,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;IACpE,OAAO;QACH,GAAG,OAAO,CAAC,UAAU;QACrB,IAAI;QACJ,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7E,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Collection, CollectionProperty } from "@ignfab/gpf-schema-store";
|
|
2
|
+
import type { GpfWfsGetFeaturesInput, SpatialFilter } from "./schema.js";
|
|
3
|
+
export type ResolvedFeatureGeometryRef = {
|
|
4
|
+
typename: string;
|
|
5
|
+
feature_id: string;
|
|
6
|
+
geometry_ewkt: string;
|
|
7
|
+
};
|
|
8
|
+
export type CompiledQuery = {
|
|
9
|
+
geometryProperty: CollectionProperty;
|
|
10
|
+
cqlFilter?: string;
|
|
11
|
+
propertyName?: string;
|
|
12
|
+
sortBy?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the single geometry property expected by the query compiler.
|
|
16
|
+
*
|
|
17
|
+
* @param featureType Feature type definition loaded from the embedded catalog.
|
|
18
|
+
* @returns The unique geometry property for the feature type.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getGeometryProperty(featureType: Collection): CollectionProperty;
|
|
21
|
+
/**
|
|
22
|
+
* Serializes a GeoJSON-like geometry object into EWKT for CQL spatial predicates.
|
|
23
|
+
*
|
|
24
|
+
* @param geometry Geometry object exposing a GeoJSON `type` and `coordinates`.
|
|
25
|
+
* @returns The EWKT representation of the geometry.
|
|
26
|
+
*/
|
|
27
|
+
export declare function geometryToEwkt(geometry: {
|
|
28
|
+
type: string;
|
|
29
|
+
coordinates: unknown;
|
|
30
|
+
}): string;
|
|
31
|
+
/**
|
|
32
|
+
* Normalizes the raw spatial input into a discriminated spatial filter object.
|
|
33
|
+
*
|
|
34
|
+
* @param input Normalized tool input.
|
|
35
|
+
* @returns A normalized spatial filter, or `undefined` when no spatial filter is requested.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getSpatialFilter(input: GpfWfsGetFeaturesInput): SpatialFilter | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Compiles normalized tool input into query fragments ready to be turned into a WFS request.
|
|
40
|
+
*
|
|
41
|
+
* @param input Normalized tool input.
|
|
42
|
+
* @param featureType Feature type definition loaded from the embedded catalog.
|
|
43
|
+
* @param resolvedGeometryRef Optional resolved reference geometry for `intersects_feature`.
|
|
44
|
+
* @returns Compiled query parts used by request builders.
|
|
45
|
+
*/
|
|
46
|
+
export declare function compileQueryParts(input: GpfWfsGetFeaturesInput, featureType: Collection, resolvedGeometryRef?: ResolvedFeatureGeometryRef): CompiledQuery;
|