From 98d92e763a585779707d5b7a5bd2dd988b218009 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Thu, 9 Dec 2021 18:01:11 +0100 Subject: [PATCH] Add tools to create postal code boundaries --- scripts/generateDocs.ts | 6 +- scripts/makeConvex.ts | 30 + scripts/postal_code_tools/genPostal.sh | 4 + .../postal_code_tools/knownPostalCodes.csv | 865 ++++++++++++++++++ .../openaddresses2geojson.ts | 123 +++ .../postal_code_tools/prepPostalCodesHulls.ts | 55 ++ 6 files changed, 1080 insertions(+), 3 deletions(-) create mode 100644 scripts/makeConvex.ts create mode 100644 scripts/postal_code_tools/genPostal.sh create mode 100644 scripts/postal_code_tools/knownPostalCodes.csv create mode 100644 scripts/postal_code_tools/openaddresses2geojson.ts create mode 100644 scripts/postal_code_tools/prepPostalCodesHulls.ts diff --git a/scripts/generateDocs.ts b/scripts/generateDocs.ts index ff0d3fc0d..3ef152e7a 100644 --- a/scripts/generateDocs.ts +++ b/scripts/generateDocs.ts @@ -51,7 +51,7 @@ Minimap.createMiniMap = _ => { const dummyLayout = new LayoutConfig({ language: ["en"], - id: "", + id: ">theme<", maintainer: "pietervdvn", version: "0", title: "", @@ -63,7 +63,7 @@ const dummyLayout = new LayoutConfig({ layers: [ { name: "", - id: "", + id: "<layer>", source: { osmTags: "id~*" }, @@ -75,7 +75,7 @@ const dummyLayout = new LayoutConfig({ new FeatureSwitchState(dummyLayout) -QueryParameters.GetQueryParameter("layer-", "true", "Wether or not the layer with id is shown") +QueryParameters.GetQueryParameter("layer-<layer-id>", "true", "Wether or not the layer with id is shown") WriteFile("./Docs/URL_Parameters.md", QueryParameterDocumentation.GenerateQueryParameterDocs(), ["QueryParameters"]) diff --git a/scripts/makeConvex.ts b/scripts/makeConvex.ts new file mode 100644 index 000000000..ddcca0818 --- /dev/null +++ b/scripts/makeConvex.ts @@ -0,0 +1,30 @@ +import fs from "fs"; +import {GeoOperations} from "../Logic/GeoOperations"; +import ScriptUtils from "./ScriptUtils"; + +/** + * Given one of more files, calculates a somewhat convex hull for them + * @param file + */ + +function makeConvex(file) { + ScriptUtils.erasableLog("Handling", file) + const geoJson = JSON.parse(fs.readFileSync(file, "UTF8")) + const convex = GeoOperations.convexHull(geoJson, {concavity: 2}) + if (convex.properties === undefined) { + convex.properties = {} + } + fs.writeFileSync(file + ".convex.geojson", JSON.stringify(convex)) + +} + + +let args = [...process.argv] +args.splice(0, 2) +args.forEach(file => { + try { + makeConvex(file) + } catch (e) { + console.error("Could not handle file ", file, " due to ", e) + } +}) \ No newline at end of file diff --git a/scripts/postal_code_tools/genPostal.sh b/scripts/postal_code_tools/genPostal.sh new file mode 100644 index 000000000..1b586627f --- /dev/null +++ b/scripts/postal_code_tools/genPostal.sh @@ -0,0 +1,4 @@ +#! /bin/bash + +npm run generate:layeroverview +ts-node scripts/generateCache.ts postal_codes 8 /home/pietervdvn/Downloads/postal_codes 49.69606181911566 2.373046875 51.754240074033525 6.459960937499999 --generate-point-overview '*' --force-zoom-level 1 \ No newline at end of file diff --git a/scripts/postal_code_tools/knownPostalCodes.csv b/scripts/postal_code_tools/knownPostalCodes.csv new file mode 100644 index 000000000..c8b605cdf --- /dev/null +++ b/scripts/postal_code_tools/knownPostalCodes.csv @@ -0,0 +1,865 @@ +relation/3132739,9000 +relation/3139053,9042 +relation/3360497,2812 +relation/3362712,2840 +relation/3362870,2880 +relation/3363489,2550 +relation/3363494,2570 +relation/3363502,2850 +relation/3363503,2820 +relation/3363507,2845 +relation/3363508,2630 +relation/3363512,2610 +relation/3363513,2650 +relation/3363518,2600 +relation/3363519,2640 +relation/3363541,2620 +relation/3363542,2627 +relation/3363543,2660 +relation/3363545,2830 +relation/3363546,2870 +relation/3363558,2150 +relation/3363559,2160 +relation/3363560,2530 +relation/3363561,2531 +relation/3363578,2540 +relation/3363579,2547 +relation/3363583,2520 +relation/3363592,2970 +relation/3363595,2100 +relation/3363596,2110 +relation/3363734,2040 +relation/3363834,2940 +relation/3363845,2910 +relation/3363847,2990 +relation/3363868,2980 +relation/3363869,2330 +relation/3363873,2370 +relation/3363878,2470 +relation/3363879,2480 +relation/3363881,2400 +relation/3363885,2340 +relation/3363886,2350 +relation/3363890,2275 +relation/3363892,2290 +relation/3363893,2200 +relation/3363894,2250 +relation/3363897,2260 +relation/3364558,2320 +relation/3364559,2321 +relation/3364560,2322 +relation/3364561,2323 +relation/3364562,2328 +relation/3364725,2280 +relation/3364726,2288 +relation/3364735,2270 +relation/3364739,2235 +relation/3364741,2230 +relation/3364742,2440 +relation/3364743,2460 +relation/3364745,2450 +relation/3364748,3560 +relation/3364754,3920 +relation/3364759,3900 +relation/3364761,3930 +relation/3364762,3910 +relation/3364768,3960 +relation/3364769,3950 +relation/3364771,3990 +relation/3364772,3670 +relation/3364789,3660 +relation/3364795,3640 +relation/3364804,3680 +relation/3364806,3550 +relation/3364812,3520 +relation/3364813,3600 +relation/3364815,3590 +relation/3364821,3690 +relation/3364825,3770 +relation/3364826,3700 +relation/3364827,3840 +relation/3364829,3870 +relation/3364833,3440 +relation/3364835,3350 +relation/3364836,3300 +relation/3364838,4287 +relation/3364841,1357 +relation/3364842,3540 +relation/3364845,3570 +relation/3364847,3980 +relation/3364848,3370 +relation/3364851,3360 +relation/3364852,3040 +relation/3365424,2030 +relation/3365426,2170 +relation/3365439,2950 +relation/3365440,2180 +relation/3365441,2930 +relation/3365442,2920 +relation/3365443,2900 +relation/3365444,2960 +relation/3365445,2390 +relation/3365447,2310 +relation/3365684,2050 +relation/3365779,2020 +relation/3365990,2500 +relation/3366032,2060 +relation/3366102,2000 +relation/3366103,2018 +relation/3366216,2590 +relation/3366218,2580 +relation/3366219,2560 +relation/3366245,3140 +relation/3366247,3130 +relation/3366250,3150 +relation/3366251,1910 +relation/3366254,1820 +relation/3366255,1800 +relation/3366258,1880 +relation/3366260,1840 +relation/3366261,9255 +relation/3366264,1780 +relation/3366265,1785 +relation/3366268,2890 +relation/3366269,1745 +relation/3366272,9280 +relation/3366273,9200 +relation/3366275,9220 +relation/3366276,9240 +relation/3366277,9140 +relation/3366282,9150 +relation/3366288,2070 +relation/3366289,9170 +relation/3366292,9190 +relation/3366294,9250 +relation/3366296,9160 +relation/3366298,9080 +relation/3366299,9180 +relation/3366301,9060 +relation/3366302,9290 +relation/3366305,9260 +relation/3366308,9340 +relation/3366309,9420 +relation/3366312,9230 +relation/3366318,9270 +relation/3366320,9070 +relation/3366321,9090 +relation/3366325,9860 +relation/3366344,9185 +relation/3366347,9940 +relation/3366348,9900 +relation/3366355,9910 +relation/3366358,8340 +relation/3366360,8730 +relation/3366362,8377 +relation/3366364,8490 +relation/3366366,8370 +relation/3366383,2140 +relation/3366390,8300 +relation/3366392,8301 +relation/3366396,8380 +relation/3366400,8310 +relation/3366410,8200 +relation/3366411,8000 +relation/3366414,8470 +relation/3366415,8400 +relation/3366421,8450 +relation/3366423,8620 +relation/3366426,8670 +relation/3366427,8660 +relation/3366428,8630 +relation/3366433,8600 +relation/3366434,8820 +relation/3366435,8480 +relation/3366436,8680 +relation/3366442,8430 +relation/3366446,8431 +relation/3366454,8432 +relation/3366457,8434 +relation/3366462,8433 +relation/3366463,3000 +relation/3366464,3001 +relation/3366465,3010 +relation/3366466,3012 +relation/3366467,3018 +relation/3366516,3020 +relation/3366517,3118 +relation/3366561,3110 +relation/3366562,3111 +relation/3366812,8020 +relation/3366814,8211 +relation/3366818,8210 +relation/3366820,8750 +relation/3366822,8830 +relation/3366823,8840 +relation/3366829,8690 +relation/3366830,8691 +relation/3366874,8647 +relation/3366876,8640 +relation/3366879,8978 +relation/3366883,8970 +relation/3366888,8972 +relation/3367188,8908 +relation/3367195,8906 +relation/3367200,8904 +relation/3367229,8902 +relation/3367235,8900 +relation/3367255,8952 +relation/3367260,8953 +relation/3367485,8950 +relation/3367488,8951 +relation/3367525,8954 +relation/3367526,8956 +relation/3367528,8958 +relation/3367534,8957 +relation/3367536,8980 +relation/3367990,8880 +relation/3367991,8890 +relation/3367995,8920 +relation/3367997,8650 +relation/3368005,8610 +relation/3368013,8810 +relation/3368014,8850 +relation/3368033,8851 +relation/3368036,8740 +relation/3368038,8800 +relation/3368047,8870 +relation/3368056,8770 +relation/3368057,8700 +relation/3368059,8755 +relation/3368064,8760 +relation/3368066,8860 +relation/3368070,8940 +relation/3368084,8930 +relation/3368087,8560 +relation/3368088,8511 +relation/3368096,8720 +relation/3368099,8780 +relation/3368101,8710 +relation/3368108,8531 +relation/3368115,8792 +relation/3368119,8791 +relation/3368120,8193 +relation/3368124,8790 +relation/3368132,8540 +relation/3368143,8530 +relation/3368151,8520 +relation/3368162,8501 +relation/3368167,8510 +relation/3368549,8500 +relation/3368551,8550 +relation/3368552,8551 +relation/3368553,8552 +relation/3368866,8554 +relation/3368867,8587 +relation/3368870,8580 +relation/3368872,8581 +relation/3368875,8582 +relation/3368878,8583 +relation/3368879,8553 +relation/3368881,8572 +relation/3368884,8573 +relation/3368890,8570 +relation/3368898,9790 +relation/3368899,9750 +relation/3368903,9870 +relation/3368904,9700 +relation/3368906,9690 +relation/3368908,9600 +relation/3368920,9661 +relation/3368951,9660 +relation/3369135,2240 +relation/3369136,2242 +relation/3369137,2243 +relation/3369141,2300 +relation/3369143,2360 +relation/3369202,2380 +relation/3369203,2381 +relation/3369204,2382 +relation/3369409,2220 +relation/3369410,2221 +relation/3369411,2222 +relation/3369412,2223 +relation/3369532,2800 +relation/3369533,2801 +relation/3369534,2811 +relation/3369670,2430 +relation/3369671,2431 +relation/3369708,2490 +relation/3369709,2491 +relation/3373522,9120 +relation/3373523,9130 +relation/3376627,9112 +relation/3376836,9100 +relation/3376837,9111 +relation/3379410,1000 +relation/3379411,1020 +relation/3379412,1030 +relation/3379413,1040 +relation/3379414,1050 +relation/3379415,1060 +relation/3379416,1070 +relation/3379417,1080 +relation/3379418,1081 +relation/3379419,1082 +relation/3379420,1083 +relation/3379421,1090 +relation/3379422,1120 +relation/3379423,1130 +relation/3379424,1140 +relation/3379425,1150 +relation/3379426,1160 +relation/3379427,1170 +relation/3379428,1180 +relation/3379429,1190 +relation/3379430,1200 +relation/3379431,1210 +relation/3382866,1730 +relation/3382867,1731 +relation/3388165,2860 +relation/3388166,2861 +relation/3388219,9960 +relation/3388220,9961 +relation/3388221,9968 +relation/3388426,9320 +relation/3389084,9300 +relation/3389085,9308 +relation/3389086,9310 +relation/3389796,9450 +relation/3389797,9451 +relation/3389820,9403 +relation/3389821,9406 +relation/3390349,9400 +relation/3390350,9401 +relation/3390351,9402 +relation/3390352,9404 +relation/3390505,9470 +relation/3390506,9472 +relation/3390507,9473 +relation/3395144,9040 +relation/3395438,9500 +relation/3395439,9506 +relation/3395501,9550 +relation/3395502,9551 +relation/3395503,9552 +relation/3395517,9620 +relation/3395616,9570 +relation/3395617,9571 +relation/3395618,9572 +relation/3396269,9520 +relation/3396270,9521 +relation/3401812,9680 +relation/3401813,9681 +relation/3401814,9688 +relation/3402433,9630 +relation/3402434,9636 +relation/3402455,9890 +relation/3402463,9820 +relation/3402467,9667 +relation/3402498,9770 +relation/3402499,9771 +relation/3402512,9810 +relation/3402518,9840 +relation/3402538,9830 +relation/3402539,9831 +relation/3402546,9800 +relation/3402556,9920 +relation/3402557,9921 +relation/3402566,9950 +relation/3402584,9772 +relation/3464939,9990 +relation/3464940,9991 +relation/3464941,9992 +relation/3465067,9980 +relation/3465068,9988 +relation/3465069,9981 +relation/3465070,9982 +relation/3465093,9970 +relation/3465094,9971 +relation/3465186,9930 +relation/3465187,9931 +relation/3465188,9932 +relation/3465267,9850 +relation/3465316,9880 +relation/3465317,9881 +relation/3465327,8421 +relation/3465330,8420 +relation/3465348,8460 +relation/3465364,1860 +relation/3465365,1861 +relation/3479470,3190 +relation/3479471,3191 +relation/3479494,1980 +relation/3479495,1981 +relation/3479536,1850 +relation/3479537,1851 +relation/3479538,1852 +relation/3479539,1853 +relation/3479592,1830 +relation/3479593,1831 +relation/3479621,3070 +relation/3479622,3071 +relation/3479623,3078 +relation/3479665,1930 +relation/3479666,1932 +relation/3479667,1933 +relation/3479696,3080 +relation/3479742,1970 +relation/3479744,1950 +relation/3479747,3090 +relation/3479750,1560 +relation/3479798,3060 +relation/3479799,3061 +relation/3479847,3050 +relation/3479848,3051 +relation/3479849,3052 +relation/3479850,3053 +relation/3479851,3054 +relation/3479860,1982 +relation/3754121,9050 +relation/3754122,9051 +relation/3867174,3120 +relation/3867175,3128 +relation/3891769,3945 +relation/3891778,3545 +relation/3895654,3970 +relation/3895655,3971 +relation/3929631,3940 +relation/3929632,3941 +relation/3930000,3581 +relation/3930143,3583 +relation/3931049,3580 +relation/3931050,3582 +relation/3939002,3530 +relation/3942151,3850 +relation/3942525,3210 +relation/3942526,3211 +relation/3942527,3212 +relation/3942584,1790 +relation/3942585,1770 +relation/3942600,1547 +relation/3942703,1570 +relation/3942876,1755 +relation/3942878,1750 +relation/3942890,1620 +relation/3942912,1630 +relation/3942913,1640 +relation/3943013,9032 +relation/3943014,9041 +relation/3943048,9030 +relation/3943055,9031 +relation/3943102,9052 +relation/3945536,3220 +relation/3945537,3221 +relation/3950158,1740 +relation/3950159,1741 +relation/3950160,1742 +relation/3953991,1761 +relation/3954045,1760 +relation/3962684,1702 +relation/3964740,3320 +relation/3964741,3321 +relation/3977259,3717 +relation/4011593,1703 +relation/4012641,1700 +relation/4012642,1701 +relation/4017007,7730 +relation/4017128,7760 +relation/4017129,7750 +relation/4017304,7611 +relation/4017305,7610 +relation/4017306,7618 +relation/4017348,7624 +relation/4017358,7623 +relation/4017376,7621 +relation/4017450,7620 +relation/4017452,7622 +relation/4017512,7643 +relation/4017569,7642 +relation/4017570,7641 +relation/4017582,7640 +relation/4017842,7350 +relation/4017852,7382 +relation/4017853,7380 +relation/4018917,7370 +relation/4062084,7600 +relation/4062085,7601 +relation/4069650,7340 +relation/4069687,7080 +relation/4072281,7390 +relation/4072445,7050 +relation/4072459,7870 +relation/4072510,7830 +relation/4072511,7850 +relation/4072560,1430 +relation/4072656,7090 +relation/4072686,7070 +relation/4103968,1650 +relation/4103969,1651 +relation/4103970,1652 +relation/4103971,1653 +relation/4103972,1654 +relation/4104019,1601 +relation/4104200,1600 +relation/4104201,1602 +relation/4105502,1501 +relation/4105926,1500 +relation/4105927,1502 +relation/4108139,1671 +relation/4109781,1670 +relation/4109782,1673 +relation/4109783,1674 +relation/4109911,1540 +relation/4109912,1541 +relation/4186134,3501 +relation/4189269,3500 +relation/4193628,3512 +relation/4196096,3510 +relation/4196328,3650 +relation/4198359,3511 +relation/4203185,7170 +relation/4203186,7160 +relation/4215710,3665 +relation/4215711,3668 +relation/4218236,7120 +relation/4218237,6560 +relation/4218238,6567 +relation/4220905,6470 +relation/4235983,6000 +relation/4236044,6001 +relation/4236045,6010 +relation/4236122,6020 +relation/4236123,6030 +relation/4236155,6031 +relation/4236156,6032 +relation/4236191,6040 +relation/4236198,6041 +relation/4236232,6042 +relation/4236233,6043 +relation/4236263,6044 +relation/4236299,6060 +relation/4236300,6061 +relation/4238953,6120 +relation/4238988,6150 +relation/4239031,6200 +relation/4239038,6211 +relation/4239165,6210 +relation/4240188,6224 +relation/4240192,6223 +relation/4240196,6222 +relation/4240197,6221 +relation/4240223,6220 +relation/4253515,6230 +relation/4253516,6238 +relation/4253571,6240 +relation/4253578,6250 +relation/4253589,6280 +relation/4253627,7180 +relation/4253628,7181 +relation/4253646,6500 +relation/4253647,6511 +relation/4253781,1480 +relation/4473118,3830 +relation/4476408,3730 +relation/4478844,3200 +relation/4478891,3201 +relation/4478892,3202 +relation/4479876,3831 +relation/4479877,3832 +relation/4479929,3720 +relation/4479930,3721 +relation/4479931,3722 +relation/4479932,3723 +relation/4479933,3724 +relation/4479946,3732 +relation/4480724,3293 +relation/4480743,3290 +relation/4480744,3294 +relation/4482775,3746 +relation/4492492,3270 +relation/4493465,3742 +relation/4494368,3271 +relation/4494369,3272 +relation/4497124,3798 +relation/4497188,3792 +relation/4497356,3790 +relation/4497379,3791 +relation/4497380,3793 +relation/4635621,3390 +relation/4635622,3391 +relation/4636469,3460 +relation/4636470,3461 +relation/4641362,3450 +relation/4641363,3454 +relation/4642674,3380 +relation/4642675,3381 +relation/4642676,3384 +relation/4644584,3473 +relation/4644666,3472 +relation/4644681,3470 +relation/4644682,3471 +relation/4677616,3401 +relation/4677870,3404 +relation/4678417,3400 +relation/4681897,3800 +relation/4681898,3803 +relation/4681899,3806 +relation/4713840,3740 +relation/4714602,3621 +relation/4714658,3620 +relation/4717645,3631 +relation/4717688,3630 +relation/4720905,3890 +relation/4720907,3891 +relation/4727591,1315 +relation/4727592,1320 +relation/4727593,1350 +relation/4727594,1360 +relation/4727595,1367 +relation/4727596,1370 +relation/4727602,1390 +relation/4727606,1325 +relation/4727607,1457 +relation/4727631,1310 +relation/4727632,1331 +relation/4727641,1330 +relation/4727642,1332 +relation/4727648,1410 +relation/4727654,1380 +relation/4727658,1440 +relation/4727668,1420 +relation/4727671,1421 +relation/4727712,1460 +relation/4727713,1461 +relation/4727724,1435 +relation/4727727,1450 +relation/4727732,1495 +relation/4727733,1490 +relation/4727759,1342 +relation/4727761,1341 +relation/4728040,7608 +relation/5720163,1428 +relation/5721127,1401 +relation/5721133,1404 +relation/5724081,1402 +relation/5724100,1400 +relation/5724109,1476 +relation/5724114,1473 +relation/5724115,1471 +relation/5724131,1474 +relation/5724280,1472 +relation/5724305,1470 +relation/5726870,5140 +relation/6343119,1300 +relation/6517171,59150 +relation/8345160,1340 +relation/8345161,1348 +relation/9520110,7940 +relation/9622112,6724 +relation/9706199,4970 +relation/9706200,4960 +relation/9708979,4790 +relation/9721913,4760 +relation/9721914,4750 +relation/9721915,4770 +relation/9721916,4950 +relation/9721917,4780 +relation/9724931,5150 +relation/9730734,4987 +relation/9792735,4990 +relation/9938886,4837 +relation/9970249,4820 +relation/9970250,4821 +relation/10143396,4877 +relation/10184618,4870 +relation/10184619,4861 +relation/10184620,4860 +relation/10284874,4845 +relation/10284875,4910 +relation/10284876,4900 +relation/10308690,6700 +relation/10308691,6704 +relation/10308692,6706 +relation/10312732,6721 +relation/10312733,6720 +relation/10312734,6723 +relation/10619232,6792 +relation/10626187,6630 +relation/10626251,6840 +relation/10626571,6717 +relation/10632750,6747 +relation/10707212,6780 +relation/10893681,4920 +relation/10953767,6890 +relation/10973142,4141 +relation/10973143,4140 +relation/11074457,4190 +relation/11133193,4180 +relation/11133194,4181 +relation/11152476,6990 +relation/11152477,6997 +relation/11152478,6960 +relation/11230847,6637 +relation/11278663,6987 +relation/11294782,6860 +relation/11331902,6640 +relation/11384736,6600 +relation/11485371,6687 +relation/11583045,7783 +relation/11583046,7782 +relation/11583047,7784 +relation/11583048,7780 +relation/11583049,7781 +relation/11584131,7711 +relation/11584132,7712 +relation/11584133,7700 +relation/11599903,7880 +relation/11599904,7890 +relation/11611417,4130 +relation/11611430,7860 +relation/11726320,4653 +relation/11726410,4654 +relation/11736448,4651 +relation/11736449,4652 +relation/11736450,4650 +relation/11798622,4890 +relation/11820267,4880 +relation/11866085,6343 +relation/11965721,4841 +relation/11965722,4840 +relation/12006674,6760 +relation/12009767,6769 +relation/12009804,6730 +relation/12077869,6782 +relation/12077908,6781 +relation/12077926,6741 +relation/12077964,6813 +relation/12077971,6740 +relation/12078017,6742 +relation/12095656,4721 +relation/12095657,4720 +relation/12095658,4728 +relation/12108800,6812 +relation/12108822,6811 +relation/12108981,6810 +relation/12109042,6823 +relation/12115031,6820 +relation/12142985,4731 +relation/12142986,4730 +relation/12192340,4701 +relation/12192341,4700 +relation/12192342,4710 +relation/12192343,4711 +relation/12215466,6887 +relation/12215660,6824 +relation/12215687,6821 +relation/12215831,6831 +relation/12215896,6836 +relation/12247586,4590 +relation/12265101,4161 +relation/12265102,4162 +relation/12265103,4163 +relation/12265104,4160 +relation/12431129,4560 +relation/12452305,4577 +relation/12472225,4570 +relation/12476593,4520 +relation/12476594,4500 +relation/12481068,4550 +relation/12481069,4557 +relation/12553251,4217 +relation/12553252,4210 +relation/12575264,4218 +relation/12593511,4480 +relation/12593512,4537 +relation/12593513,4470 +relation/12593514,4540 +relation/12612191,4530 +relation/12616025,6800 +relation/12616487,6830 +relation/12616501,6832 +relation/12616681,6880 +relation/12751422,4260 +relation/12751423,4280 +relation/12751424,4357 +relation/12751425,4350 +relation/12751426,4360 +relation/12751427,4367 +relation/12751428,4300 +relation/12751429,4250 +relation/12751430,4257 +relation/12818751,6681 +relation/12818787,6680 +relation/12888344,6661 +relation/12888355,6666 +relation/12888356,6663 +relation/12888358,6660 +relation/12888379,6662 +relation/12888625,6688 +relation/12888627,6686 +relation/12901768,6673 +relation/12901769,6674 +relation/12901770,6670 +relation/12901772,6672 +relation/12901773,6671 +relation/12901778,6692 +relation/12901817,6690 +relation/12901819,6698 +relation/12904655,6984 +relation/12904664,6983 +relation/12904688,6986 +relation/12904710,6972 +relation/12904847,6982 +relation/12904861,6980 +relation/12904877,6971 +relation/12904949,6970 +relation/12910224,6870 +relation/12911159,6927 +relation/12911189,6852 +relation/12911214,6856 +relation/12911238,6850 +relation/12911239,6851 +relation/12911525,6924 +relation/12911552,6920 +relation/12911560,6922 +relation/12911593,6921 +relation/12911603,6853 +relation/12911813,6838 +relation/12911859,6834 +relation/12911863,6833 +relation/12922472,6929 +relation/13006513,4219 +relation/13017440,4261 +relation/13017441,4263 +relation/13072253,6940 +relation/13072279,6941 +relation/13075685,6951 +relation/13075686,6952 +relation/13075687,6900 +relation/13075718,6950 +relation/13075724,6953 +relation/13163556,4347 +relation/13219312,4351 +relation/13238973,4317 +relation/13241165,4252 +relation/13241166,4253 +relation/13241167,4254 +relation/13281285,4420 +relation/13281286,4400 +relation/13281287,4460 +relation/13330444,4610 +relation/13330601,4608 +relation/13330602,4606 +relation/13330603,4607 +relation/13375800,4672 +relation/13375801,4671 +relation/13375802,4670 +relation/13435478,4624 +relation/13435479,4623 +relation/13435480,4621 +relation/13435481,4620 +relation/13436023,4631 +relation/13436024,4632 +relation/13436025,4633 +relation/13436026,4630 +relation/13529276,4791 diff --git a/scripts/postal_code_tools/openaddresses2geojson.ts b/scripts/postal_code_tools/openaddresses2geojson.ts new file mode 100644 index 000000000..572603fc9 --- /dev/null +++ b/scripts/postal_code_tools/openaddresses2geojson.ts @@ -0,0 +1,123 @@ +import * as fs from "fs"; +import * as readline from "readline"; +import ScriptUtils from "./ScriptUtils"; +import {existsSync, writeFileSync} from "fs"; +import {GeoOperations} from "../Logic/GeoOperations"; +import {Utils} from "../Utils"; +import {post} from "jquery"; +import {createECDH} from "crypto"; + +/** + * Converts an open-address CSV file into a big geojson file + */ + +async function main(args: string[]) { + + const inputFile = args[0] + const outputFile = args[1] + const fileStream = fs.createReadStream(inputFile); + const perPostalCode = args[2] == "--per-postal-code" + const rl = readline.createInterface({ + input: fileStream, + crlfDelay: Infinity + }); + // Note: we use the crlfDelay option to recognize all instances of CR LF + // ('\r\n') in input.txt as a single line break. + + const fields = [ + "EPSG:31370_x", "EPSG:31370_y", "EPSG:4326_lat", "EPSG:4326_lon", + "address_id", "box_number", + "house_number", "municipality_id", "municipality_name_de", "municipality_name_fr", "municipality_name_nl", "postcode", "postname_fr", + "postname_nl", "street_id", "streetname_de", "streetname_fr", "streetname_nl", "region_code", "status" + ] + + let i = 0; + let failed = 0 + + let createdFiles : string [] = [] + fs.writeFileSync(outputFile, "") + // @ts-ignore + for await (const line of rl) { + i++; + if (i % 10000 == 0) { + ScriptUtils.erasableLog("Converted ", i, "features (of which ", failed, "features don't have a coordinate)") + } + const data = line.split(",") + const parsed: any = {} + for (let i = 0; i < fields.length; i++) { + const field = fields[i]; + parsed[field] = data[i] + } + const lat = Number(parsed["EPSG:4326_lat"]) + const lon = Number(parsed["EPSG:4326_lon"]) + + if (parsed["EPSG:31370_x"] === "0.0") { + failed++ + continue + } + + delete parsed["EPSG:4326_lat"] + delete parsed["EPSG:4326_lon"] + delete parsed["EPSG:31370_x"] + delete parsed["EPSG:31370_y"] + delete parsed["EPSG:4326_lat"] + delete parsed["EPSG:4326_lat"] + + let targetFile = outputFile + if (perPostalCode) { + targetFile = outputFile + "-" + parsed["postcode"] + ".geojson" + let isFirst = false + if(!existsSync(targetFile)){ + writeFileSync(targetFile, '{ "type":"FeatureCollection", "features":[') + createdFiles.push(targetFile) + isFirst = true + } + + if(!isFirst){ + fs.appendFileSync(targetFile, ",\n") + } + + fs.appendFileSync(targetFile, JSON.stringify({ + type: "Feature", + properties: parsed, + geometry: { + type: "Point", + coordinates: [lon, lat] + } + })) + + }else{ + + + fs.appendFileSync(outputFile, JSON.stringify({ + type: "Feature", + properties: parsed, + geometry: { + type: "Point", + coordinates: [lon, lat] + } + }) + "\n") + } + + + } + + console.log("Closing files...") + createdFiles.sort() + for (const createdFile of createdFiles) { + ScriptUtils.erasableLog("Closing ", createdFile, "and creating convex hull") + fs.appendFileSync(createdFile, "]}") + } + + console.log("Done! Converted ", i, "features (of which ", failed, "features don't have a coordinate)") + +} + +let args = [...process.argv] +args.splice(0, 2) + +if (args.length == 0) { + console.log("USAGE: input-csv-file output.newline-delimited-geojson.json [--per-postal-code]") +} else { + main(args).catch(e => console.error(e)) +} diff --git a/scripts/postal_code_tools/prepPostalCodesHulls.ts b/scripts/postal_code_tools/prepPostalCodesHulls.ts new file mode 100644 index 000000000..33a0816a7 --- /dev/null +++ b/scripts/postal_code_tools/prepPostalCodesHulls.ts @@ -0,0 +1,55 @@ +import * as fs from "fs"; +import ScriptUtils from "./ScriptUtils"; +import {post} from "jquery"; +import {writeFileSync} from "fs"; + +function handleFile(file: string, postalCode: number) { + + const geojson = JSON.parse(fs.readFileSync(file, "UTF8")) + geojson.properties = { + type: "boundary", + "boundary": "postal_code", + "postal_code": postalCode + "" + } + return geojson +} + + +function getKnownPostalCodes(): number[] { + return fs.readFileSync("./scripts/postal_code_tools/knownPostalCodes.csv", "UTF8").split("\n") + .map(line => Number(line.split(",")[1])) +} + +function main(args: string[]) { + const dir = args[0] + const knownPostals = new Set(getKnownPostalCodes()) + const files = ScriptUtils.readDirRecSync(dir, 1) + const allFiles = [] + const skipped = [] + for (const file of files) { + const nameParts = file.split("-") + const postalCodeStr = nameParts[nameParts.length - 1] + const postalCode = Number(postalCodeStr.substr(0, postalCodeStr.length - ".geojson.convex.geojson".length)) + if (isNaN(postalCode)) { + console.error("Not a number: ", postalCodeStr) + continue + } + if (knownPostals.has(postalCode)) { + skipped.push(postalCode) + ScriptUtils.erasableLog("Skipping boundary for ", postalCode, "as it is already known - skipped ", skipped.length, "already") + continue + } + allFiles.push(handleFile(file, postalCode)) + } + + + writeFileSync("all_postal_codes_filtered.geojson", JSON.stringify({ + type: "FeatureCollection", + features: allFiles + })) + +} + +let args = [...process.argv] +args.splice(0, 2) +main(args) \ No newline at end of file