Skip to content

Commit

Permalink
Fixed crash when trajectory contains only one point (equinor#788)
Browse files Browse the repository at this point in the history
Closes equinor#771

Co-authored-by: Shadab Khan <[email protected]>
  • Loading branch information
shadab-skhan and Shadab Khan authored Feb 1, 2022
1 parent 7428afa commit 0c9dd82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions react/src/lib/components/DeckGLMap/components/InfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function Row(props: { layer_data: InfoCardDataType }) {
const [open, setOpen] = React.useState(true);
const classes = useStyles();

if (layer_data.properties?.length == 0) return null;
return (
<React.Fragment>
<TableRow className={classes.table_row}>
Expand Down
27 changes: 18 additions & 9 deletions react/src/lib/components/DeckGLMap/layers/wells/wellsLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,16 @@ function getWellObjectByName(
);
}

function getWellCoordinates(well_object: Feature): Position[] {
function getWellCoordinates(well_object?: Feature): Position[] {
return (
(well_object.geometry as GeometryCollection)?.geometries.find(
(well_object?.geometry as GeometryCollection)?.geometries.find(
(item) => item.type == "LineString"
) as LineString
)?.coordinates;
}

function getWellMds(well_object: Feature): number[] {
return well_object.properties?.["md"][0];
function getWellMds(well_object?: Feature): number[] {
return well_object?.properties?.["md"][0];
}

function getNeighboringMdIndices(mds: number[], md: number): number[] {
Expand All @@ -341,11 +341,16 @@ function getLogPath(
logrun_name: string
): Position[] {
const well_object = getWellObjectByName(wells_data, d.header.well);
if (well_object == undefined) return [];

const well_xyz = getWellCoordinates(well_object);
const well_mds = getWellMds(well_object);
if (well_xyz.length == 0 || well_mds.length == 0) return [];

if (
well_xyz == undefined ||
well_mds == undefined ||
well_xyz.length == 0 ||
well_mds.length == 0
)
return [];

const log_xyz: Position[] = [];
const log_mds = getLogMd(d, logrun_name);
Expand Down Expand Up @@ -473,6 +478,10 @@ function interpolateDataOnTrajectory(
data: number[],
trajectory: Position[]
): number {
// if number of data points in less than 1 or
// length of data and trajectory are different we cannot interpolate.
if (data.length <= 1 || data.length != trajectory.length) return -1;

// Identify closest well path leg to coord.
const segment_index = getSegmentIndex(coord, trajectory);

Expand Down Expand Up @@ -508,9 +517,9 @@ function getMd(coord: Position, feature: Feature): number | null {
if (!feature.properties || !feature.geometry) return null;

const measured_depths = feature.properties["md"][0] as number[];
const trajectory3D = getWellCoordinates(feature);

const gc = feature.geometry as GeometryCollection;
const trajectory3D = (gc.geometries[1] as LineString).coordinates;
if (trajectory3D == undefined) return null;

let trajectory;
// In 2D view coord is of type Position2D and in 3D view it's Position3D,
Expand Down

0 comments on commit 0c9dd82

Please sign in to comment.