npm install fast-csv
var csv = require('fast-csv');
var fs = require('fs');
var request = require("super-request");
var Terraformer = require('terraformer');
var WKT = require('terraformer-wkt-parser');
var input_host = "http://datasets.antwerpen.be";
var input_path = "/v4/gis/grondwaterstroming.json";
var writeOptions = {
headers : true,
quoteHeaders : true,
quoteColumns : true,
rowDelimiter :'\n',
delimiter : ';'
};
var csvWriteStream = csv
.format(writeOptions);
var writableStream = fs.createWriteStream("C:/temp/grondwaterstroming-json-out.csv")
.on("finish", function(){
console.log("All done");
});
csvWriteStream.pipe(writableStream);
function transformOpenDataInCSVForHANA (json) {
var i = 0;
json.data.forEach(function(item) {
var geometry = new Terraformer.Primitive(JSON.parse(item.geometry));
if (geometry.hasHoles()) {
console.log("found holes in " + item.id + ". let's remove the holes");
} else {
item.geometry = WKT.convert(JSON.parse(item.geometry));
csvWriteStream.write(item);
}
i++;
});
}
function getJSONOpenData (param_host, param_path) {
var record_count = 1;
// Start the request
request(param_host)
// first let's get the number of records from the first page
.get(param_path)
.qs(function () {
return {page_size: record_count};
})
.expect(200)
.end(
function (error, response, json) {
if (!error && response.statusCode === 200) {
var page = JSON.parse(json);
record_count = page.paging.records;
} else {
console.log(error);
}
}
)
// now let's get all the records
.get(param_path)
.qs(function () {
return {page_size: record_count};
})
.expect(200)
.end(
function (error, response, json) {
console.log("page_size " + record_count);
if (!error && response.statusCode === 200) {
transformOpenDataInCSVForHANA (JSON.parse(json));
} else {
console.log(error);
}
csvWriteStream.end();
}
);
}
getJSONOpenData (input_host, input_path);
node convert-geojson-to-wkt-json.js
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
26 | |
14 | |
13 | |
13 | |
12 | |
8 | |
8 | |
7 | |
5 | |
5 |