Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -602,19 +602,35 @@ export function getSpatialFilter(input: GpfWfsGetFeaturesInput): SpatialFilter |
}

/**
* Builds the list of non-geometric properties to request from the WFS layer.
* Build the list of property names to return in the WFS response according to the `select` and `result_type` input parameters.
*
* Note that :
* - When `select` is omitted and `result_type` is `results`, all non-geometric properties are returned.
* - When `select` is provided, the specified properties are validated according to the featureType from the Catalog.
*
* @param featureType Feature type definition loaded from the embedded catalog.
* @param geometryProperty Geometry property already resolved for the feature type.
* @param input Normalized tool input.
* @returns The list of selected property names, or every non-geometric property when `select` is omitted.
* @returns The list of non-geometric property names to include in the WFS `propertyName` parameter, or an empty list to include all properties.
*
*/
function buildSelectList(featureType: Collection, geometryProperty: CollectionProperty, input: GpfWfsGetFeaturesInput) {
return input.select && input.select.length > 0
? input.select.map((propertyName) => compileSelectProperty(featureType, geometryProperty, propertyName))
: featureType.properties
// if `select` is specified, we only return the requested properties (after validation)
if (input.select && input.select.length > 0) {
return input.select.map((propertyName) => compileSelectProperty(featureType, geometryProperty, propertyName));
}

// if `select` is omitted and result_type is `results`,
// we return every non-geometric property
if (input.result_type === "results") {
return featureType.properties
.filter((property) => !property.defaultCrs)
.map((property) => property.name);
}

// if `select` is omitted and result_type is `hits` or `request`
// we don't specify any propertyName
return [];
}

// --- Query Compilation ---
Expand Down
8 changes: 4 additions & 4 deletions src/tools/GpfWfsGetFeaturesTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { wfsClient } from "../gpf/wfs.js";
import { fetchJSONPost } from "../helpers/http.js";
import logger from "../logger.js";
import { READ_ONLY_OPEN_WORLD_TOOL_ANNOTATIONS } from "../helpers/toolAnnotations.js";
import { compileQueryParts, geometryToEwkt, getGeometryProperty, getSpatialFilter } from "./gpfWfsGetFeatures/compile.js";
import { buildMainRequest, buildReferenceGeometryRequest, type CompiledRequest } from "./gpfWfsGetFeatures/request.js";
import { transformFeatureCollectionResponse } from "./gpfWfsGetFeatures/response.js";
import { compileQueryParts, geometryToEwkt, getGeometryProperty, getSpatialFilter } from "../helpers/wfs_internal/compile.js";
import { buildMainRequest, buildReferenceGeometryRequest, type CompiledRequest } from "../helpers/wfs_internal/request.js";
import { transformFeatureCollectionResponse } from "../helpers/wfs_internal/response.js";
import {
gpfWfsGetFeaturesHitsOutputSchema,
gpfWfsGetFeaturesInputSchema,
type GpfWfsGetFeaturesInput,
gpfWfsGetFeaturesPublishedInputSchema,
gpfWfsGetFeaturesRequestOutputSchema,
} from "./gpfWfsGetFeatures/schema.js";
} from "../helpers/wfs_internal/schema.js";

class GpfWfsGetFeaturesTool extends MCPTool<GpfWfsGetFeaturesInput> {
name = "gpf_wfs_get_features";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Collection } from "@ignfab/gpf-schema-store";

import { compileQueryParts, geometryToEwkt } from "../../src/tools/gpfWfsGetFeatures/compile";
import type { GpfWfsGetFeaturesInput } from "../../src/tools/gpfWfsGetFeatures/schema";
import { compileQueryParts, geometryToEwkt } from "../../../src/helpers/wfs_internal/compile";
import type { GpfWfsGetFeaturesInput } from "../../../src/helpers/wfs_internal/schema";

describe("gpfWfsGetFeatures/compile", () => {
const featureType: Collection = {
Expand Down Expand Up @@ -119,4 +119,5 @@ describe("gpfWfsGetFeatures/compile", () => {
expect(geometryToEwkt({ type: "MultiPoint", coordinates: [[2.3, 48.8], [2.4, 48.9]] })).toEqual("SRID=4326;MULTIPOINT((2.3 48.8),(2.4 48.9))");
expect(geometryToEwkt({ type: "LineString", coordinates: [[2.3, 48.8], [2.4, 48.9]] })).toEqual("SRID=4326;LINESTRING(2.3 48.8,2.4 48.9)");
});

});
Loading