Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 62 additions & 17 deletions service/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"@ngageoint/geopackage": "4.2.6",
"@ngageoint/mongodb-migrations": "1.0.0",
"@node-saml/passport-saml": "4.0.4",
"@turf/centroid": "6.5.0",
"@turf/kinks": "6.5.0",
"@turf/centroid": "7.2.0",
"@turf/kinks": "7.2.0",
"@types/geojson": "7946.0.16",
"@types/json-schema": "7.0.15",
"@types/mime-types": "2.1.4",
Expand Down
31 changes: 15 additions & 16 deletions service/src/export/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import async from 'async'
import archiver from 'archiver'
import path from 'path'
import { AllGeoJSON } from '@turf/helpers'
import { Exporter } from './exporter'
import turfCentroid from '@turf/centroid'
import { centroid as turfCenteroid } from '@turf/centroid'
import * as User from '../models/user'
import * as Device from '../models/device'
import * as json2csv from 'json2csv'
const mgrs = require('mgrs')
const log = require('winston')
const wkx = require('wkx')
import { attachmentBaseDirectory as attachmentBase } from '../environment/env'
import { attachmentBaseDirectory as attachmentBase } from '../environment/env'
import stream from 'stream'
import { ObservationDocument } from '../models/observation'
import { UserDocument } from '../adapters/users/adapters.users.db.mongoose'
Expand Down Expand Up @@ -92,7 +91,7 @@ export class Csv extends Exporter {
});
},
(done): void => {
if (!this._filter.exportLocations){
if (!this._filter.exportLocations) {
return done();
}
const asyncParser = new json2csv.AsyncParser({ fields: locationFields }, { readableObjectMode: true, writableObjectMode: true });
Expand Down Expand Up @@ -161,7 +160,7 @@ export class Csv extends Exporter {
flat.device = cache.device.uid;
}

const centroid = turfCentroid(observation as AllGeoJSON);
const centroid = turfCenteroid(observation);
flat.mgrs = mgrs.forward(centroid.geometry.coordinates);

flat.shapeType = observation.geometry.type;
Expand Down Expand Up @@ -192,7 +191,7 @@ export class Csv extends Exporter {
}

if (observation.attachments) {
observation.attachments.forEach((attachment, index) => {
observation.attachments.forEach((attachment) => {
if (!attachment.relativePath) {
// exclude attachments that are pending upload and/or not saved
return
Expand Down Expand Up @@ -221,16 +220,16 @@ export class Csv extends Exporter {
stream.push(locationRecord)
numLocations++
})
.then(() => {
if (cursor) {
cursor.close
}
log.info('Successfully wrote ' + numLocations + ' locations to CSV')
log.info('done writing locations')
stream.push(null)
done()
})
.catch(err => done(err))
.then(() => {
if (cursor) {
cursor.close
}
log.info('Successfully wrote ' + numLocations + ' locations to CSV')
log.info('done writing locations')
stream.push(null)
done()
})
.catch(err => done(err))
}

async flattenLocation(location: UserLocationDocument, cache: { user: UserDocument | null, device: any }): Promise<any> {
Expand Down
49 changes: 24 additions & 25 deletions service/src/export/geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import archiver from 'archiver'
import moment from 'moment'
import stream from 'stream'
import path from 'path'
import turfCentroid from '@turf/centroid'
import { AllGeoJSON } from '@turf/helpers'
import { centroid as turfCentroid } from '@turf/centroid'
import { Exporter } from './exporter'
import { attachmentBaseDirectory as attachmentBase } from '../environment/env'
import User, { UserDocument } from '../models/user'
Expand All @@ -17,7 +16,7 @@ import { FormFieldType } from '../entities/events/entities.events.forms'
const mgrs = require('mgrs')

const logger = require('../logger')
const log = [ 'debug', 'info', 'warn', 'error', 'log' ].reduce((log: any, methodName: string): any => {
const log = ['debug', 'info', 'warn', 'error', 'log'].reduce((log: any, methodName: string): any => {
const logMethod = logger[methodName] as (...args: any[]) => any
return {
...log,
Expand Down Expand Up @@ -64,7 +63,7 @@ export class GeoJson extends Exporter {
}

mapObservationProperties(observation: ObservationDocument, archive: archiver.Archiver): void {
const centroid = turfCentroid(observation as AllGeoJSON)
const centroid = turfCentroid(observation);
const exportProperties = {
...observation.properties,
id: observation._id,
Expand All @@ -88,7 +87,7 @@ export class GeoJson extends Exporter {
return attachment.relativePath &&
attachment.fieldName === field.name &&
String(attachment.observationFormId) === String(formEntry._id)
}
}
)
const attachmentRelPaths = fieldAttachments.map(x => x.relativePath)
fieldEntryHash[field.name] = attachmentRelPaths
Expand Down Expand Up @@ -150,17 +149,17 @@ export class GeoJson extends Exporter {
stream.write(data);
numObservations++;
})
.then(() => {
if (cursor) {
cursor.close()
}
stream.write(']}');
// throw in icons
archive.directory(new api.Icon(this._event.id).getBasePath(), 'mage-export/icons', { date: new Date() });
log.info(`wrote ${numObservations} observations`);
done();
})
.catch(err => done(err));
.then(() => {
if (cursor) {
cursor.close()
}
stream.write(']}');
// throw in icons
archive.directory(new api.Icon(this._event.id).getBasePath(), 'mage-export/icons', { date: new Date() });
log.info(`wrote ${numObservations} observations`);
done();
})
.catch(err => done(err));
}

streamLocations(stream: NodeJS.WritableStream, done: (err?: any) => void): void {
Expand All @@ -180,14 +179,14 @@ export class GeoJson extends Exporter {
stream.write(data);
numLocations++;
})
.then(() => {
if (cursor) {
cursor.close();
}
stream.write(']}');
log.info(`wrote ${numLocations} locations`);
done();
})
.catch(err => done(err));
.then(() => {
if (cursor) {
cursor.close();
}
stream.write(']}');
log.info(`wrote ${numLocations} locations`);
done();
})
.catch(err => done(err));
}
}
33 changes: 16 additions & 17 deletions service/src/export/kmlWriter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const mgrs = require('mgrs')
import moment from 'moment'
import moment from 'moment'
import path from 'path'
import turfCentroid from '@turf/centroid'
import { AllGeoJSON } from '@turf/helpers'
import { fragment } from 'xmlbuilder2'
import { centroid as turfCentroid } from '@turf/centroid'
import { fragment } from 'xmlbuilder2'
import { UserDocument } from '../models/user'
import { FormDocument, FormFieldDocument, MageEventDocument } from '../models/event'
import { ObservationDocument, ObservationDocumentFormEntry } from '../models/observation'
Expand All @@ -28,10 +27,10 @@ const defaultStyle: Required<LineStyle> = {
function requiredStyle(style: BaseFormStyle): Required<BaseFormStyle> {
const dup = copyBaseFormStyle(style)
dup.fill = style.fill || defaultStyle.fill,
dup.stroke = style.stroke || defaultStyle.stroke,
dup.fillOpacity = isNumber(style.fillOpacity) ? style.fillOpacity : defaultStyle.fillOpacity,
dup.strokeOpacity = isNumber(style.strokeOpacity) ? style.strokeOpacity : defaultStyle.strokeOpacity,
dup.strokeWidth = isNumber(style.strokeWidth) ? style.strokeWidth : defaultStyle.strokeWidth
dup.stroke = style.stroke || defaultStyle.stroke,
dup.fillOpacity = isNumber(style.fillOpacity) ? style.fillOpacity : defaultStyle.fillOpacity,
dup.strokeOpacity = isNumber(style.strokeOpacity) ? style.strokeOpacity : defaultStyle.strokeOpacity,
dup.strokeWidth = isNumber(style.strokeWidth) ? style.strokeWidth : defaultStyle.strokeWidth
return dup as Required<BaseFormStyle>
}

Expand Down Expand Up @@ -264,7 +263,7 @@ export function generateObservationStyles(event: MageEventDocument, icons: any[]
const formStyles = event.forms.map(form => {
return generateFormStyles(event, form, icons.filter(icon => icon.formId === form._id));
})
return [ generateEventStyle(event, icons), ...formStyles ].join('')
return [generateEventStyle(event, icons), ...formStyles].join('')
}

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

const styles = [ String(event.id) ]
const styles = [String(event.id)]
if (firstFormEntry) {
const form = event.formFor(firstFormEntry.formId)
if (form) {
Expand Down Expand Up @@ -406,21 +405,21 @@ export function generateKMLClose(): string {
return '</kml>'
}

export function generateDescription(feature: Feature, sections: any[]): { description: { $: string }} {
const centroid = turfCentroid(feature as AllGeoJSON);
export function generateDescription(feature: Feature, sections: any[]): { description: { $: string } } {
const centroid = turfCentroid(feature);
const header = [{
section: [
{
span: [ { label: 'Timestamp' }, moment(feature.properties!.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z' ]
span: [{ label: 'Timestamp' }, moment(feature.properties!.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z']
},
{
span: [ { label: 'Latitude' }, centroid.geometry.coordinates[1] ]
span: [{ label: 'Latitude' }, centroid.geometry.coordinates[1]]
},
{
span: [ { label: 'Longitude' }, centroid.geometry.coordinates[0] ]
span: [{ label: 'Longitude' }, centroid.geometry.coordinates[0]]
},
{
span: [ { label: 'MGRS' }, mgrs.forward(centroid.geometry.coordinates) ]
span: [{ label: 'MGRS' }, mgrs.forward(centroid.geometry.coordinates)]
}
]
}]
Expand Down Expand Up @@ -458,7 +457,7 @@ export function generateDescription(feature: Feature, sections: any[]): { descri
})
} else {
properties.push({
span: [ { label: property.key }, property.value.toString() ]
span: [{ label: property.key }, property.value.toString()]
})
}
});
Expand Down
2 changes: 1 addition & 1 deletion web-app/admin/src/app/geometry/geometry.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Pipe, PipeTransform } from '@angular/core'
import * as turfCenter from '@turf/center'
import { center as turfCenter } from '@turf/center'
import { Feature, Point } from 'geojson'
import * as mgrs from 'mgrs'
import { LocalStorageService } from '../upgrade/ajs-upgraded-providers'
Expand Down
Loading