Skip to content

Commit b1c929b

Browse files
committed
fix tests and variable names
1 parent b05ef8d commit b1c929b

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

service/src/export/csv.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import async from 'async'
44
import archiver from 'archiver'
55
import path from 'path'
6-
import { Polygon } from '@turf/helpers'
76
import { Exporter } from './exporter'
8-
import centroid from '@turf/centroid'
7+
import { centroid as turfCenteroid } from '@turf/centroid'
98
import * as User from '../models/user'
109
import * as Device from '../models/device'
1110
import * as json2csv from 'json2csv'
@@ -161,16 +160,16 @@ export class Csv extends Exporter {
161160
flat.device = cache.device.uid;
162161
}
163162

164-
const cd = centroid(observation.geometry as Polygon);
165-
flat.mgrs = mgrs.forward(cd.geometry.coordinates);
163+
const centroid = turfCenteroid(observation);
164+
flat.mgrs = mgrs.forward(centroid.geometry.coordinates);
166165

167166
flat.shapeType = observation.geometry.type;
168167
if (observation.geometry.type === 'Point') {
169168
flat.longitude = observation.geometry.coordinates[0];
170169
flat.latitude = observation.geometry.coordinates[1];
171170
} else {
172-
flat.longitude = cd.geometry.coordinates[0];
173-
flat.latitude = cd.geometry.coordinates[1];
171+
flat.longitude = centroid.geometry.coordinates[0];
172+
flat.latitude = centroid.geometry.coordinates[1];
174173
}
175174
flat.wkt = wkx.Geometry.parseGeoJSON(observation.geometry).toWkt();
176175
flat.excelTimestamp = "=DATEVALUE(MID(INDIRECT(ADDRESS(ROW(),COLUMN()-1)),1,10)) + TIMEVALUE(MID(INDIRECT(ADDRESS(ROW(),COLUMN()-1)),12,8))";

service/src/export/geojson.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import archiver from 'archiver'
66
import moment from 'moment'
77
import stream from 'stream'
88
import path from 'path'
9-
import centroid from '@turf/centroid'
9+
import { centroid as turfCentroid } from '@turf/centroid'
1010
import { Exporter } from './exporter'
1111
import { attachmentBaseDirectory as attachmentBase } from '../environment/env'
1212
import User, { UserDocument } from '../models/user'
@@ -63,12 +63,12 @@ export class GeoJson extends Exporter {
6363
}
6464

6565
mapObservationProperties(observation: ObservationDocument, archive: archiver.Archiver): void {
66-
const cd = centroid(observation);
66+
const centroid = turfCentroid(observation);
6767
const exportProperties = {
6868
...observation.properties,
6969
id: observation._id,
7070
timestamp: moment(observation.properties.timestamp).toISOString(),
71-
mgrs: mgrs.forward(cd.geometry.coordinates),
71+
mgrs: mgrs.forward(centroid.geometry.coordinates),
7272
} as any
7373
delete exportProperties.forms
7474
const formEntries = observation.properties?.forms || [] as ObservationDocumentFormEntry[]
@@ -172,9 +172,9 @@ export class GeoJson extends Exporter {
172172
if (numLocations > 0) {
173173
stream.write(',');
174174
}
175-
const cd = centroid(location);
175+
const centroid = turfCentroid(location);
176176
const exportProperties = location.properties as any
177-
exportProperties.mgrs = mgrs.forward(cd.geometry.coordinates);
177+
exportProperties.mgrs = mgrs.forward(centroid.geometry.coordinates);
178178
const data = JSON.stringify(location);
179179
stream.write(data);
180180
numLocations++;

service/src/export/kmlWriter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const mgrs = require('mgrs')
44
import moment from 'moment'
55
import path from 'path'
6-
import centroid from '@turf/centroid'
6+
import { centroid as turfCentroid } from '@turf/centroid'
77
import { fragment } from 'xmlbuilder2'
88
import { UserDocument } from '../models/user'
99
import { FormDocument, FormFieldDocument, MageEventDocument } from '../models/event'
@@ -406,20 +406,20 @@ export function generateKMLClose(): string {
406406
}
407407

408408
export function generateDescription(feature: Feature, sections: any[]): { description: { $: string } } {
409-
const cd = centroid(feature);
409+
const centroid = turfCentroid(feature);
410410
const header = [{
411411
section: [
412412
{
413413
span: [{ label: 'Timestamp' }, moment(feature.properties!.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z']
414414
},
415415
{
416-
span: [{ label: 'Latitude' }, cd.geometry.coordinates[1]]
416+
span: [{ label: 'Latitude' }, centroid.geometry.coordinates[1]]
417417
},
418418
{
419-
span: [{ label: 'Longitude' }, cd.geometry.coordinates[0]]
419+
span: [{ label: 'Longitude' }, centroid.geometry.coordinates[0]]
420420
},
421421
{
422-
span: [{ label: 'MGRS' }, mgrs.forward(cd.geometry.coordinates)]
422+
span: [{ label: 'MGRS' }, mgrs.forward(centroid.geometry.coordinates)]
423423
}
424424
]
425425
}]

web-app/src/app/geometry/geometry.pipe.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class GeometryPipe implements PipeTransform {
4141
}
4242

4343
center(value: any): Point {
44+
if (!value || !value.coordinates || !Array.isArray(value.coordinates)) {
45+
return { type: 'Point', coordinates: [0, 0] }
46+
}
47+
4448
const feature: Feature = {
4549
type: 'Feature',
4650
properties: {},
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from "@angular/core";
22
import { polygon } from "@turf/helpers";
3-
import kinks from '@turf/kinks'
3+
import { kinks as turfKinks } from '@turf/kinks'
44

55
@Injectable({
66
providedIn: 'root'
@@ -11,8 +11,8 @@ export class GeometryService {
1111
return false;
1212
}
1313

14-
const ks = kinks(polygon(feature.geometry.coordinates));
14+
const kinks = turfKinks(polygon(feature.geometry.coordinates));
1515

16-
return ks.features.length !== 0;
16+
return kinks.features.length !== 0;
1717
}
1818
}

0 commit comments

Comments
 (0)