Skip to content

Commit f49fd9c

Browse files
authored
Merge pull request #330 from ngageoint/mage-1618
Update @Turf dependencies to 7.2.0
2 parents da63887 + 4e38b01 commit f49fd9c

File tree

11 files changed

+215
-99
lines changed

11 files changed

+215
-99
lines changed

service/npm-shrinkwrap.json

Lines changed: 62 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"@ngageoint/geopackage": "4.2.6",
3232
"@ngageoint/mongodb-migrations": "1.0.0",
3333
"@node-saml/passport-saml": "4.0.4",
34-
"@turf/centroid": "6.5.0",
35-
"@turf/kinks": "6.5.0",
34+
"@turf/centroid": "7.2.0",
35+
"@turf/kinks": "7.2.0",
3636
"@types/geojson": "7946.0.16",
3737
"@types/json-schema": "7.0.15",
3838
"@types/mime-types": "2.1.4",

service/src/export/csv.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
import async from 'async'
44
import archiver from 'archiver'
55
import path from 'path'
6-
import { AllGeoJSON } from '@turf/helpers'
76
import { Exporter } from './exporter'
8-
import turfCentroid 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'
1211
const mgrs = require('mgrs')
1312
const log = require('winston')
1413
const wkx = require('wkx')
15-
import { attachmentBaseDirectory as attachmentBase } from '../environment/env'
14+
import { attachmentBaseDirectory as attachmentBase } from '../environment/env'
1615
import stream from 'stream'
1716
import { ObservationDocument } from '../models/observation'
1817
import { UserDocument } from '../adapters/users/adapters.users.db.mongoose'
@@ -92,7 +91,7 @@ export class Csv extends Exporter {
9291
});
9392
},
9493
(done): void => {
95-
if (!this._filter.exportLocations){
94+
if (!this._filter.exportLocations) {
9695
return done();
9796
}
9897
const asyncParser = new json2csv.AsyncParser({ fields: locationFields }, { readableObjectMode: true, writableObjectMode: true });
@@ -161,7 +160,7 @@ export class Csv extends Exporter {
161160
flat.device = cache.device.uid;
162161
}
163162

164-
const centroid = turfCentroid(observation as AllGeoJSON);
163+
const centroid = turfCenteroid(observation);
165164
flat.mgrs = mgrs.forward(centroid.geometry.coordinates);
166165

167166
flat.shapeType = observation.geometry.type;
@@ -192,7 +191,7 @@ export class Csv extends Exporter {
192191
}
193192

194193
if (observation.attachments) {
195-
observation.attachments.forEach((attachment, index) => {
194+
observation.attachments.forEach((attachment) => {
196195
if (!attachment.relativePath) {
197196
// exclude attachments that are pending upload and/or not saved
198197
return
@@ -221,16 +220,16 @@ export class Csv extends Exporter {
221220
stream.push(locationRecord)
222221
numLocations++
223222
})
224-
.then(() => {
225-
if (cursor) {
226-
cursor.close
227-
}
228-
log.info('Successfully wrote ' + numLocations + ' locations to CSV')
229-
log.info('done writing locations')
230-
stream.push(null)
231-
done()
232-
})
233-
.catch(err => done(err))
223+
.then(() => {
224+
if (cursor) {
225+
cursor.close
226+
}
227+
log.info('Successfully wrote ' + numLocations + ' locations to CSV')
228+
log.info('done writing locations')
229+
stream.push(null)
230+
done()
231+
})
232+
.catch(err => done(err))
234233
}
235234

236235
async flattenLocation(location: UserLocationDocument, cache: { user: UserDocument | null, device: any }): Promise<any> {

service/src/export/geojson.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import archiver from 'archiver'
66
import moment from 'moment'
77
import stream from 'stream'
88
import path from 'path'
9-
import turfCentroid from '@turf/centroid'
10-
import { AllGeoJSON } from '@turf/helpers'
9+
import { centroid as turfCentroid } from '@turf/centroid'
1110
import { Exporter } from './exporter'
1211
import { attachmentBaseDirectory as attachmentBase } from '../environment/env'
1312
import User, { UserDocument } from '../models/user'
@@ -17,7 +16,7 @@ import { FormFieldType } from '../entities/events/entities.events.forms'
1716
const mgrs = require('mgrs')
1817

1918
const logger = require('../logger')
20-
const log = [ 'debug', 'info', 'warn', 'error', 'log' ].reduce((log: any, methodName: string): any => {
19+
const log = ['debug', 'info', 'warn', 'error', 'log'].reduce((log: any, methodName: string): any => {
2120
const logMethod = logger[methodName] as (...args: any[]) => any
2221
return {
2322
...log,
@@ -64,7 +63,7 @@ export class GeoJson extends Exporter {
6463
}
6564

6665
mapObservationProperties(observation: ObservationDocument, archive: archiver.Archiver): void {
67-
const centroid = turfCentroid(observation as AllGeoJSON)
66+
const centroid = turfCentroid(observation);
6867
const exportProperties = {
6968
...observation.properties,
7069
id: observation._id,
@@ -88,7 +87,7 @@ export class GeoJson extends Exporter {
8887
return attachment.relativePath &&
8988
attachment.fieldName === field.name &&
9089
String(attachment.observationFormId) === String(formEntry._id)
91-
}
90+
}
9291
)
9392
const attachmentRelPaths = fieldAttachments.map(x => x.relativePath)
9493
fieldEntryHash[field.name] = attachmentRelPaths
@@ -150,17 +149,17 @@ export class GeoJson extends Exporter {
150149
stream.write(data);
151150
numObservations++;
152151
})
153-
.then(() => {
154-
if (cursor) {
155-
cursor.close()
156-
}
157-
stream.write(']}');
158-
// throw in icons
159-
archive.directory(new api.Icon(this._event.id).getBasePath(), 'mage-export/icons', { date: new Date() });
160-
log.info(`wrote ${numObservations} observations`);
161-
done();
162-
})
163-
.catch(err => done(err));
152+
.then(() => {
153+
if (cursor) {
154+
cursor.close()
155+
}
156+
stream.write(']}');
157+
// throw in icons
158+
archive.directory(new api.Icon(this._event.id).getBasePath(), 'mage-export/icons', { date: new Date() });
159+
log.info(`wrote ${numObservations} observations`);
160+
done();
161+
})
162+
.catch(err => done(err));
164163
}
165164

166165
streamLocations(stream: NodeJS.WritableStream, done: (err?: any) => void): void {
@@ -180,14 +179,14 @@ export class GeoJson extends Exporter {
180179
stream.write(data);
181180
numLocations++;
182181
})
183-
.then(() => {
184-
if (cursor) {
185-
cursor.close();
186-
}
187-
stream.write(']}');
188-
log.info(`wrote ${numLocations} locations`);
189-
done();
190-
})
191-
.catch(err => done(err));
182+
.then(() => {
183+
if (cursor) {
184+
cursor.close();
185+
}
186+
stream.write(']}');
187+
log.info(`wrote ${numLocations} locations`);
188+
done();
189+
})
190+
.catch(err => done(err));
192191
}
193192
}

service/src/export/kmlWriter.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict';
22

33
const mgrs = require('mgrs')
4-
import moment from 'moment'
4+
import moment from 'moment'
55
import path from 'path'
6-
import turfCentroid from '@turf/centroid'
7-
import { AllGeoJSON } from '@turf/helpers'
8-
import { fragment } from 'xmlbuilder2'
6+
import { centroid as turfCentroid } from '@turf/centroid'
7+
import { fragment } from 'xmlbuilder2'
98
import { UserDocument } from '../models/user'
109
import { FormDocument, FormFieldDocument, MageEventDocument } from '../models/event'
1110
import { ObservationDocument, ObservationDocumentFormEntry } from '../models/observation'
@@ -28,10 +27,10 @@ const defaultStyle: Required<LineStyle> = {
2827
function requiredStyle(style: BaseFormStyle): Required<BaseFormStyle> {
2928
const dup = copyBaseFormStyle(style)
3029
dup.fill = style.fill || defaultStyle.fill,
31-
dup.stroke = style.stroke || defaultStyle.stroke,
32-
dup.fillOpacity = isNumber(style.fillOpacity) ? style.fillOpacity : defaultStyle.fillOpacity,
33-
dup.strokeOpacity = isNumber(style.strokeOpacity) ? style.strokeOpacity : defaultStyle.strokeOpacity,
34-
dup.strokeWidth = isNumber(style.strokeWidth) ? style.strokeWidth : defaultStyle.strokeWidth
30+
dup.stroke = style.stroke || defaultStyle.stroke,
31+
dup.fillOpacity = isNumber(style.fillOpacity) ? style.fillOpacity : defaultStyle.fillOpacity,
32+
dup.strokeOpacity = isNumber(style.strokeOpacity) ? style.strokeOpacity : defaultStyle.strokeOpacity,
33+
dup.strokeWidth = isNumber(style.strokeWidth) ? style.strokeWidth : defaultStyle.strokeWidth
3534
return dup as Required<BaseFormStyle>
3635
}
3736

@@ -264,7 +263,7 @@ export function generateObservationStyles(event: MageEventDocument, icons: any[]
264263
const formStyles = event.forms.map(form => {
265264
return generateFormStyles(event, form, icons.filter(icon => icon.formId === form._id));
266265
})
267-
return [ generateEventStyle(event, icons), ...formStyles ].join('')
266+
return [generateEventStyle(event, icons), ...formStyles].join('')
268267
}
269268

270269
export function generateObservationPlacemark(observation: ObservationDocument, event: MageEvent): string {
@@ -336,7 +335,7 @@ export function generateObservationPlacemark(observation: ObservationDocument, e
336335
sections.push({ title: 'GPS', properties: gpsProperties })
337336
}
338337

339-
const styles = [ String(event.id) ]
338+
const styles = [String(event.id)]
340339
if (firstFormEntry) {
341340
const form = event.formFor(firstFormEntry.formId)
342341
if (form) {
@@ -406,21 +405,21 @@ export function generateKMLClose(): string {
406405
return '</kml>'
407406
}
408407

409-
export function generateDescription(feature: Feature, sections: any[]): { description: { $: string }} {
410-
const centroid = turfCentroid(feature as AllGeoJSON);
408+
export function generateDescription(feature: Feature, sections: any[]): { description: { $: string } } {
409+
const centroid = turfCentroid(feature);
411410
const header = [{
412411
section: [
413412
{
414-
span: [ { label: 'Timestamp' }, moment(feature.properties!.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z' ]
413+
span: [{ label: 'Timestamp' }, moment(feature.properties!.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z']
415414
},
416415
{
417-
span: [ { label: 'Latitude' }, centroid.geometry.coordinates[1] ]
416+
span: [{ label: 'Latitude' }, centroid.geometry.coordinates[1]]
418417
},
419418
{
420-
span: [ { label: 'Longitude' }, centroid.geometry.coordinates[0] ]
419+
span: [{ label: 'Longitude' }, centroid.geometry.coordinates[0]]
421420
},
422421
{
423-
span: [ { label: 'MGRS' }, mgrs.forward(centroid.geometry.coordinates) ]
422+
span: [{ label: 'MGRS' }, mgrs.forward(centroid.geometry.coordinates)]
424423
}
425424
]
426425
}]
@@ -458,7 +457,7 @@ export function generateDescription(feature: Feature, sections: any[]): { descri
458457
})
459458
} else {
460459
properties.push({
461-
span: [ { label: property.key }, property.value.toString() ]
460+
span: [{ label: property.key }, property.value.toString()]
462461
})
463462
}
464463
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Inject, Pipe, PipeTransform } from '@angular/core'
2-
import * as turfCenter from '@turf/center'
2+
import { center as turfCenter } from '@turf/center'
33
import { Feature, Point } from 'geojson'
44
import * as mgrs from 'mgrs'
55
import { LocalStorageService } from '../upgrade/ajs-upgraded-providers'

0 commit comments

Comments
 (0)