Skip to content

Commit

Permalink
Fix geosolutions-it#9685 measurements issues and added some enhanceme…
Browse files Browse the repository at this point in the history
…nts to it
  • Loading branch information
MV88 committed Dec 12, 2023
1 parent 468775b commit a014569
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 18 deletions.
36 changes: 25 additions & 11 deletions web/client/epics/geoProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ import {
import {
getGeom,
createFC,
getCounter
getCounter,
createFeatureId,
transformLineToArc
} from "../utils/GeoProcessingUtils";
import {buildIdentifyRequest} from "../utils/MapInfoUtils";
import {logError} from "../utils/DebugUtils";
Expand Down Expand Up @@ -373,7 +375,13 @@ export const getFeatureDataGPTEpic = (action$, store) => action$
});
})
.switchMap(({features}) => {
const ft = find(features, f => f.id === featureId);
const featuresNormalized = features.map((ft, i) => {
return {
...ft,
id: createFeatureId(ft, i)
};
});
const ft = find(featuresNormalized, f => f.id === featureId);
const zoomTo = showHighlightLayers ? [zoomToExtent(getGeoJSONExtent(ft.geometry), "EPSG:4326")] : [];
return Rx.Observable.from([
setSourceFeature(ft),
Expand All @@ -385,7 +393,7 @@ export const getFeatureDataGPTEpic = (action$, store) => action$
type: "vector",
name: "highlight-gpt-features",
visibility: showHighlightLayers,
features: features.filter(f => f.id === featureId).map(applyMapInfoStyle(highlightStyle))
features: featuresNormalized.filter(f => f.id === featureId).map(applyMapInfoStyle(highlightStyle)).map(transformLineToArc)
}),
...zoomTo
]);
Expand Down Expand Up @@ -428,7 +436,13 @@ export const getIntersectionFeatureDataGPTEpic = (action$, store) => action$
});
})
.switchMap(({features}) => {
const ft = find(features, f => f.id === featureId);
const featuresNormalized = features.map((ft, i) => {
return {
...ft,
id: createFeatureId(ft, i)
};
});
const ft = find(featuresNormalized, f => f.id === featureId);
const zoomTo = showHighlightLayers ? [zoomToExtent(getGeoJSONExtent(ft.geometry), "EPSG:4326")] : [];
return Rx.Observable.from([
setIntersectionFeature(ft),
Expand All @@ -440,7 +454,7 @@ export const getIntersectionFeatureDataGPTEpic = (action$, store) => action$
type: "vector",
name: "highlight-gpt-intersection-features",
visibility: showHighlightLayers,
features: features.filter(f => f.id === featureId).map(applyMapInfoStyle(highlightStyle))
features: featuresNormalized.filter(f => f.id === featureId).map(applyMapInfoStyle(highlightStyle)).map(transformLineToArc)
}),
...zoomTo
]);
Expand Down Expand Up @@ -560,7 +574,7 @@ export const runBufferProcessGPTEpic = (action$, store) => action$
...f.properties,
geomType: getGeom(f.geometry.type)
}
})),
})).map(transformLineToArc),
style: {
format: "geostyler",
body: {
Expand Down Expand Up @@ -589,12 +603,12 @@ export const runBufferProcessGPTEpic = (action$, store) => action$
}));
})
);
const feature = sourceFeatureSelector(state);
const feature = transformLineToArc(sourceFeatureSelector(state));
if (isEmpty(feature)) {
// then run the collect geometries which and then run the buffer
const executeCollectProcess$ = executeProcess(
layerUrl,
collectGeometriesXML({ name: layer.name, featureCollection: (layer.type === "vector") ? createFC(layer.features) : null }),
collectGeometriesXML({ name: layer.name, featureCollection: (layer.type === "vector") ? createFC(layer.features.map(transformLineToArc)) : null }),
executeOptions,
{
headers: {'Content-Type': 'application/xml', 'Accept': `application/xml, application/json`}
Expand Down Expand Up @@ -672,9 +686,9 @@ export const runIntersectProcessGPTEpic = (action$, store) => action$
const layer = getLayerFromIdSelector(state, layerId);
const layers = wfsBackedLayersSelector(state);
const layerUrl = wpsUrlSelector(state) || head(castArray(layer.url));
const sourceFeature = sourceFeatureSelector(state);
const sourceFeature = transformLineToArc(sourceFeatureSelector(state));
const executeOptions = {};
const intersectionFeature = intersectionFeatureSelector(state);
const intersectionFeature = transformLineToArc(intersectionFeatureSelector(state));
const counter = getCounter(layers, GPT_INTERSECTION_GROUP_ID);
let sourceFC$;
let intersectionFC$;
Expand All @@ -699,7 +713,7 @@ export const runIntersectProcessGPTEpic = (action$, store) => action$
if (isEmpty(intersectionFeature)) {
intersectionFC$ = executeProcess(
intersectionLayerUrl,
collectGeometriesXML({ name: intersectionLayer.name, featureCollection: (intersectionLayer.type === "vector") ? createFC(intersectionLayer.features) : null }),
collectGeometriesXML({ name: intersectionLayer.name, featureCollection: (intersectionLayer.type === "vector") ? createFC(intersectionLayer.features.map(transformLineToArc)) : null }),
executeOptions,
{
headers: {'Content-Type': 'application/xml', 'Accept': `application/xml, application/json`}
Expand Down
2 changes: 1 addition & 1 deletion web/client/epics/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const toggleWidgetConnectFlow = (action$, {getState = () => {}} = {}) =>
if (widget.widgetType === 'map') {
deps = deps.filter(d => (WIDGETS_MAPS_REGEX.exec(d) || [])[2] === widget.selectedMapId);
}
return configureDependency(active, deps[0], options, widget.dependeciesMap).concat(Rx.Observable.of(toggleDependencySelector(false, {})));
return configureDependency(active, deps[0], options, widget.dependenciesMap).concat(Rx.Observable.of(toggleDependencySelector(false, {})));
}).takeUntil(
action$.ofType(LOCATION_CHANGE)
.merge(action$.filter(({ type, key } = {}) => type === EDITOR_SETTING_CHANGE && key === DEPENDENCY_SELECTOR_KEY))
Expand Down
3 changes: 2 additions & 1 deletion web/client/plugins/GeoProcessing/IntersectionLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
selectedLayerTypeSelector,
wfsBackedLayersSelector
} from '../../selectors/geoProcessing';
import { createFeatureId } from '../../utils/GeoProcessingUtils';

const Addon = tooltip(InputGroup.Addon);
const Intersection = ({
Expand Down Expand Up @@ -123,7 +124,7 @@ const Intersection = ({
value={intersectionFeatureId}
noResultsText={<Message msgId="GeoProcessing.noMatchedFeature" />}
onChange={handleOnChangeIntersectionFeatureId}
options={intersectionFeatures.map((f, i) => ({value: f.id ?? `id: ${f.id} Feature #${i}`, label: `id: ${f.id} Feature #${i}` }))}
options={intersectionFeatures.map((f, i) => ({value: createFeatureId(f, i), label: f?.properties?.measureType ? `${f?.properties?.measureType} #${i}` : createFeatureId(f, i) }))}
onOpen={() => {
if (selectedLayerType !== "intersection" && intersectionFeatures.length === 0 ) {
onGetFeatures(intersectionLayerId, "intersection", 0);
Expand Down
4 changes: 3 additions & 1 deletion web/client/plugins/GeoProcessing/SourceLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import {
wfsBackedLayersSelector
} from '../../selectors/geoProcessing';

import { createFeatureId } from '../../utils/GeoProcessingUtils';

const Addon = tooltip(InputGroup.Addon);

const Source = ({
Expand Down Expand Up @@ -121,7 +123,7 @@ const Source = ({
clearable
noResultsText={<Message msgId="GeoProcessing.noMatchedFeature" />}
onChange={handleOnChangeSourceFeatureId}
options={sourceFeatures.map((f, i) => ({value: f.id ?? `id: ${f.id} Feature #${i}`, label: `id: ${f.id} Feature #${i}` }))}
options={sourceFeatures.map((f, i) => ({value: createFeatureId(f, i), label: f?.properties?.measureType ? `${f?.properties?.measureType} #${i}` : createFeatureId(f, i) }))}
value={sourceFeatureId}

onOpen={() => {
Expand Down
6 changes: 4 additions & 2 deletions web/client/reducers/__tests__/geoProcessing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ describe('Test Geo Processing Tools reducer', () => {
geometry: {
type: "Feature",
coordinates: [0, 0]
}
},
id: 'Feature #0'
}]);
});
it('SET_FEATURES add extra from pagination', () => {
Expand Down Expand Up @@ -187,7 +188,8 @@ describe('Test Geo Processing Tools reducer', () => {
geometry: {
type: "Feature",
coordinates: [0, 0]
}
},
id: 'Feature #1'
}]);
});
it('SET_FEATURES error', () => {
Expand Down
7 changes: 5 additions & 2 deletions web/client/reducers/geoProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/

import { createFeatureId } from '../utils/GeoProcessingUtils';

import find from "lodash/find";
import {
GPT_TOOL_BUFFER,
Expand Down Expand Up @@ -181,7 +183,8 @@ function geoProcessing( state = {
...state,
[action.source]: {
...state[action.source],
features: (state[action.source].features || []).concat(action.data.features || []),
features: (state[action.source].features || []).concat(action.data.features || []).filter(f => !f?.properties?.measureId).map((ft, i) => ({...ft,
id: createFeatureId(ft, i)})),
totalCount: action.data.totalFeatures,
currentPage: action.nextPage
},
Expand Down Expand Up @@ -287,7 +290,7 @@ function geoProcessing( state = {
source: {
...state.source,
feature: action.feature,
features: find(state.source.features, ft => ft.id === action.feature.id) ? state.source.features : [action.feature]
features: find(state.source.features, ft => ft?.id === action.feature?.id) ? state.source.features : [action.feature]
}
};
}
Expand Down
30 changes: 30 additions & 0 deletions web/client/utils/GeoProcessingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/
import last from 'lodash/last';
import sortBy from 'lodash/sortBy';
import {
transformLineToArcs
} from './CoordinatesUtils';

export const getGeom = (geomType) => {
switch (geomType) {
Expand Down Expand Up @@ -42,3 +45,30 @@ export const getCounter = (layers, groupName) => {
const counter = allLayers.length ? Number(last(allLayers).name.match(/\d/)[0]) + 1 : 0;
return counter;
};

/**
* it creates an id of a feature if not existing
* @param {object} feature list of layers to check
* @param {string} index the index of the feature
* @return {string} a predictable id
*/
export const createFeatureId = (feature, index) => {
return feature.id || `Feature #${index}`;
};
/**
* it creates an arc line into a multiple segments, only for LineString ft
* @param {object} feature list of layers to check
* @return {object} the transformed feature if geodesic
*/
export const transformLineToArc = (feature) => {
if (feature?.properties?.geodesic) {
return {
...feature,
geometry: {
...feature.geometry,
coordinates: transformLineToArcs(feature.geometry.coordinates)
}
};
}
return feature;
};

0 comments on commit a014569

Please sign in to comment.