Skip to content

Commit b05ef8d

Browse files
committed
update turf to 7.2.0
1 parent 7120d4e commit b05ef8d

File tree

10 files changed

+199
-118
lines changed

10 files changed

+199
-118
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: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import async from 'async'
44
import archiver from 'archiver'
55
import path from 'path'
6-
import { AllGeoJSON } from '@turf/helpers'
6+
import { Polygon } from '@turf/helpers'
77
import { Exporter } from './exporter'
8-
import turfCentroid from '@turf/centroid'
8+
import centroid from '@turf/centroid'
99
import * as User from '../models/user'
1010
import * as Device from '../models/device'
1111
import * as json2csv from 'json2csv'
1212
const mgrs = require('mgrs')
1313
const log = require('winston')
1414
const wkx = require('wkx')
15-
import { attachmentBaseDirectory as attachmentBase } from '../environment/env'
15+
import { attachmentBaseDirectory as attachmentBase } from '../environment/env'
1616
import stream from 'stream'
1717
import { ObservationDocument } from '../models/observation'
1818
import { UserDocument } from '../adapters/users/adapters.users.db.mongoose'
@@ -92,7 +92,7 @@ export class Csv extends Exporter {
9292
});
9393
},
9494
(done): void => {
95-
if (!this._filter.exportLocations){
95+
if (!this._filter.exportLocations) {
9696
return done();
9797
}
9898
const asyncParser = new json2csv.AsyncParser({ fields: locationFields }, { readableObjectMode: true, writableObjectMode: true });
@@ -161,16 +161,16 @@ export class Csv extends Exporter {
161161
flat.device = cache.device.uid;
162162
}
163163

164-
const centroid = turfCentroid(observation as AllGeoJSON);
165-
flat.mgrs = mgrs.forward(centroid.geometry.coordinates);
164+
const cd = centroid(observation.geometry as Polygon);
165+
flat.mgrs = mgrs.forward(cd.geometry.coordinates);
166166

167167
flat.shapeType = observation.geometry.type;
168168
if (observation.geometry.type === 'Point') {
169169
flat.longitude = observation.geometry.coordinates[0];
170170
flat.latitude = observation.geometry.coordinates[1];
171171
} else {
172-
flat.longitude = centroid.geometry.coordinates[0];
173-
flat.latitude = centroid.geometry.coordinates[1];
172+
flat.longitude = cd.geometry.coordinates[0];
173+
flat.latitude = cd.geometry.coordinates[1];
174174
}
175175
flat.wkt = wkx.Geometry.parseGeoJSON(observation.geometry).toWkt();
176176
flat.excelTimestamp = "=DATEVALUE(MID(INDIRECT(ADDRESS(ROW(),COLUMN()-1)),1,10)) + TIMEVALUE(MID(INDIRECT(ADDRESS(ROW(),COLUMN()-1)),12,8))";
@@ -192,7 +192,7 @@ export class Csv extends Exporter {
192192
}
193193

194194
if (observation.attachments) {
195-
observation.attachments.forEach((attachment, index) => {
195+
observation.attachments.forEach((attachment) => {
196196
if (!attachment.relativePath) {
197197
// exclude attachments that are pending upload and/or not saved
198198
return
@@ -221,16 +221,16 @@ export class Csv extends Exporter {
221221
stream.push(locationRecord)
222222
numLocations++
223223
})
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))
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))
234234
}
235235

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

service/src/export/geojson.ts

Lines changed: 27 additions & 28 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 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,12 +63,12 @@ export class GeoJson extends Exporter {
6463
}
6564

6665
mapObservationProperties(observation: ObservationDocument, archive: archiver.Archiver): void {
67-
const centroid = turfCentroid(observation as AllGeoJSON)
66+
const cd = centroid(observation);
6867
const exportProperties = {
6968
...observation.properties,
7069
id: observation._id,
7170
timestamp: moment(observation.properties.timestamp).toISOString(),
72-
mgrs: mgrs.forward(centroid.geometry.coordinates),
71+
mgrs: mgrs.forward(cd.geometry.coordinates),
7372
} as any
7473
delete exportProperties.forms
7574
const formEntries = observation.properties?.forms || [] as ObservationDocumentFormEntry[]
@@ -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 {
@@ -173,21 +172,21 @@ export class GeoJson extends Exporter {
173172
if (numLocations > 0) {
174173
stream.write(',');
175174
}
176-
const centroid = turfCentroid(location);
175+
const cd = centroid(location);
177176
const exportProperties = location.properties as any
178-
exportProperties.mgrs = mgrs.forward(centroid.geometry.coordinates);
177+
exportProperties.mgrs = mgrs.forward(cd.geometry.coordinates);
179178
const data = JSON.stringify(location);
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
}

0 commit comments

Comments
 (0)