Skip to content

Commit

Permalink
feat(iso-converter): use single geometry for spatial extent
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Aug 1, 2024
1 parent f924559 commit 986c82d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 54 deletions.
24 changes: 11 additions & 13 deletions libs/api/metadata-converter/src/lib/fixtures/geocat-ch.records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,22 +342,20 @@ Die Quelle ist zu bezeichnen: „Quelle: Stadt Zürich“.`,
],
},
{
geometries: [
{
type: 'MultiPolygon',
coordinates: [
geometry: {
type: 'MultiPolygon',
coordinates: [
[
[
[
[6.777075, 45.827119, 0],
[6.755991, 47.517566, 0],
[10.541824, 47.477984, 0],
[10.446252, 45.788744, 0],
[6.777075, 45.827119, 0],
],
[6.777075, 45.827119, 0],
[6.755991, 47.517566, 0],
[10.541824, 47.477984, 0],
[10.446252, 45.788744, 0],
[6.777075, 45.827119, 0],
],
],
},
],
],
},
},
],
temporalExtents: [],
Expand Down
50 changes: 23 additions & 27 deletions libs/api/metadata-converter/src/lib/iso19139/read-parts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
// @ts-ignore
import GEOCAT_CH_DATASET from '../fixtures/geocat-ch.iso19139.dataset.xml'
// @ts-ignore
import { XmlElement } from '@rgrove/parse-xml'
// @ts-ignore
import GEOCAT_CH_SERVICE from '../fixtures/geocat-ch.iso19139.service.xml'
import { pipe } from '../function-utils'
import {
Expand Down Expand Up @@ -448,22 +448,20 @@ describe('read parts', () => {
it('returns an array of spatial extents with geometries, bbox and description', () => {
expect(readSpatialExtents(recordRootEl)).toEqual([
{
geometries: [
{
type: 'MultiPolygon',
coordinates: [
geometry: {
type: 'MultiPolygon',
coordinates: [
[
[
[
[6.777075, 45.827119, 0],
[6.755991, 47.517566, 0],
[10.541824, 47.477984, 0],
[10.446252, 45.788744, 0],
[6.777075, 45.827119, 0],
],
[6.777075, 45.827119, 0],
[6.755991, 47.517566, 0],
[10.541824, 47.477984, 0],
[10.446252, 45.788744, 0],
[6.777075, 45.827119, 0],
],
],
},
],
],
},
bbox: [
6.75599105586694, 45.7887442565203, 10.5418236945627,
47.5175655551557,
Expand All @@ -486,22 +484,20 @@ describe('read parts', () => {
],
},
{
geometries: [
{
type: 'MultiPolygon',
coordinates: [
geometry: {
type: 'MultiPolygon',
coordinates: [
[
[
[
[6.777075, 45.827119, 0],
[6.755991, 47.517566, 0],
[10.541824, 47.477984, 0],
[10.446252, 45.788744, 0],
[6.777075, 45.827119, 0],
],
[6.777075, 45.827119, 0],
[6.755991, 47.517566, 0],
[10.541824, 47.477984, 0],
[10.446252, 45.788744, 0],
[6.777075, 45.827119, 0],
],
],
},
],
],
},
},
])
})
Expand Down
23 changes: 10 additions & 13 deletions libs/api/metadata-converter/src/lib/iso19139/read-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
UpdateFrequencyCustom,
} from '@geonetwork-ui/common/domain/model/record'
import { ThesaurusModel } from '@geonetwork-ui/common/domain/model/thesaurus'
import { Geometry } from 'geojson'
import { MultiPolygon, Polygon } from 'geojson'
import { matchMimeType, matchProtocol } from '../common/distribution.mapper'
import {
ChainableFunction,
Expand All @@ -28,15 +28,16 @@ import {
pipe,
} from '../function-utils'
import {
XmlElement,
findChildElement,
findChildrenElement,
findNestedElement,
findNestedElements,
findParent,
firstChildElement,
readAttribute,
readGeometry,
readText,
XmlElement,
} from '../xml-utils'
import { fullNameToParts } from './utils/individual-name'
import { getKeywordTypeFromKeywordTypeCode } from './utils/keyword.mapper'
Expand Down Expand Up @@ -907,16 +908,12 @@ export function readTemporalExtents(rootEl: XmlElement) {
}

export function readSpatialExtents(rootEl: XmlElement) {
const extractGeometries = (rootEl: XmlElement): Geometry[] => {
const extractGeometry = (rootEl: XmlElement): Polygon | MultiPolygon => {
if (!rootEl) return null
return pipe(
findChildrenElement('gmd:polygon', false),
mapArray((el) => {
const elements = el.children.filter(
(child) => child instanceof XmlElement
)
return readGeometry(elements[0] as XmlElement)
})
findChildElement('gmd:polygon', false),
firstChildElement,
map((el) => readGeometry(el) as Polygon | MultiPolygon)
)(rootEl)
}

Expand Down Expand Up @@ -951,17 +948,17 @@ export function readSpatialExtents(rootEl: XmlElement) {
findNestedElements('gmd:extent', 'gmd:EX_Extent', 'gmd:geographicElement'),
mapArray(
combine(
pipe(findChildElement('gmd:EX_BoundingPolygon'), extractGeometries),
pipe(findChildElement('gmd:EX_BoundingPolygon'), extractGeometry),
pipe(findChildElement('gmd:EX_GeographicBoundingBox'), extractBBox),
pipe(
findChildElement('gmd:EX_GeographicDescription'),
extractDescription
)
)
),
mapArray(([geometries, bbox, description]) => {
mapArray(([geometry, bbox, description]) => {
return {
...(geometries && { geometries }),
...(geometry && { geometry }),
...(bbox && { bbox }),
...(description && { description }),
}
Expand Down
5 changes: 5 additions & 0 deletions libs/api/metadata-converter/src/lib/xml-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import GeoJSON from 'ol/format/GeoJSON'
import GML32 from 'ol/format/GML32'
import { parse } from 'ol/xml'
import { ChainableFunction, fallback } from './function-utils'

export { XmlDocument, XmlElement } from '@rgrove/parse-xml'

export class XmlParseError extends Error {
Expand Down Expand Up @@ -119,6 +120,10 @@ export function allChildrenElement(element: XmlElement): Array<XmlElement> {
] as Array<XmlElement>
}

export function firstChildElement(element: XmlElement): XmlElement {
return allChildrenElement(element)[0] ?? null
}

/**
* Will return all matching elements nested according to the given
* names (similar to a path), starting form the input element;
Expand Down
2 changes: 1 addition & 1 deletion libs/common/domain/src/lib/model/record/metadata.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ export interface GraphicOverview {
}

export interface DatasetSpatialExtent {
geometries?: Geometry[]
bbox?: [number, number, number, number]
geometry?: Geometry
description?: string
}

Expand Down

0 comments on commit 986c82d

Please sign in to comment.