@@ -6,8 +6,7 @@ import archiver from 'archiver'
66import moment from 'moment'
77import stream from 'stream'
88import path from 'path'
9- import turfCentroid from '@turf/centroid'
10- import { AllGeoJSON } from '@turf/helpers'
9+ import centroid from '@turf/centroid'
1110import { Exporter } from './exporter'
1211import { attachmentBaseDirectory as attachmentBase } from '../environment/env'
1312import User , { UserDocument } from '../models/user'
@@ -17,7 +16,7 @@ import { FormFieldType } from '../entities/events/entities.events.forms'
1716const mgrs = require ( 'mgrs' )
1817
1918const 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