-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(export): added possibility of exporting merged CSV files #949
Changes from 7 commits
e946efc
5f3962d
97f8672
262db67
c2c458e
ea1796d
c8e8790
39bd4d4
e9da836
1f9b774
b3bced3
70cfc66
bd4cc63
fa304a2
29b04b0
440d694
ac7ae0c
1cd1144
2166573
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -459,11 +459,19 @@ export class ImportExportComponent implements OnDestroy, OnInit { | |
this.handlePopup(); | ||
} | ||
|
||
data.layers.forEach((layer) => { | ||
let geomTypesCSV: { geometryType: string, features: any[] }[] = []; | ||
let featuresCSV: any[] = []; | ||
let filename: string = ""; | ||
|
||
for (const [layerIndex, layer] of data.layers.entries()) { | ||
const lay = this.map.getLayerById(layer); | ||
let filename = lay.title; | ||
if (data.name !== undefined) { | ||
filename = data.name; | ||
if (!(data.format === ExportFormat.CSVsemicolon || data.format === ExportFormat.CSVcomma) || ! data.combineLayers) { | ||
filename = lay.title; | ||
if (data.name) { | ||
filename = data.name; | ||
} | ||
} else { | ||
filename = "combinedLayers"; | ||
} | ||
const dSOptions: DataSourceOptions = lay.dataSource.options; | ||
if (data.format === ExportFormat.URL && dSOptions.download && (dSOptions.download.url || dSOptions.download.dynamicUrl)) { | ||
|
@@ -530,6 +538,8 @@ export class ImportExportComponent implements OnDestroy, OnInit { | |
|
||
geomTypes.forEach(geomType => { | ||
geomType.features.forEach(feature => { | ||
const re = new RegExp('^\\D+'); | ||
feature.set('couche', lay.title.match(re)[0].trim()); | ||
const radius: number = feature.get('rad'); | ||
|
||
if (radius) { | ||
|
@@ -552,36 +562,88 @@ export class ImportExportComponent implements OnDestroy, OnInit { | |
} | ||
} | ||
|
||
if ((data.format === ExportFormat.CSVsemicolon || data.format === ExportFormat.CSVcomma) && data.combineLayers) { | ||
geomTypes.forEach(geomType => geomTypesCSV.push(geomType)); | ||
|
||
if (layerIndex !== data.layers.length - 1) { | ||
continue; | ||
} else { | ||
let previousFeature = undefined; | ||
geomTypesCSV.forEach(geomType => { | ||
geomType.features.forEach(currentFeature => { | ||
if (data.separator) { | ||
if (previousFeature) { | ||
if (currentFeature.get('type') !== previousFeature.get('type')) { | ||
const emptyRowFeature = previousFeature.clone(); | ||
const previousFeatureKeys: Array<string> = previousFeature.getKeys(); | ||
previousFeatureKeys.forEach(key => { | ||
emptyRowFeature.unset(key, true); | ||
}); | ||
featuresCSV.push(emptyRowFeature); | ||
} | ||
} | ||
} | ||
featuresCSV.push(currentFeature); | ||
previousFeature = currentFeature; | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
if (geomTypes.length === 0) { | ||
this.loading$.next(false); | ||
const title = translate.instant('igo.geo.export.nothing.title'); | ||
const message = translate.instant('igo.geo.export.nothing.text'); | ||
this.messageService.error(message, title, { timeOut: 20000 }); | ||
|
||
} else { | ||
geomTypes.map(geomType => | ||
this.exportService.export(geomType.features, data.format, filename + geomType.geometryType, data.encoding, this.map.projection) | ||
.subscribe( | ||
() => {}, | ||
(error: Error) => this.onFileExportError(error), | ||
() => { | ||
this.onFileExportSuccess(); | ||
|
||
geomType.features.forEach(feature => { | ||
const radius: number = feature.get('rad'); | ||
|
||
if (radius) { | ||
const point = new olPoint([feature.get('longitude'), feature.get('latitude')]); | ||
point.transform('EPSG:4326', feature.get('_projection')); | ||
feature.setGeometry(point); | ||
} | ||
}); | ||
|
||
this.loading$.next(false); | ||
if (!(data.format === ExportFormat.CSVsemicolon || data.format === ExportFormat.CSVcomma) || !data.combineLayers) { | ||
geomTypes.map(geomType => | ||
this.exportService.export(geomType.features, data.format, filename + geomType.geometryType, data.encoding, this.map.projection) | ||
.subscribe( | ||
() => {}, | ||
(error: Error) => this.onFileExportError(error), | ||
() => { | ||
this.onFileExportSuccess(); | ||
|
||
geomType.features.forEach(feature => { | ||
const radius: number = feature.get('rad'); | ||
|
||
if (radius) { | ||
const point = new olPoint([feature.get('longitude'), feature.get('latitude')]); | ||
point.transform('EPSG:4326', feature.get('_projection')); | ||
feature.setGeometry(point); | ||
} | ||
}); | ||
|
||
this.loading$.next(false); | ||
} | ||
)); | ||
)); | ||
} | ||
} | ||
}); | ||
}; | ||
if ((data.format === ExportFormat.CSVsemicolon || data.format === ExportFormat.CSVcomma) && data.combineLayers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be put into else condition (line 561) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
this.exportService.export(featuresCSV, data.format, filename, data.encoding, this.map.projection) | ||
.subscribe( | ||
() => {}, | ||
(error: Error) => this.onFileExportError(error), | ||
() => { | ||
this.onFileExportSuccess(); | ||
|
||
featuresCSV.forEach(feature => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create method instead ? Could be also use for geomType at line 609 |
||
const radius: number = feature.get('rad'); | ||
|
||
if (radius) { | ||
const point = new olPoint([feature.get('longitude'), feature.get('latitude')]); | ||
point.transform('EPSG:4326', feature.get('_projection')); | ||
feature.setGeometry(point); | ||
} | ||
}); | ||
|
||
this.loading$.next(false); | ||
} | ||
); | ||
} | ||
} | ||
|
||
private buildForm() { | ||
|
@@ -595,6 +657,8 @@ export class ImportExportComponent implements OnDestroy, OnInit { | |
layers: [[], [Validators.required]], | ||
layersWithSelection: [[]], | ||
encoding: [EncodingFormat.UTF8, [Validators.required]], | ||
combineLayers: [true, [Validators.required]], | ||
separator: [false, [Validators.required]], | ||
featureInMapExtent: [false, [Validators.required]], | ||
name: ['', [Validators.required]] | ||
}); | ||
|
@@ -604,6 +668,8 @@ export class ImportExportComponent implements OnDestroy, OnInit { | |
layers: [[], [Validators.required]], | ||
layersWithSelection: [[]], | ||
encoding: [EncodingFormat.UTF8, [Validators.required]], | ||
combineLayers: [true, [Validators.required]], | ||
separator: [false, [Validators.required]], | ||
featureInMapExtent: [false, [Validators.required]], | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Translation would be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done