@janekolszak/poland 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ULIC_Adresowy_2023-02-19.csv +292672 -0
- package/generated/go/streetsInDistricts.json +1 -0
- package/generated/go/streetsInLocalities.json +1 -0
- package/generated/json/streetsInDistricts.json +1 -0
- package/generated/json/streetsInLocalities.json +1 -0
- package/index.ts +3 -3
- package/package.json +2 -2
- package/src/args.ts +2 -0
- package/src/compute.ts +117 -8
- package/src/csvparse.ts +38 -0
- package/src/generate.ts +4 -0
- package/src/map.ts +22 -1
package/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { parseCsv, parseLocalityCsv, parseLocalityTypeCsv } from "./src/csvparse"
|
|
2
|
+
import { parseCsv, parseLocalityCsv, parseLocalityTypeCsv, parseStreetsCsv } from "./src/csvparse"
|
|
3
3
|
import { compute } from "./src/compute"
|
|
4
4
|
import { generate } from "./src/generate"
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
(() => {
|
|
8
|
-
Promise.all([parseCsv(), parseLocalityCsv(), parseLocalityTypeCsv()])
|
|
9
|
-
.then(r => compute(r[0], r[1], r[2]))
|
|
8
|
+
Promise.all([parseCsv(), parseLocalityCsv(), parseLocalityTypeCsv(), parseStreetsCsv()])
|
|
9
|
+
.then(r => compute(r[0], r[1], r[2], r[3]))
|
|
10
10
|
.then(generate)
|
|
11
11
|
})();
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@janekolszak/poland",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Administrative division of Poland",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
-
"generate": "tsc && node ./dist/index.js -o ./generated -i ./TERC_Urzedowy_2023-02-12.csv -l ./SIMC_Urzedowy_2023-02-12.csv -t ./WMRODZ_2023-02-12.csv"
|
|
7
|
+
"generate": "tsc && node ./dist/index.js -o ./generated -i ./TERC_Urzedowy_2023-02-12.csv -l ./SIMC_Urzedowy_2023-02-12.csv -t ./WMRODZ_2023-02-12.csv -s ./ULIC_Adresowy_2023-02-19.csv"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
package/src/args.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { parse } from 'ts-command-line-args';
|
|
|
3
3
|
export interface Args {
|
|
4
4
|
input: string;
|
|
5
5
|
localities: string;
|
|
6
|
+
streets: string;
|
|
6
7
|
types: string;
|
|
7
8
|
output: string;
|
|
8
9
|
help?: boolean;
|
|
@@ -12,6 +13,7 @@ export const args = parse<Args>(
|
|
|
12
13
|
{
|
|
13
14
|
input: { type: String, alias: 'i', description: 'Input TERC CSV as downloaded from https://eteryt.stat.gov.pl/eTeryt/rejestr_teryt/udostepnianie_danych/baza_teryt/uzytkownicy_indywidualni/pobieranie/pliki_pelne.aspx' },
|
|
14
15
|
localities: { type: String, alias: 'l', description: 'Input SIMC CSV as downloaded from https://eteryt.stat.gov.pl/eTeryt/rejestr_teryt/udostepnianie_danych/baza_teryt/uzytkownicy_indywidualni/pobieranie/pliki_pelne.aspx' },
|
|
16
|
+
streets: { type: String, alias: 's', description: 'Input ULIC CSV as downloaded from https://eteryt.stat.gov.pl/eTeryt/rejestr_teryt/udostepnianie_danych/baza_teryt/uzytkownicy_indywidualni/pobieranie/pliki_pelne.aspx' },
|
|
15
17
|
types: { type: String, alias: 't', description: 'Input WMRODZ CSV as downloaded from https://eteryt.stat.gov.pl/eTeryt/rejestr_teryt/udostepnianie_danych/baza_teryt/uzytkownicy_indywidualni/pobieranie/pliki_pelne.aspx' },
|
|
16
18
|
output: { type: String, alias: 'o', description: 'Output file path' },
|
|
17
19
|
help: { type: Boolean, optional: true, alias: 'h', description: 'Prints this usage guide' },
|
package/src/compute.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LocalityType, Region, Locality } from "./csvparse"
|
|
1
|
+
import { LocalityType, Region, Locality, Street } from "./csvparse"
|
|
2
2
|
import { MultiKeyMap } from "./map"
|
|
3
3
|
|
|
4
4
|
export interface NamesMap {
|
|
@@ -12,25 +12,43 @@ export interface NamesMapTwoKeys {
|
|
|
12
12
|
export interface NamesMapThreeKeys {
|
|
13
13
|
[postcode: string]: NamesMapTwoKeys
|
|
14
14
|
};
|
|
15
|
+
|
|
15
16
|
export interface NamesMapFourKeys {
|
|
16
17
|
[postcode: string]: NamesMapThreeKeys
|
|
17
18
|
};
|
|
18
19
|
|
|
20
|
+
export interface NamesMapFiveKeys {
|
|
21
|
+
[postcode: string]: NamesMapFourKeys
|
|
22
|
+
};
|
|
23
|
+
|
|
19
24
|
export interface Computed {
|
|
20
25
|
voivodeships: string[]
|
|
21
26
|
counties: NamesMap
|
|
22
27
|
municipalities: MultiKeyMap
|
|
23
28
|
localities: MultiKeyMap
|
|
24
29
|
districts: MultiKeyMap
|
|
30
|
+
streetsLocalities: MultiKeyMap
|
|
31
|
+
streetsDistricts: MultiKeyMap
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
// RODZ_GMI
|
|
35
|
+
// 1 - gmina miejska,
|
|
36
|
+
// 2 - gmina wiejska,
|
|
37
|
+
// 3 - gmina miejsko-wiejska,
|
|
38
|
+
// 4 - miasto w gminie miejsko-wiejskiej,
|
|
39
|
+
// 5 - obszar wiejski w gminie miejsko-wiejskiej,
|
|
40
|
+
// 8 - dzielnica w m.st. Warszawa,
|
|
41
|
+
// 9 - delegatury miast: Kraków, Łódź, Poznań i Wrocław
|
|
42
|
+
|
|
43
|
+
export function compute(regions: Array<Region>, localities: Array<Locality>, localityTypes: Array<LocalityType>, streets: Array<Street>): Computed {
|
|
28
44
|
let out: Computed = {
|
|
29
45
|
voivodeships: [],
|
|
30
46
|
counties: {},
|
|
31
47
|
municipalities: new MultiKeyMap(),
|
|
32
48
|
localities: new MultiKeyMap(),
|
|
33
|
-
districts: new MultiKeyMap()
|
|
49
|
+
districts: new MultiKeyMap(),
|
|
50
|
+
streetsLocalities: new MultiKeyMap(),
|
|
51
|
+
streetsDistricts: new MultiKeyMap()
|
|
34
52
|
}
|
|
35
53
|
|
|
36
54
|
const locTypeIdMap: Map<string, string> = new Map(localityTypes.map(r => [r.name, r.id]))
|
|
@@ -72,8 +90,6 @@ export function compute(regions: Array<Region>, localities: Array<Locality>, loc
|
|
|
72
90
|
municipalityIdMap.set([r.voivodeship, r.county, r.municipality], r.name)
|
|
73
91
|
})
|
|
74
92
|
|
|
75
|
-
console.log(out.municipalities.Get2Deep())
|
|
76
|
-
|
|
77
93
|
// Miejscowosci
|
|
78
94
|
let localityTypeIds = [
|
|
79
95
|
locTypeIdMap.get("wieś"),
|
|
@@ -104,7 +120,7 @@ export function compute(regions: Array<Region>, localities: Array<Locality>, loc
|
|
|
104
120
|
})
|
|
105
121
|
|
|
106
122
|
// Dzielnice
|
|
107
|
-
const allLocalitiesIdMap = new Map(localities.map(r => [r.localityId, r
|
|
123
|
+
const allLocalitiesIdMap = new Map(localities.map(r => [r.localityId, r]))
|
|
108
124
|
|
|
109
125
|
let districtIds = [
|
|
110
126
|
locTypeIdMap.get("dzielnica"),
|
|
@@ -121,7 +137,7 @@ export function compute(regions: Array<Region>, localities: Array<Locality>, loc
|
|
|
121
137
|
const v = vivIdMap.get(r.voivodeship)
|
|
122
138
|
const c = countyIdMap.get([r.voivodeship, r.county])
|
|
123
139
|
const m = municipalityIdMap.get([r.voivodeship, r.county, r.municipality])
|
|
124
|
-
const l = allLocalitiesIdMap.get(r.baseLocalityId)
|
|
140
|
+
const l = allLocalitiesIdMap.get(r.baseLocalityId)?.name
|
|
125
141
|
|
|
126
142
|
if (!v || !c || !m || !l) {
|
|
127
143
|
// console.error("Missing voivodeship, county, municipality or base locality for district: " + r.name + " (" + v + ", " + c + ", " + m + ", " + l + ")")
|
|
@@ -179,12 +195,105 @@ export function compute(regions: Array<Region>, localities: Array<Locality>, loc
|
|
|
179
195
|
d = d ? d : []
|
|
180
196
|
out.districts.set([v, c, m, l], [...d, name])
|
|
181
197
|
})
|
|
182
|
-
// console.log(out.districts)
|
|
183
198
|
|
|
199
|
+
// Ulice w miejscowosciach
|
|
200
|
+
let districtMunicipalityIds = ["8", "9"]
|
|
201
|
+
streets
|
|
202
|
+
.filter(r => !districtMunicipalityIds.includes(r.municipalityTypeId))
|
|
203
|
+
.forEach(r => {
|
|
204
|
+
const v = vivIdMap.get(r.voivodeship)
|
|
205
|
+
const c = countyIdMap.get([r.voivodeship, r.county])
|
|
206
|
+
const m = municipalityIdMap.get([r.voivodeship, r.county, r.municipality])
|
|
207
|
+
const l = allLocalitiesIdMap.get(r.localityId)
|
|
208
|
+
|
|
209
|
+
if (!v || !c || !m || !l) {
|
|
210
|
+
console.error("4 Missing voivodeship, county, municipality or base locality for district: " + r.name + " (" + v + ", " + c + ", " + m + ", " + l + ")")
|
|
211
|
+
console.error(r.voivodeship, r.county, r.municipality)
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const fullName = r.name + " " + r.restName
|
|
216
|
+
|
|
217
|
+
if (districtIds.includes(l.localityTypeId)) {
|
|
218
|
+
const d = out.districts.get([v, c, m, l.name])
|
|
219
|
+
if (!d) {
|
|
220
|
+
console.error("Missing district: " + r.name)
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let s = out.streetsDistricts.get([v, c, m, l.name, d])
|
|
225
|
+
s = s ? s : []
|
|
226
|
+
if (!s.includes(fullName)) {
|
|
227
|
+
out.streetsDistricts.set([v, c, m, l.name, d], [...s, fullName])
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
let s = out.streetsLocalities.get([v, c, m, l.name])
|
|
231
|
+
s = s ? s : []
|
|
232
|
+
if (!s.includes(fullName)) {
|
|
233
|
+
out.streetsLocalities.set([v, c, m, l.name], [...s, fullName])
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
// Ulice w dzielnicach Warszawy
|
|
239
|
+
streets
|
|
240
|
+
.filter(r => r.municipalityTypeId === "8")
|
|
241
|
+
.forEach(r => {
|
|
242
|
+
const v = vivIdMap.get(r.voivodeship)
|
|
243
|
+
const c = countyIdMap.get([r.voivodeship, r.county])
|
|
244
|
+
const m = "Warszawa"
|
|
245
|
+
const l = "Warszawa"
|
|
246
|
+
const d = allLocalitiesIdMap.get(r.localityId)?.name
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
if (!v || !c || !m || !l || !d) {
|
|
250
|
+
console.error("4 Missing voivodeship, county, municipality or base locality for district: " + r.name + " (" + v + ", " + c + ", " + m + ", " + l + ")")
|
|
251
|
+
console.error(r.voivodeship, r.county, r.municipality)
|
|
252
|
+
return
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
let s = out.streetsDistricts.get([v, c, m, l, d])
|
|
256
|
+
s = s ? s : []
|
|
257
|
+
const fullName = r.name + " " + r.restName
|
|
258
|
+
|
|
259
|
+
if (!s.includes(fullName)) {
|
|
260
|
+
out.streetsDistricts.set([v, c, m, l, d], [...s, fullName])
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
// Ulice w delegaturach miast
|
|
265
|
+
streets
|
|
266
|
+
.filter(r => r.municipalityTypeId === "9")
|
|
267
|
+
.forEach(r => {
|
|
268
|
+
const v = vivIdMap.get(r.voivodeship)
|
|
269
|
+
const c = countyIdMap.get([r.voivodeship, r.county])
|
|
270
|
+
|
|
271
|
+
const name = allLocalitiesIdMap.get(r.localityId)?.name
|
|
272
|
+
const d = name?.substring(name.indexOf('-') + 1)
|
|
273
|
+
const m = name?.substring(0, name?.indexOf('-'))
|
|
274
|
+
const l = name?.substring(0, name?.indexOf('-'))
|
|
275
|
+
|
|
276
|
+
if (!v || !c || !m || !l || !d) {
|
|
277
|
+
console.error("4 Missing voivodeship, county, municipality or base locality for district: " + r.name + " (" + v + ", " + c + ", " + m + ", " + l + ")")
|
|
278
|
+
console.error(r.voivodeship, r.county, r.municipality)
|
|
279
|
+
return
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
let s = out.streetsDistricts.get([v, c, m, l, d])
|
|
283
|
+
s = s ? s : []
|
|
284
|
+
const fullName = r.name + " " + r.restName
|
|
285
|
+
if (!s.includes(fullName)) {
|
|
286
|
+
out.streetsDistricts.set([v, c, m, l, d], [...s, fullName])
|
|
287
|
+
}
|
|
288
|
+
})
|
|
184
289
|
|
|
290
|
+
// Sort all lists
|
|
185
291
|
out.municipalities.sortValues()
|
|
186
292
|
out.localities.sortValues()
|
|
187
293
|
out.districts.sortValues()
|
|
294
|
+
out.streetsLocalities.sortValues()
|
|
295
|
+
out.streetsDistricts.sortValues()
|
|
296
|
+
|
|
188
297
|
|
|
189
298
|
return out
|
|
190
299
|
}
|
package/src/csvparse.ts
CHANGED
|
@@ -28,6 +28,20 @@ export type Locality = {
|
|
|
28
28
|
date: string;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
// WOJ;POW;GMI;RODZ_GMI;SYM;SYM_UL;CECHA;NAZWA_1;NAZWA_2;STAN_NA
|
|
32
|
+
export type Street = {
|
|
33
|
+
voivodeship: string
|
|
34
|
+
county: string;
|
|
35
|
+
municipality: string;
|
|
36
|
+
municipalityTypeId: string;
|
|
37
|
+
localityId: string;
|
|
38
|
+
streenId: string;
|
|
39
|
+
characteristic: string;
|
|
40
|
+
name: string;
|
|
41
|
+
restName: string
|
|
42
|
+
date: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
31
45
|
export type LocalityType = {
|
|
32
46
|
id: string;
|
|
33
47
|
name: string;
|
|
@@ -111,4 +125,28 @@ export async function parseLocalityTypeCsv() {
|
|
|
111
125
|
});
|
|
112
126
|
await finished(parser);
|
|
113
127
|
return records;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export async function parseStreetsCsv() {
|
|
131
|
+
const records: Street[] = [];
|
|
132
|
+
const parser = fs
|
|
133
|
+
.createReadStream(args.streets)
|
|
134
|
+
.pipe(parse({
|
|
135
|
+
relax_quotes: true,
|
|
136
|
+
delimiter: ';',
|
|
137
|
+
skip_empty_lines: true,
|
|
138
|
+
record_delimiter: '\r\n',
|
|
139
|
+
columns: () => {
|
|
140
|
+
return ["voivodeship", "county", "municipality", "municipalityTypeId", "localityId", "streenId", "characteristic", "name", "restName", "date"]
|
|
141
|
+
},
|
|
142
|
+
}))
|
|
143
|
+
.on('readable', function () {
|
|
144
|
+
let record; while ((record = parser.read()) !== null) {
|
|
145
|
+
// Work with each record
|
|
146
|
+
// record.name = toTitleCase(record.name)
|
|
147
|
+
records.push(record);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
await finished(parser);
|
|
151
|
+
return records;
|
|
114
152
|
};
|
package/src/generate.ts
CHANGED
|
@@ -8,6 +8,8 @@ function genJson(c: Computed) {
|
|
|
8
8
|
fs.writeFileSync(args.output + "/json/municipalities.json", JSON.stringify(c.municipalities.Get2Deep()))
|
|
9
9
|
fs.writeFileSync(args.output + "/json/localities.json", JSON.stringify(c.localities.Get3Deep()))
|
|
10
10
|
fs.writeFileSync(args.output + "/json/districts.json", JSON.stringify(c.districts.Get4Deep()))
|
|
11
|
+
fs.writeFileSync(args.output + "/json/streetsInLocalities.json", JSON.stringify(c.streetsLocalities.Get4Deep()))
|
|
12
|
+
fs.writeFileSync(args.output + "/json/streetsInDistricts.json", JSON.stringify(c.streetsDistricts.Get5Deep()))
|
|
11
13
|
|
|
12
14
|
}
|
|
13
15
|
|
|
@@ -17,6 +19,8 @@ function genGo(c: Computed) {
|
|
|
17
19
|
fs.copyFileSync(args.output + "/json/municipalities.json", args.output + "/go/municipalities.json")
|
|
18
20
|
fs.copyFileSync(args.output + "/json/localities.json", args.output + "/go/localities.json")
|
|
19
21
|
fs.copyFileSync(args.output + "/json/districts.json", args.output + "/go/districts.json")
|
|
22
|
+
fs.copyFileSync(args.output + "/json/streetsInLocalities.json", args.output + "/go/streetsInLocalities.json")
|
|
23
|
+
fs.copyFileSync(args.output + "/json/streetsInDistricts.json", args.output + "/go/streetsInDistricts.json")
|
|
20
24
|
const data = `package poland
|
|
21
25
|
import (
|
|
22
26
|
"embed"
|
package/src/map.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NamesMapThreeKeys, NamesMapFourKeys, NamesMapTwoKeys } from "./compute";
|
|
1
|
+
import { NamesMapThreeKeys, NamesMapFourKeys, NamesMapTwoKeys, NamesMapFiveKeys } from "./compute";
|
|
2
2
|
|
|
3
3
|
export class MultiKeyMap {
|
|
4
4
|
private map: Record<string, any> = {};
|
|
@@ -100,4 +100,25 @@ export class MultiKeyMap {
|
|
|
100
100
|
})
|
|
101
101
|
return out
|
|
102
102
|
}
|
|
103
|
+
|
|
104
|
+
Get5Deep(): NamesMapFiveKeys {
|
|
105
|
+
var out: NamesMapFiveKeys = {}
|
|
106
|
+
this.forEach((keys, value) => {
|
|
107
|
+
const [v, c, m, l, d] = keys
|
|
108
|
+
if (!out[v]) {
|
|
109
|
+
out[v] = {}
|
|
110
|
+
}
|
|
111
|
+
if (!out[v][c]) {
|
|
112
|
+
out[v][c] = {}
|
|
113
|
+
}
|
|
114
|
+
if (!out[v][c][m]) {
|
|
115
|
+
out[v][c][m] = {}
|
|
116
|
+
}
|
|
117
|
+
if (!out[v][c][m][l]) {
|
|
118
|
+
out[v][c][m][l] = {}
|
|
119
|
+
}
|
|
120
|
+
out[v][c][m][l][d] = value
|
|
121
|
+
})
|
|
122
|
+
return out
|
|
123
|
+
}
|
|
103
124
|
}
|