forked from MapComplete/MapComplete
Reformat all files with prettier
This commit is contained in:
parent
e22d189376
commit
b541d3eab4
382 changed files with 50893 additions and 35566 deletions
|
@ -1,9 +1,8 @@
|
|||
import {parse} from 'csv-parse/sync';
|
||||
import {readFileSync} from "fs";
|
||||
import { parse } from "csv-parse/sync"
|
||||
import { readFileSync } from "fs"
|
||||
|
||||
var lambert72toWGS84 = function(x, y){
|
||||
|
||||
var newLongitude, newLatitude;
|
||||
var lambert72toWGS84 = function (x, y) {
|
||||
var newLongitude, newLatitude
|
||||
|
||||
var n = 0.77164219,
|
||||
F = 1.81329763,
|
||||
|
@ -12,78 +11,81 @@ var lambert72toWGS84 = function(x, y){
|
|||
a = 6378388,
|
||||
xDiff = 149910,
|
||||
yDiff = 5400150,
|
||||
theta0 = 0.07604294;
|
||||
theta0 = 0.07604294
|
||||
|
||||
var xReal = xDiff - x,
|
||||
yReal = yDiff - y;
|
||||
yReal = yDiff - y
|
||||
|
||||
var rho = Math.sqrt(xReal * xReal + yReal * yReal),
|
||||
theta = Math.atan(xReal / -yReal);
|
||||
theta = Math.atan(xReal / -yReal)
|
||||
|
||||
newLongitude = (theta0 + (theta + thetaFudge) / n) * 180 / Math.PI;
|
||||
newLatitude = 0;
|
||||
newLongitude = ((theta0 + (theta + thetaFudge) / n) * 180) / Math.PI
|
||||
newLatitude = 0
|
||||
|
||||
for (var i = 0; i < 5 ; ++i) {
|
||||
newLatitude = (2 * Math.atan(Math.pow(F * a / rho, 1 / n) * Math.pow((1 + e * Math.sin(newLatitude)) / (1 - e * Math.sin(newLatitude)), e / 2))) - Math.PI / 2;
|
||||
for (var i = 0; i < 5; ++i) {
|
||||
newLatitude =
|
||||
2 *
|
||||
Math.atan(
|
||||
Math.pow((F * a) / rho, 1 / n) *
|
||||
Math.pow(
|
||||
(1 + e * Math.sin(newLatitude)) / (1 - e * Math.sin(newLatitude)),
|
||||
e / 2
|
||||
)
|
||||
) -
|
||||
Math.PI / 2
|
||||
}
|
||||
newLatitude *= 180 / Math.PI;
|
||||
return [newLongitude, newLatitude];
|
||||
|
||||
newLatitude *= 180 / Math.PI
|
||||
return [newLongitude, newLatitude]
|
||||
}
|
||||
|
||||
function main(args: string[]): void {
|
||||
|
||||
|
||||
|
||||
if (args.length == 0) {
|
||||
/* args = ["/home/pietervdvn/Downloads/Scholen/aantallen.csv",
|
||||
/* args = ["/home/pietervdvn/Downloads/Scholen/aantallen.csv",
|
||||
"/home/pietervdvn/Downloads/Scholen/perschool.csv",
|
||||
"/home/pietervdvn/Downloads/Scholen/Vestigingsplaatsen-van-scholen-gewoon-secundair-onderwijs-cleaned.csv"]
|
||||
*/
|
||||
console.log("Usage: csvToGeojson input.csv name-of-lat-field name-of-lon-field")
|
||||
console.log("Usage: csvToGeojson input.csv name-of-lat-field name-of-lon-field")
|
||||
return
|
||||
}
|
||||
|
||||
let file = args[0]
|
||||
if(file.startsWith("file://")){
|
||||
|
||||
let file = args[0]
|
||||
if (file.startsWith("file://")) {
|
||||
file = file.substr("file://".length)
|
||||
}
|
||||
const latField = args[1]
|
||||
const lonField = args[2]
|
||||
|
||||
|
||||
const csvOptions = {
|
||||
columns: true,
|
||||
skip_empty_lines: true,
|
||||
trim: true
|
||||
trim: true,
|
||||
}
|
||||
|
||||
|
||||
const csv: Record<any, string>[] = parse(readFileSync(file), csvOptions)
|
||||
|
||||
const features = csv.map((csvElement, i) => {
|
||||
|
||||
const features = csv.map((csvElement, i) => {
|
||||
const lat = Number(csvElement[latField])
|
||||
const lon = Number(csvElement[lonField])
|
||||
if(isNaN(lat) || isNaN(lon)){
|
||||
throw `Not a valid lat or lon for entry ${i}: ${JSON.stringify(csvElement)}`
|
||||
}
|
||||
|
||||
|
||||
if (isNaN(lat) || isNaN(lon)) {
|
||||
throw `Not a valid lat or lon for entry ${i}: ${JSON.stringify(csvElement)}`
|
||||
}
|
||||
|
||||
return {
|
||||
return {
|
||||
type: "Feature",
|
||||
properties: csvElement,
|
||||
geometry: {
|
||||
type: "Point",
|
||||
coordinates: lambert72toWGS84(lon, lat)
|
||||
}
|
||||
coordinates: lambert72toWGS84(lon, lat),
|
||||
},
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
console.log(JSON.stringify({
|
||||
type: "FeatureCollection",
|
||||
features
|
||||
}))
|
||||
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
type: "FeatureCollection",
|
||||
features,
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
main(process.argv.slice(2))
|
||||
main(process.argv.slice(2))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue