Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose WMS Layer and WFS FeatureType MetadataURLs #71

Merged
merged 5 commits into from
Oct 28, 2024
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
21 changes: 21 additions & 0 deletions fixtures/wfs/capabilities-pigma-1-0-0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
<SRS>EPSG:2154</SRS>
<LatLongBoundingBox minx="-1.9540704007796161" miny="42.73286181824404" maxx="1.496463327812538"
maxy="45.717071228823876"/>
<MetadataURL type="TC211" format="text/plain">
https://www.pigma.org/geonetwork/?uuid=cbcae9a4-7fc0-4fc8-bd78-089af3af4e8a
</MetadataURL>
</FeatureType>
<FeatureType>
<Name>cd16:comptages_routiers_l</Name>
Expand All @@ -222,6 +225,15 @@
<SRS>EPSG:2154</SRS>
<LatLongBoundingBox minx="-0.4906009184568518" miny="45.175543885638376" maxx="0.9778719979726385"
maxy="46.14349349624617"/>
<MetadataURL type="TC211" format="text/html">
https://www.pigma.org/geonetwork?uuid=4d840710-3f09-4f48-aa31-d2c4c0ee6fda
</MetadataURL>
<MetadataURL type="19115" format="text/html">
https://www.pigma.org/geonetwork?uuid=4d840710-3f09-4f48-aa31-d2c4c0ee6fda
</MetadataURL>
<MetadataURL type="19115" format="text/xml">
https://www.pigma.org/geonetwork/srv/fre/xml_iso19139?uuid=4d840710-3f09-4f48-aa31-d2c4c0ee6fda
</MetadataURL>
</FeatureType>
<FeatureType>
<Name>cd16:hierarchisation_l</Name>
Expand All @@ -235,6 +247,15 @@
<SRS>EPSG:2154</SRS>
<LatLongBoundingBox minx="-0.4832134559131876" miny="45.18037755571674" maxx="0.9725372441782966"
maxy="46.13877580094452"/>
<MetadataURL type="TC211" format="text/html">
https://www.pigma.org/geonetwork?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6
</MetadataURL>
<MetadataURL type="19115" format="text/html">
https://www.pigma.org/geonetwork?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6
</MetadataURL>
<MetadataURL type="19115" format="text/xml">
https://www.pigma.org/geonetwork/srv/fre/xml_iso19139?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6
</MetadataURL>
</FeatureType>
</FeatureTypeList>
<ogc:Filter_Capabilities>
Expand Down
3 changes: 0 additions & 3 deletions fixtures/wfs/capabilities-pigma-2-0-0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,6 @@
<ows:UpperCorner>1.496463327812538 45.717071228823876</ows:UpperCorner>
</ows:WGS84BoundingBox>
<MetadataURL xlink:href="https://www.pigma.org/geonetwork/?uuid=cbcae9a4-7fc0-4fc8-bd78-089af3af4e8a"/>
<MetadataURL xlink:href="https://www.pigma.org/geonetwork/?uuid=cbcae9a4-7fc0-4fc8-bd78-089af3af4e8a"/>
<MetadataURL
xlink:href="https://www.pigma.org/geonetwork/srv/fre/xml_iso19139?uuid=cbcae9a4-7fc0-4fc8-bd78-089af3af4e8a"/>
<OutputFormats>
<Format>application/gml+xml; version=3.2</Format>
<Format>text/xml; subtype=gml/3.2.1</Format>
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type {
Provider,
LayerStyle,
BoundingBox,
MetadataURL,
FetchOptions,
GenericEndpointInfo,
MimeType,
Expand Down
6 changes: 6 additions & 0 deletions src/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ export interface LayerStyle {
*/
legendUrl?: string;
}

export type MetadataURL = {
format?: string;
type?: string;
url: string;
};
63 changes: 62 additions & 1 deletion src/wfs/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ describe('WFS capabilities', () => {
-1.9540704007796161, 42.73286181824404, 1.496463327812538,
45.717071228823876,
],
metadata: [
{
format: 'text/plain',
type: 'TC211',
url: 'https://www.pigma.org/geonetwork/?uuid=cbcae9a4-7fc0-4fc8-bd78-089af3af4e8a',
},
],
name: 'asp:asp_rpg2010',
otherCrs: ['EPSG:32615', 'EPSG:32616', 'EPSG:32617', 'EPSG:32618'],
outputFormats: [
Expand All @@ -59,6 +66,23 @@ describe('WFS capabilities', () => {
-0.4906009184568518, 45.175543885638376, 0.9778719979726385,
46.14349349624617,
],
metadata: [
{
format: 'text/html',
type: 'TC211',
url: 'https://www.pigma.org/geonetwork?uuid=4d840710-3f09-4f48-aa31-d2c4c0ee6fda',
},
{
format: 'text/html',
type: '19115',
url: 'https://www.pigma.org/geonetwork?uuid=4d840710-3f09-4f48-aa31-d2c4c0ee6fda',
},
{
format: 'text/xml',
type: '19115',
url: 'https://www.pigma.org/geonetwork/srv/fre/xml_iso19139?uuid=4d840710-3f09-4f48-aa31-d2c4c0ee6fda',
},
],
name: 'cd16:comptages_routiers_l',
otherCrs: ['EPSG:32615', 'EPSG:32616', 'EPSG:32617', 'EPSG:32618'],
outputFormats: [
Expand All @@ -80,6 +104,23 @@ describe('WFS capabilities', () => {
46.13877580094452,
],
name: 'cd16:hierarchisation_l',
metadata: [
{
format: 'text/html',
type: 'TC211',
url: 'https://www.pigma.org/geonetwork?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6',
},
{
format: 'text/html',
type: '19115',
url: 'https://www.pigma.org/geonetwork?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6',
},
{
format: 'text/xml',
type: '19115',
url: 'https://www.pigma.org/geonetwork/srv/fre/xml_iso19139?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6',
},
],
otherCrs: ['EPSG:32615', 'EPSG:32616', 'EPSG:32617', 'EPSG:32618'],
outputFormats: [
'application/gml+xml; version=3.2',
Expand All @@ -92,7 +133,13 @@ describe('WFS capabilities', () => {
];
it('reads the feature types (2.0.0)', () => {
const doc = parseXmlString(capabilities200);
expect(readFeatureTypesFromCapabilities(doc)).toEqual(expectedTypes);
const typesWithoutMetadataUrlAttributes = expectedTypes.map((type) => ({
...type,
metadata: type.metadata.map((metadata) => ({ url: metadata.url })),
}));
expect(readFeatureTypesFromCapabilities(doc)).toEqual(
typesWithoutMetadataUrlAttributes
);
});
it('reads the feature types (1.1.0)', () => {
const doc = parseXmlString(capabilities110);
Expand Down Expand Up @@ -139,6 +186,20 @@ describe('WFS capabilities', () => {
1.3472171890368316, 48.82764887581316, 4.285589467078578,
51.0896786738123,
],
metadata: [
{
url: 'https://www.geo2france.fr/geonetwork/srv/fre/catalog.search#/metadata/facf3747-bc19-44c7-9fd8-1f765d99c059',
},
{
url: 'https://www.geo2france.fr/geonetwork/srv/fre/catalog.search#/metadata/facf3747-bc19-44c7-9fd8-1f765d99c059',
},
{
url: 'https://www.geo2france.fr/geonetwork/srv/api/records/facf3747-bc19-44c7-9fd8-1f765d99c059/formatters/xml',
},
{
url: 'https://www.geo2france.fr/geonetwork/srv/api/records/facf3747-bc19-44c7-9fd8-1f765d99c059/formatters/xml',
},
],
name: 'cr_hdf:domaine_public_hdf_com',
otherCrs: [],
outputFormats: [
Expand Down
17 changes: 17 additions & 0 deletions src/wfs/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ function parseFeatureType(
)
.map(getElementText)
.filter((v, i, arr) => arr.indexOf(v) === i);

const metadata =
serviceVersion === '2.0.0'
? findChildrenElement(featureTypeEl, 'MetadataURL').map(
(metadataUrlEl) => ({
url: getElementAttribute(metadataUrlEl, 'xlink:href'),
})
)
: findChildrenElement(featureTypeEl, 'MetadataURL').map(
(metadataUrlEl) => ({
format: getElementAttribute(metadataUrlEl, 'format'),
type: getElementAttribute(metadataUrlEl, 'type'),
url: getElementText(metadataUrlEl).trim(),
})
);

return {
name: getElementText(findChildElement(featureTypeEl, 'Name')),
title: getElementText(findChildElement(featureTypeEl, 'Title')),
Expand All @@ -189,5 +205,6 @@ function parseFeatureType(
? parseBBox100()
: parseBBox(),
keywords: keywords,
...(metadata.length && { metadata }),
};
}
22 changes: 22 additions & 0 deletions src/wfs/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ describe('WfsEndpoint', () => {
],
defaultCrs: 'EPSG:2154',
keywords: ['features', 'hierarchisation_l'],
metadata: [
{
url: 'https://www.pigma.org/geonetwork?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6',
},
{
url: 'https://www.pigma.org/geonetwork?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6',
},
{
url: 'https://www.pigma.org/geonetwork/srv/fre/xml_iso19139?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6',
},
],
otherCrs: ['EPSG:32615', 'EPSG:32616', 'EPSG:32617', 'EPSG:32618'],
outputFormats: [
'application/gml+xml; version=3.2',
Expand Down Expand Up @@ -186,6 +197,17 @@ describe('WfsEndpoint', () => {
],
defaultCrs: 'EPSG:2154',
keywords: ['features', 'hierarchisation_l'],
metadata: [
{
url: 'https://www.pigma.org/geonetwork?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6',
},
{
url: 'https://www.pigma.org/geonetwork?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6',
},
{
url: 'https://www.pigma.org/geonetwork/srv/fre/xml_iso19139?uuid=cd27adaa-0ec5-4934-9374-143df09fb9f6',
},
],
otherCrs: ['EPSG:32615', 'EPSG:32616', 'EPSG:32617', 'EPSG:32618'],
outputFormats: [
'application/gml+xml; version=3.2',
Expand Down
1 change: 1 addition & 0 deletions src/wfs/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default class WfsEndpoint {
otherCrs: featureType.otherCrs,
outputFormats: featureType.outputFormats,
keywords: featureType.keywords,
...('metadata' in featureType && { metadata: featureType.metadata }),
} as WfsFeatureTypeSummary;
}

Expand Down
2 changes: 2 additions & 0 deletions src/wfs/featuretypeinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function parseFeatureTypeInfo(
outputFormats,
latLonBoundingBox: boundingBox,
keywords,
metadata,
} = featureType;

const hitsAttr = serviceVersion.startsWith('2.0')
Expand Down Expand Up @@ -79,6 +80,7 @@ export function parseFeatureTypeInfo(
...(geometryType && { geometryType }),
...(!Number.isNaN(objectCount) && { objectCount }),
...(keywords && { keywords }),
...(metadata && { metadata }),
};
}

Expand Down
9 changes: 8 additions & 1 deletion src/wfs/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { BoundingBox, CrsCode, MimeType } from '../shared/models.js';
import {
BoundingBox,
CrsCode,
MetadataURL,
MimeType,
} from '../shared/models.js';

export type WfsVersion = '1.0.0' | '1.1.0' | '2.0.0';

Expand All @@ -11,6 +16,7 @@ export type WfsFeatureTypeInternal = {
outputFormats: MimeType[];
latLonBoundingBox?: BoundingBox;
keywords?: string[];
metadata?: MetadataURL[];
};

export type FeaturePropertyType = string | number | boolean;
Expand Down Expand Up @@ -46,6 +52,7 @@ export type WfsFeatureTypeSummary = {
otherCrs: CrsCode[];
outputFormats: MimeType[];
keywords?: string[];
metadata?: MetadataURL[];
};

export type WfsFeatureTypeFull = {
Expand Down
21 changes: 21 additions & 0 deletions src/wms/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ describe('WMS capabilities', () => {
keywords: ['Geologie', 'INSPIRE:Geology', 'Geology'],
maxScaleDenominator: 1e7,
minScaleDenominator: 200000,
metadata: [
{
format: 'text/xml',
type: 'TC211',
url: 'http://www.geocatalogue.fr/api-public/servicesRest?Service=CSW&Request=GetRecordById&Version=2.0.2&id=BR_CAR_ADA&outputSchema=http://www.isotc211.org/2005/gmd&elementSetName=full',
},
],
name: 'SCAN_F_GEOL1M',
queryable: false,
opaque: false,
Expand Down Expand Up @@ -191,6 +198,13 @@ describe('WMS capabilities', () => {
maxScaleDenominator: 500000,
minScaleDenominator: 80000,
name: 'SCAN_F_GEOL250',
metadata: [
{
format: 'text/xml',
type: 'TC211',
url: 'http://www.geocatalogue.fr/api-public/servicesRest?Service=CSW&Request=GetRecordById&Version=2.0.2&id=BR_CAR_ACA&outputSchema=http://www.isotc211.org/2005/gmd&elementSetName=full',
},
],
queryable: true,
opaque: true,
styles,
Expand Down Expand Up @@ -233,6 +247,13 @@ describe('WMS capabilities', () => {
maxScaleDenominator: 251000,
minScaleDenominator: 9000,
name: 'SCAN_D_GEOL50',
metadata: [
{
format: 'text/xml',
type: 'TC211',
url: 'http://www.geocatalogue.fr/api-public/servicesRest?Service=CSW&Request=GetRecordById&Version=2.0.2&id=72cc8d40-1bb6-41a3-8376-9734f23336ff&outputSchema=http://www.isotc211.org/2005/gmd&elementSetName=full',
},
],
queryable: true,
opaque: true,
styles,
Expand Down
12 changes: 12 additions & 0 deletions src/wms/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ function parseLayer(
[minScaleDenominator, maxScaleDenominator] = parseScaleHint();
}

const metadata = findChildrenElement(layerEl, 'MetadataURL').map(
(metadataUrlEl) => ({
type: getElementAttribute(metadataUrlEl, 'type'),
format: getElementText(findChildElement(metadataUrlEl, 'Format')),
url: getElementAttribute(
findChildElement(metadataUrlEl, 'OnlineResource'),
'xlink:href'
),
})
);

const children = findChildrenElement(layerEl, 'Layer').map((layer) =>
parseLayer(
layer,
Expand All @@ -276,6 +287,7 @@ function parseLayer(
opaque,
...(minScaleDenominator !== null ? { minScaleDenominator } : {}),
...(maxScaleDenominator !== null ? { maxScaleDenominator } : {}),
...(metadata.length && { metadata }),
...(children.length && { children }),
};
}
Expand Down
8 changes: 7 additions & 1 deletion src/wms/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { BoundingBox, CrsCode, LayerStyle } from '../shared/models.js';
import {
BoundingBox,
CrsCode,
LayerStyle,
type MetadataURL,
} from '../shared/models.js';

export type WmsLayerAttribution = {
title?: string;
Expand Down Expand Up @@ -38,6 +43,7 @@ export type WmsLayerFull = {
minScaleDenominator?: number;
attribution?: WmsLayerAttribution;
keywords?: string[];
metadata?: MetadataURL[];
/**
* Not defined if the layer is a leaf in the tree
*/
Expand Down
Loading