From b3ca4d5d1bd1474ee65074531f546098ea3857e5 Mon Sep 17 00:00:00 2001 From: Matteo V Date: Thu, 19 Oct 2023 10:07:11 +0200 Subject: [PATCH] Fix #9620 better error handling of GeoProcessing (#9621) --- .../actions/__tests__/geoProcessing-test.js | 6 +- web/client/actions/geoProcessing.js | 5 +- web/client/epics/geoProcessing.js | 121 +++++++++++++++--- web/client/observables/wfs.js | 4 +- web/client/plugins/GeoProcessing/processes.js | 7 +- .../reducers/__tests__/geoProcessing-test.js | 2 - web/client/reducers/geoProcessing.js | 13 +- web/client/translations/data.de-DE.json | 6 +- web/client/translations/data.en-US.json | 6 +- web/client/translations/data.es-ES.json | 6 +- web/client/translations/data.fr-FR.json | 6 +- web/client/translations/data.it-IT.json | 6 +- web/client/utils/DebugUtils.js | 12 +- web/client/utils/GeoProcessingUtils.js | 25 ---- .../__tests__/GeoProcessingUtils-test.js | 55 -------- 15 files changed, 153 insertions(+), 127 deletions(-) delete mode 100644 web/client/utils/GeoProcessingUtils.js delete mode 100644 web/client/utils/__tests__/GeoProcessingUtils-test.js diff --git a/web/client/actions/__tests__/geoProcessing-test.js b/web/client/actions/__tests__/geoProcessing-test.js index cde8b35cde..2c25e213c8 100644 --- a/web/client/actions/__tests__/geoProcessing-test.js +++ b/web/client/actions/__tests__/geoProcessing-test.js @@ -164,14 +164,16 @@ describe('Test Geo Processing Tools related actions', () => { const source = ""; const data = {}; const nextPage = 2; + const geometryProperty = {}; - const action = setFeatures(layerId, source, data, nextPage); + const action = setFeatures(layerId, source, data, nextPage, geometryProperty); expect(action).toEqual({ type: SET_FEATURES, layerId, source, data, - nextPage + nextPage, + geometryProperty }); }); it('setFeatureSourceLoading', () => { diff --git a/web/client/actions/geoProcessing.js b/web/client/actions/geoProcessing.js index e54541be34..33c3c2e865 100644 --- a/web/client/actions/geoProcessing.js +++ b/web/client/actions/geoProcessing.js @@ -197,12 +197,13 @@ export const setBufferCapStyle = (capStyle) => ({ * @param {string} source can be "source" or "intersection" * @param {object[]|object} data list of features or error */ -export const setFeatures = (layerId, source, data, nextPage) => ({ +export const setFeatures = (layerId, source, data, nextPage, geometryProperty) => ({ type: SET_FEATURES, layerId, source, data, - nextPage + nextPage, + geometryProperty }); /** * action for the loading flag of the features diff --git a/web/client/epics/geoProcessing.js b/web/client/epics/geoProcessing.js index e5812825b7..1627ba6d6c 100644 --- a/web/client/epics/geoProcessing.js +++ b/web/client/epics/geoProcessing.js @@ -130,9 +130,10 @@ import { calculateDistance } from "../utils/CoordinatesUtils"; import {buildIdentifyRequest} from "../utils/MapInfoUtils"; +import {logError} from "../utils/DebugUtils"; import {getFeatureInfo} from "../api/identify"; import {getFeatureSimple} from '../api/WFS'; -import {findNonGeometryProperty} from '../utils/ogc/WFS/base'; +import {findNonGeometryProperty, findGeometryProperty} from '../utils/ogc/WFS/base'; import toWKT from '../utils/ogc/WKT/toWKT'; const OFFSET = 550; @@ -211,7 +212,7 @@ export const checkWPSAvailabilityGPTEpic = (action$, store) => action$ ); }) .catch((e) => { - console.error(e); + logError(e); return Rx.Observable.of( setWPSAvailability(layerId, false, source), checkingWPS(false) @@ -260,6 +261,7 @@ export const getFeaturesGPTEpic = (action$, store) => action$ startIndex: page * maxFeatures, maxFeatures }; + const geometryProperty = findGeometryProperty(layer.describeFeatureType); return Rx.Observable.merge( getLayerJSONFeature({ ...layer, @@ -269,9 +271,19 @@ export const getFeaturesGPTEpic = (action$, store) => action$ url: layer.url } }, filterObj, options) - .map(data => setFeatures(layerId, source, data, page)) - .catch(error => { - return Rx.Observable.of(setFeatures(layerId, source, error, page)); + .map(data => setFeatures(layerId, source, data, page, geometryProperty)) + .catch(e => { + logError(e); + return Rx.Observable.of( + setFeatures(layerId, source, e, page, geometryProperty), + showErrorNotification({ + title: "errorTitleDefault", + message: "GeoProcessing.notifications.errorGettingFeaturesList", + autoDismiss: 6, + position: "tc", + values: {layerName: layer.name + " - " + layer.title} + }) + ); }) .startWith(setFeatureLoading(true)) .concat(Rx.Observable.of(setFeatureLoading(false)))); @@ -316,7 +328,8 @@ export const getFeatureDataGPTEpic = (action$, store) => action$ ]); }) - .catch(() => { + .catch((e) => { + logError(e); return Rx.Observable.of(showErrorNotification({ title: "errorTitleDefault", message: "GeoProcessing.notifications.errorGetFeature", @@ -364,7 +377,8 @@ export const getIntersectionFeatureDataGPTEpic = (action$, store) => action$ ]); }) - .catch(() => { + .catch((e) => { + logError(e); return Rx.Observable.of(showErrorNotification({ title: "errorTitleDefault", message: "GeoProcessing.notifications.errorGetFeature", @@ -486,7 +500,8 @@ export const runBufferProcessGPTEpic = (action$, store) => action$ ) ); }) - .catch(() => { + .catch((e) => { + logError(e); return Rx.Observable.of(showErrorNotification({ title: "errorTitleDefault", message: "GeoProcessing.notifications.errorBuffer", @@ -504,19 +519,34 @@ export const runBufferProcessGPTEpic = (action$, store) => action$ executeOptions, { headers: {'Content-Type': 'application/xml', 'Accept': `application/xml, application/json`} - }).catch(() => { - return Rx.Observable.of(showErrorNotification({ - title: "errorTitleDefault", - message: "GeoProcessing.notifications.errorBuffer", - autoDismiss: 6, - position: "tc" - })); - }); + }) + .catch((e) => { + logError(e); + return Rx.Observable.of({error: e, layerName: layer.name, layerTitle: layer.title}); + }); return executeCollectProcess$ - .switchMap((geom) => { + .switchMap((result) => { + if (result.error) { + if (result.error.message.includes("Failed to retrieve value for input features")) { + console.error("layerName " + result.layerName + " - " + result.layerTitle); + return Rx.Observable.of(showErrorNotification({ + title: "errorTitleDefault", + message: "GeoProcessing.notifications.errorGettingFC", + autoDismiss: 6, + position: "tc", + values: {layerName: result.layerName + " - " + result.layerTitle} + })); + } + return Rx.Observable.of(showErrorNotification({ + title: "errorTitleDefault", + message: "GeoProcessing.notifications.errorBuffer", + autoDismiss: 6, + position: "tc" + })); + } const ft = { type: "Feature", - geometry: geom + geometry: result }; const featureReprojected = reprojectGeoJson(ft, "EPSG:4326", "EPSG:3857"); const geometry3857 = toWKT(featureReprojected.geometry); @@ -574,6 +604,10 @@ export const runIntersectProcessGPTEpic = (action$, store) => action$ executeOptions, { headers: {'Content-Type': 'application/xml', 'Accept': `application/xml, application/json`} + }) + .catch((e) => { + logError(e); + return Rx.Observable.of({error: e, layerName: layer.name, layerTitle: layer.title}); }); } else { sourceFC$ = Rx.Observable.of(sourceFeature.geometry); @@ -588,12 +622,46 @@ export const runIntersectProcessGPTEpic = (action$, store) => action$ executeOptions, { headers: {'Content-Type': 'application/xml', 'Accept': `application/xml, application/json`} + }) + .catch((e) => { + logError(e); + return Rx.Observable.of({error: e, layerName: intersectionLayer.name, layerTitle: intersectionLayer.title}); }); } else { intersectionFC$ = Rx.Observable.of(intersectionFeature.geometry); } return Rx.Observable.forkJoin(sourceFC$, intersectionFC$) .switchMap(([firstGeom, secondGeom]) => { + if (firstGeom?.error || secondGeom?.error) { + const errorActions = []; + if (firstGeom?.error?.message?.includes("Failed to retrieve value for input features")) { + logError(firstGeom.error); + errorActions.push(showErrorNotification({ + title: "errorTitleDefault", + message: "GeoProcessing.notifications.errorGettingFC", + autoDismiss: 6, + position: "tc", + values: {layerName: firstGeom.layerName + " - " + firstGeom.layerTitle} + })); + } + if (secondGeom?.error?.message?.includes("Failed to retrieve value for input features")) { + logError(secondGeom.error); + errorActions.push(showErrorNotification({ + title: "errorTitleDefault", + message: "GeoProcessing.notifications.errorGettingFC", + autoDismiss: 6, + position: "tc", + values: {layerName: secondGeom.layerName + " - " + secondGeom.layerTitle} + })); + } + errorActions.push(showErrorNotification({ + title: "errorTitleDefault", + message: "GeoProcessing.notifications.errorIntersectGFI", + autoDismiss: 6, + position: "tc" + })); + return Rx.Observable.from(errorActions); + } const executeProcess$ = executeProcess( layerUrl, @@ -616,7 +684,16 @@ export const runIntersectProcessGPTEpic = (action$, store) => action$ .switchMap((featureCollection) => { const groups = groupsSelector(state); const groupExist = find(groups, (g) => g.id === GPT_INTERSECTION_GROUP_ID); - const extent = getGeoJSONExtent(featureCollection); + let extent = getGeoJSONExtent(featureCollection); + if (extent.some(coord => coord === Infinity )) { + // intersection is empty, return a message + return Rx.Observable.of(showErrorNotification({ + title: "errorTitleDefault", + message: "GeoProcessing.notifications.emptyIntersection", + autoDismiss: 6, + position: "tc" + })); + } return (!groupExist ? Rx.Observable.of( addGroup("Intersected Layers", null, {id: GPT_INTERSECTION_GROUP_ID}, true)) : Rx.Observable.empty()) .concat( Rx.Observable.of( @@ -665,7 +742,8 @@ export const runIntersectProcessGPTEpic = (action$, store) => action$ }) )); }) - .catch(() => { + .catch((e) => { + logError(e); return Rx.Observable.of(showErrorNotification({ title: "errorTitleDefault", message: "GeoProcessing.notifications.errorIntersectGFI", @@ -804,7 +882,8 @@ export const clickToSelectFeatureGPTEpic = (action$, {getState}) => position: "tc" })); }) - .catch(() => { + .catch((e) => { + logError(e); return Rx.Observable.of(showErrorNotification({ title: "errorTitleDefault", message: "GeoProcessing.notifications.errorGFI", diff --git a/web/client/observables/wfs.js b/web/client/observables/wfs.js index 6a3e2250a0..f4ceb01995 100644 --- a/web/client/observables/wfs.js +++ b/web/client/observables/wfs.js @@ -8,7 +8,7 @@ import urlUtil from 'url'; -import { castArray, isNil, isObject } from 'lodash'; +import { isArray, castArray, isNil, isObject } from 'lodash'; import Rx from 'rxjs'; import { parseString } from 'xml2js'; import { stripPrefix } from 'xml2js/lib/processors'; @@ -259,7 +259,7 @@ export const getLayerJSONFeature = ({ search = {}, url, name } = {}, filter, {so } : getFeature( query(name, [ - sortBy(pn[0]), + sortBy(isArray(pn) ? pn[0] : pn), ...(pn ? [propertyName(pn)] : []), ...(filter ? castArray(filter) : []) ]), diff --git a/web/client/plugins/GeoProcessing/processes.js b/web/client/plugins/GeoProcessing/processes.js index 9b7feb7edc..918e02b5ec 100644 --- a/web/client/plugins/GeoProcessing/processes.js +++ b/web/client/plugins/GeoProcessing/processes.js @@ -115,10 +115,11 @@ export const processes = [ {props.runningProcess ? : null} ); diff --git a/web/client/reducers/__tests__/geoProcessing-test.js b/web/client/reducers/__tests__/geoProcessing-test.js index f84fc834a3..2ba78ba090 100644 --- a/web/client/reducers/__tests__/geoProcessing-test.js +++ b/web/client/reducers/__tests__/geoProcessing-test.js @@ -288,7 +288,6 @@ describe('Test Geo Processing Tools reducer', () => { }, action); expect(state.source.feature).toEqual(feature); expect(state.source.features).toEqual([feature]); - expect(state.flags.isIntersectionEnabled).toEqual(true); }); it('SET_INTERSECTION_LAYER_ID', () => { const layerId = "id"; @@ -354,7 +353,6 @@ describe('Test Geo Processing Tools reducer', () => { } }, action); expect(state.intersection.feature).toEqual(feature); - expect(state.flags.isIntersectionEnabled).toEqual(true); }); it('SET_INTERSECTION_FIRST_ATTRIBUTE', () => { const firstAttributeToRetain = "attr"; diff --git a/web/client/reducers/geoProcessing.js b/web/client/reducers/geoProcessing.js index d2254da865..b98623be84 100644 --- a/web/client/reducers/geoProcessing.js +++ b/web/client/reducers/geoProcessing.js @@ -46,7 +46,6 @@ import { RESET_CONTROLS } from '../actions/controls'; import { LOCATION_CHANGE } from 'connected-react-router'; -import { checkIfIntersectionIsPossible } from '../utils/GeoProcessingUtils'; /** * reducer for GeoProcessing @@ -208,6 +207,10 @@ function geoProcessing( state = { features: (state[action.source].features || []).concat(action.data.features || []), totalCount: action.data.totalFeatures, currentPage: action.nextPage + }, + flags: { + ...state.flags, + isIntersectionEnabled: action.source === "source" ? !action.geometryProperty?.type?.includes("Point") : state.flags.isIntersectionEnabled } } : { ...state, @@ -308,10 +311,6 @@ function geoProcessing( state = { ...state.source, feature: action.feature, features: find(state.source.features, ft => ft.id === action.feature.id) ? state.source.features : [action.feature] - }, - flags: { - ...state.flags, - isIntersectionEnabled: checkIfIntersectionIsPossible(action?.feature, state?.intersection?.feature) } }; } @@ -350,10 +349,6 @@ function geoProcessing( state = { ...state.intersection, feature: action.feature, features: find(state.intersection.features, ft => ft.id === action.feature.id) ? state.intersection.features : [action.feature] - }, - flags: { - ...state.flags, - isIntersectionEnabled: checkIfIntersectionIsPossible(state?.source?.feature, action?.feature) } }; } diff --git a/web/client/translations/data.de-DE.json b/web/client/translations/data.de-DE.json index 8a4116d145..286fa3bb6c 100644 --- a/web/client/translations/data.de-DE.json +++ b/web/client/translations/data.de-DE.json @@ -3947,7 +3947,10 @@ "noLayerSelected": "Bitte wählen Sie zuerst die Ebene aus.", "successfulIntersection": "Der Schnittvorgang war erfolgreich und ein neuer Layer wurde erstellt und dem Inhaltsverzeichnis hinzugefügt", "successfulBuffer": "Der Puffervorgang war erfolgreich und eine neue Ebene wurde erstellt und dem Inhaltsverzeichnis hinzugefügt", - "errorBuffer": "Der Puffervorgang ist fehlgeschlagen" + "errorBuffer": "Der Puffervorgang ist fehlgeschlagen", + "emptyIntersection": "Es gibt keine Schnittmenge zwischen den angegebenen Datensätzen.", + "errorGettingFC": "Es war nicht möglich, die Geometrie aus der Ebene zu erfassen {layerName}", + "errorGettingFeaturesList": "Es war nicht möglich, die Liste der Features aus dem Layer abzurufen {layerName}" }, "warningTitle": "Warnung", "warningBody": "Sie haben keine Funktion ausgewählt und dies kann die Leistung im Geoserver verlangsamen. Möchten Sie fortfahren?", @@ -3958,6 +3961,7 @@ "invalidLayers": "Eine der von Ihnen ausgewählten Ebenen kann in diesem Prozess nicht verwendet werden", "fillRequiredDataIntersection": "Bitte wählen Sie mindestens den Quell-Layer und den Schnittpunkt-Layer aus", "fillRequiredDataBuffer": "Bitte wählen Sie mindestens die Quellebene aus", + "pointAndPolygon": "Sie können einen Punktlayer nur für den Schnittpunktlayer auswählen", "siderBarBtn": "Geoverarbeitung", "selectFeature": "Bitte wählen Sie eine Funktion aus", "validFeature": "Diese Funktion ist gültig", diff --git a/web/client/translations/data.en-US.json b/web/client/translations/data.en-US.json index c2a0536341..60abe63d93 100644 --- a/web/client/translations/data.en-US.json +++ b/web/client/translations/data.en-US.json @@ -3921,7 +3921,10 @@ "noLayerSelected": "Please select layer first.", "successfulIntersection": "The intersection operation was successful and a new layer has ben created and added to the TOC", "successfulBuffer": "The Buffer operation was successful and a new layer has ben created and added to the TOC", - "errorBuffer": "The Buffer operation has failed" + "errorBuffer": "The Buffer operation has failed", + "emptyIntersection": "There is no intersection between the given datasets.", + "errorGettingFC": "It was not possible to collect the geometry from the layer {layerName}", + "errorGettingFeaturesList": "It was not possible to fetch the list of features from the layer {layerName}" }, "warningTitle": "Warning", "warningBody": "You have not selected a feature and this may slow down performances in geoserver. Do you want to continue?", @@ -3932,6 +3935,7 @@ "invalidLayers": "One of the layers you have selected cannot be used within this process", "fillRequiredDataIntersection": "Please select at least the source layer and the intersection layer", "fillRequiredDataBuffer": "Please select at least the source layer", + "pointAndPolygon": "You can select a point layer only for the intersection layer", "siderBarBtn": "GeoProcessing", "selectFeature": "Please select a feature", "validFeature": "This feature is valid", diff --git a/web/client/translations/data.es-ES.json b/web/client/translations/data.es-ES.json index 29915f10c3..a36bc8efa3 100644 --- a/web/client/translations/data.es-ES.json +++ b/web/client/translations/data.es-ES.json @@ -3910,7 +3910,10 @@ "noLayerSelected": "Por favor seleccione la capa primero.", "successfulIntersection": "La operación de intersección fue exitosa y se creó una nueva capa y se agregó a la tabla de contenido", "successfulBuffer": "La operación de búfer fue exitosa y se creó una nueva capa y se agregó a la tabla de contenido", - "errorBuffer": "La operación de búfer ha fallado" + "errorBuffer": "La operación de búfer ha fallado", + "emptyIntersection": "No hay intersección entre los conjuntos de datos dados.", + "errorGettingFC": "No fue posible recopilar la geometría de la capa {layerName}", + "errorGettingFeaturesList": "No fue posible recuperar la lista de entidades de la capa {layerName}" }, "warningTitle": "Advertencia", "warningBody": "No ha seleccionado una función y esto puede ralentizar el rendimiento en el geoservidor. ¿Desea continuar?", @@ -3921,6 +3924,7 @@ "invalidLayers": "Una de las capas que ha seleccionado no se puede utilizar dentro de este proceso", "fillRequiredDataIntersection": "Seleccione al menos la capa de origen y la capa de intersección", "fillRequiredDataBuffer": "Seleccione al menos la capa de origen", + "pointAndPolygon": "Puede seleccionar una capa de puntos solo para la capa de intersección", "siderBarBtn": "Geoprocesamiento", "selectFeature": "Seleccione una función", "validFeature": "Esta función es válida", diff --git a/web/client/translations/data.fr-FR.json b/web/client/translations/data.fr-FR.json index 6b0185a3e2..88edbd4839 100644 --- a/web/client/translations/data.fr-FR.json +++ b/web/client/translations/data.fr-FR.json @@ -3910,7 +3910,10 @@ "noLayerSelected": "Veuillez d'abord sélectionner le calque.", "successfulIntersection": "L'opération d'intersection a réussi et une nouvelle couche a été créée et ajoutée à la table des matières", "successfulBuffer": "L'opération Buffer a réussi et une nouvelle couche a été créée et ajoutée à la table des matières", - "errorBuffer": "L'opération Buffer a échoué" + "errorBuffer": "L'opération Buffer a échoué", + "emptyIntersection": "Il n'y a pas d'intersection entre les ensembles de données donnés.", + "errorGettingFC": "Il n'a pas été possible de collecter la géométrie du calque {layerName}", + "errorGettingFeaturesList": "Il n'a pas été possible de récupérer la liste des entités de la couche {layerName}" }, "warningTitle": "Avertissement", "warningBody": "Vous n'avez pas sélectionné de fonctionnalité et cela peut ralentir les performances de geoserver. Voulez-vous continuer ?", @@ -3921,6 +3924,7 @@ "invalidLayers": "L'un des calques que vous avez sélectionnés ne peut pas être utilisé dans ce processus", "fillRequiredDataIntersection": "Veuillez sélectionner au moins la couche source et la couche d'intersection", "fillRequiredDataBuffer": "Veuillez sélectionner au moins la couche source", + "pointAndPolygon": "Vous pouvez sélectionner une couche de points uniquement pour la couche d'intersection", "siderBarBtn": "Géotraitement", "selectFeature": "Veuillez sélectionner une fonctionnalité", "validFeature": "Cette fonctionnalité est valide", diff --git a/web/client/translations/data.it-IT.json b/web/client/translations/data.it-IT.json index 35651e3329..9422ce5ec9 100644 --- a/web/client/translations/data.it-IT.json +++ b/web/client/translations/data.it-IT.json @@ -3910,7 +3910,10 @@ "noLayerSelected": "Seleziona prima il livello.", "successfulIntersection": "L'operazione di intersezione è andata a buon fine e un nuovo livello è stato creato e aggiunto alla tabella dei contenuti", "successfulBuffer": "L'operazione Buffer è andata a buon fine e un nuovo livello è stato creato e aggiunto alla tabella dei contenuti", - "errorBuffer": "L'operazione Buffer è fallita" + "errorBuffer": "L'operazione Buffer è fallita", + "emptyIntersection": "Non c'è una interesezione tra i dati utilizzati.", + "errorGettingFC": "Non è stato possibile ottenere la collezione di geometrie dal layer {layerName}", + "errorGettingFeaturesList": "Non è stato possibile ottenere la lista di features dal layer {layerName}" }, "warningTitle": "Attenzione", "warningBody": "Non hai selezionato una funzione e questo potrebbe rallentare le prestazioni del geoserver. Vuoi continuare?", @@ -3921,6 +3924,7 @@ "invalidLayers": "Uno dei livelli che hai selezionato non può essere utilizzato all'interno di questo processo", "fillRequiredDataIntersection": "Seleziona almeno il livello di origine e il livello di intersezione", "fillRequiredDataBuffer": "Seleziona almeno il livello di origine", + "pointAndPolygon": "Puoi selezionare un livello puntuale solo per il livello di intersezione", "siderBarBtn": "Strumenti di geoelaborazione", "selectFeature": "Seleziona una funzione", "validFeature": "Questa feature è valida", diff --git a/web/client/utils/DebugUtils.js b/web/client/utils/DebugUtils.js index fb6731d1c2..a7419faf7b 100644 --- a/web/client/utils/DebugUtils.js +++ b/web/client/utils/DebugUtils.js @@ -11,13 +11,23 @@ import url from 'url'; const urlQuery = url.parse(window.location.href, true).query; +export const isDebugMode = () => { + return urlQuery && urlQuery.debug && __DEVTOOLS__; +}; + +export const logError = (error) => { + if (isDebugMode) { + console.error(error.message); + } +}; + export function createDebugStore(reducer, initialState, userMiddlewares, enhancer) { return createStore({ rootReducer: reducer, state: initialState, middlewares: userMiddlewares, enhancer, - debug: urlQuery && urlQuery.debug && __DEVTOOLS__ + debug: isDebugMode() }); } diff --git a/web/client/utils/GeoProcessingUtils.js b/web/client/utils/GeoProcessingUtils.js deleted file mode 100644 index 32407a7a21..0000000000 --- a/web/client/utils/GeoProcessingUtils.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2023, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -/** - * check if intersection is possible between two features - * @param {object} sourceFeature the geojson feature - * @param {object} intersectionFeature the geojson feature - * @returns {string} the converted string in wkt - */ -export const checkIfIntersectionIsPossible = (sourceFeature = {}, intersectionFeature = {}) => { - - if ( - sourceFeature?.geometry?.type.includes("Point") || - intersectionFeature?.geometry?.type.includes("Point") - ) { - return (sourceFeature?.geometry?.type.includes("Point") && intersectionFeature?.geometry?.type.includes("Polygon")) || - (intersectionFeature?.geometry?.type.includes("Point") && sourceFeature?.geometry?.type.includes("Polygon") ); - } - return true; -}; diff --git a/web/client/utils/__tests__/GeoProcessingUtils-test.js b/web/client/utils/__tests__/GeoProcessingUtils-test.js deleted file mode 100644 index 41ae87d656..0000000000 --- a/web/client/utils/__tests__/GeoProcessingUtils-test.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2023, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ -import expect from 'expect'; - -import { - checkIfIntersectionIsPossible -} from '../GeoProcessingUtils'; - - -describe('GeoProcessingUtils', () => { - const pointFT = { - type: "Feature", - geometry: { - coordinates: [1, 2], - type: "Point" - } - }; - const polygonFT = { - type: "Feature", - geometry: { - type: "Polygon" - } - }; - const lineStringFT = { - type: "Feature", - geometry: { - type: "LineString" - } - }; - describe('checkIfIntersectionIsPossible', () => { - - it('successful result', () => { - let result = checkIfIntersectionIsPossible(polygonFT, pointFT); - expect(result).toBeTruthy(); - result = checkIfIntersectionIsPossible(polygonFT, lineStringFT); - expect(result).toBeTruthy(); - result = checkIfIntersectionIsPossible(polygonFT, polygonFT); - expect(result).toBeTruthy(); - result = checkIfIntersectionIsPossible(lineStringFT, lineStringFT); - expect(result).toBeTruthy(); - }); - it(' failing result', () => { - let result = checkIfIntersectionIsPossible(lineStringFT, pointFT); - expect(result).toBeFalsy(); - result = checkIfIntersectionIsPossible(pointFT, pointFT); - expect(result).toBeFalsy(); - }); - }); - -});