Skip to content

Commit

Permalink
normalize uploaded area geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
j8seangel committed Sep 2, 2024
1 parent 50906db commit a203c5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion apps/fishing-map/features/areas/areas.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ export const fetchAreaDetailThunk = createAsyncThunk(
}
const dataset = selectDatasetById(datasetId)(getState() as RootState)
const area = await fetchAreaDetail({ dataset, areaId, areaName, signal, simplify })
debugger
return area
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Feature, FeatureCollection, GeoJsonProperties, Point, Polygon } from 'geojson'
import {
Feature,
FeatureCollection,
GeoJsonProperties,
GeometryCollection,
Point,
Polygon,
} from 'geojson'
import { flatten } from '@turf/flatten'
import union from '@turf/union'
import {
Dataset,
DatasetCategory,
Expand All @@ -23,6 +32,7 @@ import { isPrivateDataset } from 'features/datasets/datasets.utils'
import { DatasetMetadata } from 'features/datasets/upload/NewDataset'
import { getUTCDateTime } from 'utils/dates'
import { FileType } from 'utils/files'
import { AreaGeometry } from 'features/areas/areas.slice'

type ExtractMetadataProps = { name: string; sourceFormat?: FileType; data: any }

Expand Down Expand Up @@ -184,6 +194,10 @@ export const parseGeoJsonProperties = <T extends Polygon | Point>(
return {
...feature,
properties,
geometry:
(feature.geometry as unknown as GeometryCollection).type === 'GeometryCollection'
? (union(flatten(feature.geometry))?.geometry as AreaGeometry)
: (feature.geometry as AreaGeometry),
}
}) as Feature<T, GeoJsonProperties>[],
}
Expand Down

0 comments on commit a203c5e

Please sign in to comment.