Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
db73b86
add endpoint that returns the submissions in geojson format
willemarcel Jun 21, 2018
6d60fc8
add submissions map page
willemarcel Jul 4, 2018
58ec834
move submissions map to the submissions list page
willemarcel Jul 6, 2018
3c2b7e1
apply filter to submissions map view
willemarcel Jul 13, 2018
c02b703
add pagination support to geojson endpoint
willemarcel Jul 13, 2018
517f077
fix pagination and deviceId filtering
willemarcel Jul 14, 2018
721e0ef
improve page size options and dropdown management
willemarcel Jul 14, 2018
37722be
Merge branch 'master' into geojson-endpoint
willemarcel Aug 1, 2018
52f3489
fix errors introduced by the merge of master code
willemarcel Aug 3, 2018
f8183bc
add submission metadata to geojson endpoint
willemarcel Aug 3, 2018
ffed923
Update ignore files for EB Deploy
dakotabenjamin Aug 15, 2018
648d291
change SubmissionList design and add map visualization options
willemarcel Aug 16, 2018
6bd673e
Merge pull request #47 from dakotabenjamin/geojson-endpoint
willemarcel Aug 17, 2018
834739d
hide login button if the authentication is disabled
willemarcel Aug 17, 2018
882bfd3
improve S3 sync
willemarcel Aug 23, 2018
ad37df0
Merge pull request #52 from hotosm/improve-S3-sync
smit1678 Aug 24, 2018
b8ca1d8
Merge branch 'master' into geojson-endpoint
willemarcel Aug 24, 2018
805d4d4
Merge branch 'geojson-endpoint' of git://github.com/hotosm/OpenMapKit…
willemarcel Aug 24, 2018
7cda1d9
Merge pull request #48 from hotosm/optional-auth
willemarcel Aug 27, 2018
4ba0cad
break words of long form titles
willemarcel Aug 28, 2018
ec3b3ed
avoid the server to break if a user doesn't exist
willemarcel Sep 3, 2018
e7c390c
show error message when the login fails
willemarcel Sep 3, 2018
f41a80d
fix filter / clear filter errors
willemarcel Sep 3, 2018
118632c
set max-width to the features tag panel
willemarcel Sep 3, 2018
0bd5bab
fix map height
willemarcel Sep 3, 2018
a937293
show text if form has no data
willemarcel Sep 3, 2018
eec011e
update mapboxgl-js and react versions
willemarcel Sep 3, 2018
e6caf8b
show and hide legend
willemarcel Sep 3, 2018
b0dd475
Merge pull request #36 from hotosm/geojson-endpoint
smit1678 Sep 4, 2018
42db277
update version to 1.1.0
willemarcel Sep 4, 2018
f90a5f1
Merge pull request #55 from hotosm/v1.1.0
willemarcel Sep 4, 2018
dd5c189
Updating some broken links in README
jadsonrvieira Oct 2, 2018
24d42cf
add /submissions/features/<form_name>.csv endpoint
willemarcel Oct 4, 2018
bec6d74
some code improvements
willemarcel Oct 4, 2018
075532d
Merge pull request #62 from JadsonReis/master
willemarcel Oct 4, 2018
11ae403
Merge pull request #64 from hotosm/features-csv-endpoint
willemarcel Oct 4, 2018
9b2319a
version 1.2.0
willemarcel Oct 4, 2018
bfb3b27
Merge branch 'master' into features-csv-endpoint
willemarcel Oct 4, 2018
5813311
Merge pull request #66 from hotosm/features-csv-endpoint
willemarcel Oct 4, 2018
a79f884
include ODK data on the geojson endpoint
willemarcel Oct 11, 2018
a71f0ce
add link to geojson endpoint
willemarcel Oct 11, 2018
2191461
exclude nodes that are part of ways from geojson features
willemarcel Oct 11, 2018
b3a3943
add links to OSM Data as CSV
willemarcel Oct 11, 2018
a223626
Merge pull request #68 from hotosm/geojson-endpoint
willemarcel Oct 11, 2018
8066987
update version to 1.2.1
willemarcel Oct 11, 2018
6c948a0
Merge branch 'geojson-endpoint'
willemarcel Oct 11, 2018
d576b9d
beautify file
willemarcel Oct 12, 2018
c08e0f1
add authentication to /odk/data/submissions/
willemarcel Oct 12, 2018
5891b39
add documentation about users
willemarcel Oct 12, 2018
9982383
fix csv links in the Submission List sidebar
willemarcel Oct 16, 2018
9382f88
update version to 1.2.2
willemarcel Oct 16, 2018
64b6e2e
handle error in select_multiple field values
willemarcel Nov 1, 2018
00e7f7d
Merge pull request #71 from hotosm/handle-wrong-multiple-select-data
willemarcel Nov 1, 2018
cea4d76
Merge pull request #70 from hotosm/fix-csv-links
willemarcel Nov 1, 2018
a394fac
add filtered csv and json link options to odk data menu
willemarcel Nov 9, 2018
54874c0
update version to 1.2.3
willemarcel Nov 9, 2018
e0c7d9f
Merge pull request #72 from hotosm/add-filtered-links
willemarcel Nov 9, 2018
e8fe03d
refactoring of the S3 sync operations
willemarcel Nov 12, 2018
f74c5e4
change util/get_data_files.js and requirements
willemarcel Nov 12, 2018
71f5ba9
handle undefined values in deviceid field
willemarcel Nov 30, 2018
9a66609
Merge pull request #76 from hotosm/handle-undefined-deviceid
willemarcel Nov 30, 2018
23efb91
Merge branch 'master' into improve-s3-sync
willemarcel Nov 30, 2018
11bb61b
Merge pull request #73 from hotosm/improve-s3-sync
willemarcel Nov 30, 2018
4538948
update version
willemarcel Dec 1, 2018
fda5c57
increase maxBuffer
willemarcel Dec 4, 2018
f2feea2
add --delete option to s3 sync command
willemarcel Dec 7, 2018
057e1c6
fix bug in filter by deviceId if it is undefined.
willemarcel Dec 7, 2018
3557595
update version to 1.2.7
willemarcel Dec 7, 2018
7d5ddb1
Merge pull request #78 from hotosm/fix-s3-sync-command
willemarcel Dec 7, 2018
db43d39
update dependencies
willemarcel Jan 11, 2019
7e40e96
Merge pull request #80 from hotosm/update-dependencies
willemarcel Jan 17, 2019
acb2769
Merge pull request #69 from hotosm/data-dir-auth
willemarcel Jan 17, 2019
ca7a308
update package.json version
willemarcel Jan 17, 2019
d460942
Add filtered attachments download option
dakotabenjamin Jan 28, 2019
fffcf0d
add endpoint to create a new deployment folder
willemarcel Jan 29, 2019
2b35bdc
add deployment view and network functions
willemarcel Jan 29, 2019
2fa8907
Filter attachments
dakotabenjamin Jan 29, 2019
e7b4962
Use proper callbacks for the filter function
dakotabenjamin Jan 30, 2019
ac188db
add upload deployment view and backend endpoint
willemarcel Jan 31, 2019
67910bb
split deployment in two components + layout fixes
willemarcel Feb 4, 2019
7463082
fix deployment files server urls
willemarcel Feb 4, 2019
ca44c2f
improve text of upload deployment view
willemarcel Feb 4, 2019
8a91580
Merge pull request #85 from dakotabenjamin/add/filtered-attachments
dakotabenjamin Feb 4, 2019
f107ed1
Change download filtered attachments icon
dakotabenjamin Feb 4, 2019
d8c9e84
Merge branch 'add/filtered-attachments' of github.com:hotosm/OpenMapK…
dakotabenjamin Feb 4, 2019
46f0f6e
Fix typo
dakotabenjamin Feb 4, 2019
c93b1d5
fix problem in the filter by start and end dates
willemarcel Feb 4, 2019
83e8a72
Merge pull request #87 from hotosm/add/filtered-attachments
willemarcel Feb 4, 2019
7f1f86b
update version to 1.3.0
willemarcel Feb 4, 2019
2512d53
sync deployment folder to S3 after a file is uploaded
willemarcel Feb 7, 2019
9e1ff4a
update node version to 8
willemarcel Feb 8, 2019
48af165
Merge pull request #89 from hotosm/node8-update
willemarcel Feb 8, 2019
ebbd887
Merge pull request #86 from hotosm/deployment-upload
willemarcel Feb 11, 2019
9e66c32
update version to 1.4.0
willemarcel Feb 13, 2019
b12dbce
Merge pull request #94 from hotosm/1.4.0-release
willemarcel Feb 13, 2019
2643d2c
add loading indicator to upload forms
willemarcel Feb 14, 2019
049e8a6
update .nvmrc file
willemarcel Feb 14, 2019
aa4b065
Merge pull request #97 from hotosm/node8-update
willemarcel Feb 14, 2019
e6c1ed2
Merge pull request #96 from hotosm/loading-indicator
willemarcel Feb 14, 2019
3e92a81
code linting
willemarcel Feb 15, 2019
422c123
update frontend dependencies
willemarcel Feb 15, 2019
cf60fec
show a better error message when form/deployment upload fails
willemarcel Feb 16, 2019
726bbf9
validate form filenames for special characters
willemarcel Feb 16, 2019
f767884
store pageSize and DataView options on global state. Change table and…
willemarcel Feb 25, 2019
c28fce0
fix class tags by className
willemarcel Feb 28, 2019
87de047
improve dataView and pageSize state management
willemarcel Feb 28, 2019
55f26af
improve geojson submissions view to work also with ODK only forms
willemarcel Mar 1, 2019
f07bb9e
update frontend dependencies
willemarcel Mar 1, 2019
a2ff5c1
fix bug in preferences reducer
willemarcel Mar 4, 2019
352604d
handle forms that don't have gps_location property
willemarcel Mar 4, 2019
59d755c
fix bug when datepicker is overlaying the table
willemarcel Mar 5, 2019
3141f37
Cloudformation template for this stack (#91)
arunasank Mar 11, 2019
780bcd1
Alarms investigation (#111)
arunasank Mar 11, 2019
55799ea
add pm2 to cloudformation template
willemarcel Mar 12, 2019
f70f0e4
return response when a data file is not found
willemarcel Mar 12, 2019
cf89d17
update version to 1.4.1
willemarcel Mar 12, 2019
7145506
Merge pull request #114 from hotosm/404-form-file-error
willemarcel Mar 12, 2019
1d75b90
unset osmApi and only call createAndSubmitChangesets when osmApi is c…
willemarcel Mar 12, 2019
8fd59f1
update version to 1.4.2 and commit yarn.lock
willemarcel Mar 12, 2019
ef233e3
handle error in field variable of form.parse
willemarcel Mar 13, 2019
c419b5e
Merge pull request #116 from hotosm/handle-form-submission-error
willemarcel Mar 13, 2019
0c354d2
Merge pull request #115 from hotosm/remove-submit-to-osm
willemarcel Mar 13, 2019
8c75e8a
Merge pull request #113 from hotosm/add-pm2
willemarcel Mar 13, 2019
6857992
import values, instead of configuring them
arunasank Apr 10, 2019
8f6aabb
strings
arunasank Apr 10, 2019
4c95cc4
redirect http -> https
arunasank Apr 10, 2019
7d1bbe3
use an update policy to cycle instances
arunasank Apr 10, 2019
7769e32
Merge pull request #120 from hotosm/foreign-exchange
willemarcel Apr 10, 2019
6f2af75
Merge pull request #121 from hotosm/fencing
willemarcel Apr 10, 2019
e11e44c
Merge pull request #122 from hotosm/bicycle
willemarcel Apr 10, 2019
6ca92fc
enable secure option on openrosa middleware
willemarcel Apr 16, 2019
8bc6aaf
update openrosa-form-submission-middleware
willemarcel Apr 16, 2019
0969960
add ENABLE_HTTPS env var, update cfn template, docs and lib version
willemarcel Apr 16, 2019
99b6f1d
Merge pull request #124 from hotosm/open-rosa-secure
willemarcel Apr 23, 2019
0bab57f
Merge pull request #101 from hotosm/dependencies-linting
willemarcel Apr 23, 2019
10f4741
Merge branch 'master' into map-table-updated
willemarcel Apr 23, 2019
d957a93
Merge pull request #107 from hotosm/map-table-updated
willemarcel Apr 23, 2019
4dd8e1e
discover image field on the submission json file + fix bug on data en…
willemarcel May 2, 2019
7490034
update version to 1.5.1
willemarcel May 2, 2019
91cc84b
Merge pull request #126 from hotosm/image-discovery
willemarcel May 3, 2019
78c5e69
update pyxform version and installation method
willemarcel Nov 11, 2019
aab2edf
Merge pull request #128 from hotosm/pyxform-v0.15.1
willemarcel Nov 11, 2019
6a5a283
update posm master build url
willemarcel Jun 26, 2020
2c7aff7
Add AWS deployment docs
dakotabenjamin Jun 26, 2020
f283e80
Merge pull request #131 from hotosm/add/aws-docs
willemarcel Jun 26, 2020
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
1 change: 1 addition & 0 deletions .ebignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn.lock
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ frontend/build/asset-*

############## Jekyll Stuff ##################
.sass-cache/

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6
8
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN \
curl \
software-properties-common \
&& curl -sf https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \
&& add-apt-repository -y -u -s "deb https://deb.nodesource.com/node_6.x $(lsb_release -c -s) main" \
&& add-apt-repository -y -u -s "deb https://deb.nodesource.com/node_8.x $(lsb_release -c -s) main" \
&& apt install -y --no-install-recommends \
build-essential \
default-jre-headless \
Expand Down Expand Up @@ -49,8 +49,7 @@ RUN \
&& yarn build

RUN \
git submodule update --init \
&& useradd omkserver -m \
useradd omkserver -m \
&& chown -R omkserver:omkserver /app/data

USER omkserver
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ If you want to run OpenMapKit Server for your field mapping survey, use the

## Project Structure

[__deployments__](deployments) is the OpenMapKit
[__deployments__](api/deployments) is the OpenMapKit
deployment API. This services deployment data in the
[deployments data directory](data/deployments).
Manifest files in this directory are read by OpenMapKit Android as metadata regarding the deployment
data provided. Deployments are created by [posm-admin](https://github.com/AmericanRedCross/posm-admin).
to provision deployment data that is fetched by OpenMapKit Android.

[__odk__](odk) is the OpenMapKit ODK API.
[__odk__](api/odk) is the OpenMapKit ODK API.
This is a REST API that handles all of the ODK business logic, including communicating with ODK Collect,
as well as serving and ingesting ODK XForm data.

Expand All @@ -44,7 +44,7 @@ useful to OpenMapKit Server as a whole.

#### After your installation is done, you can see if the server is alive at:

http://{{your_host_url}}/info
http://{{your_host_url}}/omk/info

#### To get forms and send submissions in ODK Collect set:

Expand All @@ -54,11 +54,11 @@ __ODK Collect__ > __General Settings__ > __Configure platform settings__ > __URL

#### See all of the pages on your server:

http://{{your_host_url}}/pages/
http://{{your_host_url}}/

#### Upload an XLS Form:

http://{{your_host_url}}/pages/upload-form/
http://{{your_host_url}}/omk/pages/#/upload-form


## API
Expand Down
23 changes: 23 additions & 0 deletions alarms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Alarms

## Server crashes: Accessing the website returns a `504 Gateway Timeout` or `502 Bad Gateway`

This means that the request was routed to an unhealthy instance behind the OpenMapKitServer load balancer, or that there are no healthy instances behind the OpenMapKitServer load balancer. In order to fix this issue:

* Log onto the EC2 console. Find `Target Groups` from the left panel.
* Search using the full OMK stack name as a search string. For example: `OpenMapKitServer-tanzania` (Not `tanzania`). Select the target group that shows up in the search results.
* Select the `Targets` tab. At least one target must be unhealthy. Navigate to the EC2 console of the unhealthy target by clicking on the instance ID.
* SSH into the EC2 instance by using its public DNS and its key file: `ssh -i ../<path-to-keyfile> ubuntu@<Public DNS>`
* `sudo su`
* Run `lsof -i:3210`. If this shows a result, the server should become healthy, and no further actions are required. If it doesn't show a result:
* Check if there is a file called `screenlog.0` in `/home/ubuntu`. If yes, open this file, and check the last few lines. `tail -n 100 /home/ubuntu/screenlog.0 | less`.
* If this file does not exist, check the last few lines on `/var/log/cloud-init-output.log`, by running: `tail -n 100 /var/log/cloud-init-output.log | less`. Note down the last request that may have caused the server to crash on https://github.com/hotosm/OpenMapKitServer/issues/108. There are a few examples of such requests on that ticket, if you need help identifying a faulty request.

To resolve:
* `screen -S restart`
* `cd /`
* `sh /var/log/cloud/instances/<instance-ID>/user-data.txt`
* Run `Ctrl + a`, and then press `H`. This creates a new logfile for the application.
* Run `Ctrl + a` and press `d` to exit the application.

Check the target group again to see if the instance has become healthy.
4 changes: 3 additions & 1 deletion api/deployments/deployment-routes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
var router = require('express').Router({ mergeParams: true });

var getDeployments = require('./controllers/deployments');

/**
* Retrieve the list of deployment areas of interest.
*/
router.route('/').get(getDeployments.getAll);
router.route('/')
.get(getDeployments.getAll);

/**
* Retrieve meta-data for a given deployment.
Expand Down
4 changes: 0 additions & 4 deletions api/odk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ This API persists data [directly on the filesystem](https://github.com/AmericanR

This API is inspired from and directly uses some of [SimpleODK](https://github.com/digidem/simple-odk)
as well as several assocaited node modules.

[pyxform](https://github.com/spatialdev/pyxform) is installed in this directory. This python tool is used to
convert XLS Forms into XForm XML - the format understood by ODK Collect. The SpatialDev fork is used in a submodule
which fixes a bug preventing it from working on OS X.
38 changes: 3 additions & 35 deletions api/odk/controllers/archive-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var settings = require('../../../settings.js');


const moveFiles = (archiveDir, formName) => {
// move forms file to archive
// move forms files to archive/forms/ dir
fs.readdir(path.join(settings.dataDir, 'forms'), (err, items) => {
items.filter(
i => [`${formName}.xls`, `${formName}.xlsx`, `${formName}.xml`].includes(i)
Expand All @@ -19,7 +19,8 @@ const moveFiles = (archiveDir, formName) => {
if (renameError) {
console.log(`Error when moving file ${i}.`);
} else {
syncDataDir();
syncDataDir('forms');
syncDataDir('archive/forms');
};
}
)
Expand All @@ -28,22 +29,6 @@ const moveFiles = (archiveDir, formName) => {
}


const moveSubmissions = (submissionDir, archiveDir, formName) => {
// move submissions dir to archive
fse.move(
submissionDir,
path.join(archiveDir, 'submissions', formName),
renameError => {
if (renameError) {
console.log('It was not possible to move the submissions directory.');
} else {
syncDataDir();
};
}
);
}


module.exports = (req, res, next) => {
const formName = req.params.formName;
const submissionDir = path.join(settings.dataDir, 'submissions', formName);
Expand All @@ -59,9 +44,6 @@ module.exports = (req, res, next) => {
fs.mkdir(path.join(archiveDir, 'forms'), formsDirError => {
if (!formsDirError) moveFiles(archiveDir, formName);
});
fs.mkdir(path.join(archiveDir, 'submissions'), subDirError => {
if (!subDirError) moveSubmissions(submissionDir, archiveDir, formName);
});
return res.status(200).json({detail: "Form archived successfully."});
}
});
Expand All @@ -80,20 +62,6 @@ module.exports = (req, res, next) => {
} else {
moveFiles(archiveDir, formName);
}
if (items.filter(i => i === 'submissions').length === 0) {
fs.mkdir(path.join(archiveDir, 'submissions'), err => {
if (!err) {
moveSubmissions(submissionDir, archiveDir, formName);
} else {
return res.status(500).json(
{detail: "It wasn't possible to create submissions archive dir."}
);
}
}
);
} else {
moveSubmissions(submissionDir, archiveDir, formName);
}
return res.status(200).json({detail: "Form archived successfully."});
}
});
Expand Down
23 changes: 23 additions & 0 deletions api/odk/controllers/create-deployment-folder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('path');
var fs = require('fs');

var settings = require('../../../settings.js');


module.exports = (req, res, next) => {
if (req.body && req.body.name && !/[^a-zA-Z0-9\-\/]/.test(req.body.name)) {
const newDir = path.join(settings.dataDir, 'deployments', req.body.name);

fs.mkdir(newDir, {recursive: true}, mkdirError => {
if (mkdirError) {
return res.status(500).json({detail: "It wasn't possible to create new deployment folder."});
} else {
return res.status(200).json({detail: "New deployment folder created successfully."});
}
});
} else {
return res.status(500).json(
{detail: "Missing deployment name in the request body or name contains invalid characters."}
);
}
}
3 changes: 2 additions & 1 deletion api/odk/controllers/delete-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = (req, res, next) => {
const submissionDir = path.join(settings.dataDir, 'submissions', formName);
let errors = [];

// check if the form has submissions
fs.readdir(submissionDir, (err, items) => {
if (!err && items.length > 0) {
return res.status(403).json(
Expand Down Expand Up @@ -40,7 +41,7 @@ module.exports = (req, res, next) => {
{detail: "It was not possible to find or delete the form files"}
);
} else {
syncDataDir();
syncDataDir('forms');
res.status(200).json({detail: "Form deleted successfully"});
}
}
Expand Down
94 changes: 94 additions & 0 deletions api/odk/controllers/get-csv-features-submissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
var _ = require('lodash')
var aggregateOsm = require('../osm/aggregate-osm-to-geojson');
var getOsmSubmissionsDirs = require('../helpers/get-osm-submissions-dirs');
var osmtogeojson = require('osmtogeojson');
var DOMParser = require("xmldom").DOMParser;
/**
* Aggregates together all of the OSM submissions
* from ODK Collect / OpenMapKit Android to the
* file system for the given form.
*/
module.exports = function(req, res, next) {
var formName = req.params.formName;
var filters = {
deviceId: req.query.deviceId,
username: req.query.username,
startDate: req.query.start_date,
endDate: req.query.end_date,
offset: req.query.offset,
limit: req.query.limit
};

getOsmSubmissionsDirs(formName, {
filters: filters
}, function(err, osmDirs) {
if (err) {
res.status(err.status || 500).json(err);
return;
}
aggregate(osmDirs, req, res);
});
};

/**
* Calls aggregate-osm middleware to read OSM edit files
* and concatenate into a single OSM XML aggregation.
*
* @param osmDirs - submission dirs with array of osm files
* @param req - the http request
* @param res - the http response
*/
function aggregate(osmDirs, req, res) {
var osmFiles = [];
for (var i in osmDirs) {
osmFiles = osmFiles.concat(osmDirs[i].files);
}
if (req.query.offset != null) {
var offset = parseInt(req.query.offset);
var limit = parseInt(req.query.limit);
osmFiles = osmFiles.slice(offset, offset + limit);
}
//We filter by the query parameters of the request
aggregateOsm(osmFiles, req.query, function(err, osmXml) {
if (err) {
if (!res._headerSent) { // prevents trying to send multiple error responses on a single request
res.status(500).json({
status: 500,
msg: 'There was a problem with aggregating OSM JOSM editor files in the submissions directory.',
err: err
});
}
return;
}
var xmlObj = (new DOMParser()).parseFromString(osmXml, 'text/xml');
var geojson = osmtogeojson(xmlObj);
var csv = '';

// add headers (list all properties keys of the geojson file)
var properties = geojson.features.reduce(
(props, item) =>
props.concat(
Object.keys(item.properties).filter(i => props.indexOf(i) === -1)
),
[]
);

_.each(properties, function(property) {
csv += `${property},`;
});
csv += '\n';

// add data (if a feature has not a property, add a empty space)
_.each(geojson.features, function(feature){
_.each(properties, function(key, i) {
let value = feature.properties[key] ? feature.properties[key] : ' ';
csv += `"${value}",`;
});
csv += '\n';
});

res.status(200)
.set('Content-Type', 'text/csv')
.send(csv);
});
}
Loading