Skip to content

Commit

Permalink
Fix KML Upload Visibility Issue (#3759)
Browse files Browse the repository at this point in the history
* add and accept other geometry types

* move geo type to sharedAPI constants, remove unused activity type from constants
  • Loading branch information
meghna0593 authored Dec 18, 2024
1 parent d5ad255 commit 92966d6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
12 changes: 0 additions & 12 deletions api/src/constants/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ export const ALL_ROLES = [
Role.PRIMARY_BIOCONTROL_USER
];

/**
* Supported activity types.
*
* @export
* @enum {number}
*/
export enum ActivityType {
OBSERVATION = 'Observation',
MONITOR = 'Monitor',
TREATMENT = 'Treatment'
}

/**
* Some of the S3 ACL roles supported by default.
*
Expand Down
1 change: 1 addition & 0 deletions api/src/paths/admin-defined-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ function uploadShape(): RequestHandler {
const buffer = Buffer.from(data['data'], 'base64');
const KML = KMZToKML(buffer);
const dirtyGeoJSON = GeoJSONFromKML(KML);

geoJSON = sanitizeGeoJSON(dirtyGeoJSON);

break;
Expand Down
23 changes: 9 additions & 14 deletions api/src/utils/kml-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as GeoJSON from '@mapbox/togeojson';
import AdmZip from 'adm-zip';
import { FeatureCollection } from 'geojson';
import { getLogger } from 'utils/logger';
import { VALID_GEOMETRY_TYPES } from 'sharedAPI';

function KMZToKML(data: Buffer): Buffer {
const log = getLogger('KML');
Expand Down Expand Up @@ -59,20 +60,14 @@ function sanitizeGeoJSON(data: FeatureCollection): FeatureCollection {
throw new Error(`Invalid GeoJSON Type: ${data.type}`);
}

// filter out non-polygon features (V1)
const newFeatures = data.features.map((feature) => {
if (
feature.geometry.type === 'Polygon' ||
feature.geometry.type === 'LineString' ||
feature.geometry.type === 'Point'
) {
return {
type: feature.type,
geometry: feature.geometry,
properties: {}
};
}
});
// Exclude features with geometry types that are not supported
const newFeatures = data.features
.filter((feature) => VALID_GEOMETRY_TYPES.includes(feature.geometry.type))
.map((feature) => ({
type: feature.type,
geometry: feature.geometry,
properties: {}
}));

const filteredData: FeatureCollection = { type: 'FeatureCollection', features: newFeatures };

Expand Down
10 changes: 10 additions & 0 deletions sharedAPI/src/validation/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ export const FORM_SUBTYPES_WITH_AREA_LIMITS = [
'Activity_Transect_BiocontrolEfficacy',
'Activity_Biocontrol_Collection'
];

export const VALID_GEOMETRY_TYPES = [
'GeometryCollection',
'MultiPolygon',
'MultiLineString',
'MultiPoint',
'Polygon',
'LineString',
'Point'
];

0 comments on commit 92966d6

Please sign in to comment.