text-to-map 1.0.2 → 1.0.4
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/dist/address_points_init.db +0 -0
- package/dist/bin/address-points.js +2 -2
- package/dist/bin/regions.js +8 -0
- package/dist/bin/schools.js +2 -2
- package/dist/bin/streets.js +2 -2
- package/dist/db/address-points.d.ts +1 -0
- package/dist/db/address-points.js +28 -29
- package/dist/db/db.d.ts +3 -1
- package/dist/db/db.js +11 -4
- package/dist/db/founders.js +134 -26
- package/dist/db/meta.d.ts +2 -0
- package/dist/db/meta.js +10 -0
- package/dist/db/regions.d.ts +23 -0
- package/dist/db/regions.js +65 -0
- package/dist/db/schools.d.ts +1 -1
- package/dist/db/schools.js +24 -26
- package/dist/db/types.d.ts +6 -0
- package/dist/index.d.ts +20 -4
- package/dist/index.js +37 -4
- package/dist/open-data-sync/address-points.d.ts +1 -2
- package/dist/open-data-sync/address-points.js +1 -5
- package/dist/open-data-sync/regions.d.ts +2 -0
- package/dist/open-data-sync/regions.js +36 -0
- package/dist/open-data-sync/schools.d.ts +1 -1
- package/dist/open-data-sync/schools.js +20 -11
- package/dist/open-data-sync/streets.d.ts +1 -1
- package/dist/open-data-sync/streets.js +4 -3
- package/dist/street-markdown/types.d.ts +2 -14
- package/dist/street-markdown/types.js +0 -5
- package/dist/utils/helpers.d.ts +5 -0
- package/dist/utils/helpers.js +14 -3
- package/package.json +4 -2
- package/dist/bin/address-points-import-only.js +0 -14
- package/dist/utils/addressBuilder.d.ts +0 -8
- package/dist/utils/addressBuilder.js +0 -101
- /package/dist/bin/{address-points-import-only.d.ts → regions.d.ts} +0 -0
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { downloadAndImportAddressPoints } from "../open-data-sync/address-points";
|
|
2
2
|
console.time("downloadAndImportAllLatestAddressPoints");
|
|
3
|
-
|
|
3
|
+
downloadAndImportAddressPoints()
|
|
4
4
|
.then(() => {
|
|
5
5
|
console.timeEnd("downloadAndImportAllLatestAddressPoints");
|
|
6
6
|
})
|
package/dist/bin/schools.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { downloadAndImportSchools } from "../open-data-sync/schools";
|
|
2
|
+
downloadAndImportSchools({ tmpDir: "tmp" })
|
|
3
3
|
.then(() => {
|
|
4
4
|
console.log("Completed");
|
|
5
5
|
})
|
package/dist/bin/streets.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { downloadAndImportStreets } from "../open-data-sync/streets";
|
|
2
2
|
console.time("downloadAndImportAllStreets");
|
|
3
|
-
|
|
3
|
+
downloadAndImportStreets({})
|
|
4
4
|
.then(() => {
|
|
5
5
|
console.timeEnd("downloadAndImportAllStreets");
|
|
6
6
|
})
|
|
@@ -26,6 +26,7 @@ export declare const commitAddressPoints: () => number;
|
|
|
26
26
|
export declare const insertCities: (buffer: string[][]) => number;
|
|
27
27
|
export declare const insertDistricts: (buffer: string[][]) => number;
|
|
28
28
|
export declare const insertMunicipalityParts: (buffer: string[][]) => number;
|
|
29
|
+
export declare const insertPragueDistricts: (buffer: string[][]) => number;
|
|
29
30
|
export declare const insertStreets: (buffer: string[][]) => number;
|
|
30
31
|
export declare const getAddressPointById: (addressPointId: number) => AddressPoint | null;
|
|
31
32
|
export declare const checkStreetExists: (streetName: string, founder: Founder) => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { extractKeyValuesPairs, getDb, insertMultipleRows, nonEmptyOrNull, } from "./db";
|
|
2
1
|
import jtsk2wgs84 from "@arodax/jtsk2wgs84";
|
|
3
|
-
import { AddressPointType,
|
|
4
|
-
import {
|
|
2
|
+
import { AddressPointType, createSingleLineAddress } from "czech-address";
|
|
3
|
+
import { SeriesType, isNegativeSeriesSpec, isRange, isSeriesSpecArray, isWholeMunicipalitySmdLine, } from "../street-markdown/types";
|
|
5
4
|
import { findClosestString } from "../utils/helpers";
|
|
5
|
+
import { extractKeyValuesPairs, generate2DPlaceholders, getDb, insertMultipleRows, nonEmptyOrNull, } from "./db";
|
|
6
6
|
import { getFounderCityCode } from "./founders";
|
|
7
|
-
import {
|
|
7
|
+
import { MunicipalityType } from "./types";
|
|
8
8
|
const buffer = [];
|
|
9
9
|
const MaxBufferSize = 1000;
|
|
10
10
|
const DescriptiveType = "č.p.";
|
|
@@ -49,12 +49,11 @@ export const commitAddressPoints = () => {
|
|
|
49
49
|
insertDistricts(buffer);
|
|
50
50
|
insertMunicipalityParts(buffer);
|
|
51
51
|
insertStreets(buffer);
|
|
52
|
+
insertPragueDistricts(buffer);
|
|
52
53
|
const db = getDb();
|
|
53
|
-
const placeHolders =
|
|
54
|
-
.fill("(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
|
55
|
-
.join(", ");
|
|
54
|
+
const placeHolders = generate2DPlaceholders(15, buffer.length);
|
|
56
55
|
const insertStatement = db.prepare(`INSERT OR IGNORE INTO address_point
|
|
57
|
-
(id, street_code, object_type_id, descriptive_number, orientational_number, orientational_number_letter, city_code, city_district_code, municipality_part_code, postal_code, jtsk_x, jtsk_y, wgs84_latitude, wgs84_longitude)
|
|
56
|
+
(id, street_code, object_type_id, descriptive_number, orientational_number, orientational_number_letter, city_code, city_district_code, municipality_part_code, prague_district_code, postal_code, jtsk_x, jtsk_y, wgs84_latitude, wgs84_longitude)
|
|
58
57
|
VALUES ${placeHolders}`);
|
|
59
58
|
const params = [];
|
|
60
59
|
buffer.forEach((data) => {
|
|
@@ -65,7 +64,7 @@ export const commitAddressPoints = () => {
|
|
|
65
64
|
const { lat, lon } = jtsk2wgs84(parseFloat(data[Column.xCoordinate]), parseFloat(data[Column.yCoordinate]));
|
|
66
65
|
[latOrNull, lonOrNull] = [lat.toString(), lon.toString()];
|
|
67
66
|
}
|
|
68
|
-
params.push(data[Column.admCode], nonEmptyOrNull(data[Column.streetCode]), ObjectTypes[data[Column.objectType]], nonEmptyOrNull(data[Column.houseNumber]), nonEmptyOrNull(data[Column.orientationalNumber]), nonEmptyOrNull(data[Column.orientationalNumberLetter]), data[Column.cityCode], nonEmptyOrNull(data[Column.districtCode]), nonEmptyOrNull(data[Column.municipalityPartCode]), data[Column.postalCode], nonEmptyOrNull(data[Column.xCoordinate]), nonEmptyOrNull(data[Column.yCoordinate]), latOrNull, lonOrNull);
|
|
67
|
+
params.push(data[Column.admCode], nonEmptyOrNull(data[Column.streetCode]), ObjectTypes[data[Column.objectType]], nonEmptyOrNull(data[Column.houseNumber]), nonEmptyOrNull(data[Column.orientationalNumber]), nonEmptyOrNull(data[Column.orientationalNumberLetter]), data[Column.cityCode], nonEmptyOrNull(data[Column.districtCode]), nonEmptyOrNull(data[Column.municipalityPartCode]), nonEmptyOrNull(data[Column.pragueDistrictCode]), data[Column.postalCode], nonEmptyOrNull(data[Column.xCoordinate]), nonEmptyOrNull(data[Column.yCoordinate]), latOrNull, lonOrNull);
|
|
69
68
|
});
|
|
70
69
|
buffer.length = 0;
|
|
71
70
|
return insertStatement.run(params).changes;
|
|
@@ -84,6 +83,11 @@ export const insertMunicipalityParts = (buffer) => {
|
|
|
84
83
|
Column.municipalityPartName,
|
|
85
84
|
]), "municipality_part", ["code", "name"]);
|
|
86
85
|
};
|
|
86
|
+
export const insertPragueDistricts = (buffer) => {
|
|
87
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, Column.pragueDistrictCode, [
|
|
88
|
+
Column.pragueDistrictName,
|
|
89
|
+
]), "prague_district", ["code", "name"]);
|
|
90
|
+
};
|
|
87
91
|
export const insertStreets = (buffer) => {
|
|
88
92
|
return insertMultipleRows(extractKeyValuesPairs(buffer, Column.streetCode, [
|
|
89
93
|
Column.cityCode,
|
|
@@ -93,13 +97,14 @@ export const insertStreets = (buffer) => {
|
|
|
93
97
|
const addressPointSelect = `
|
|
94
98
|
SELECT a.id, s.name AS street_name, o.name AS object_type_name, a.descriptive_number,
|
|
95
99
|
a.orientational_number, a.orientational_number_letter, c.name AS city_name,
|
|
96
|
-
m.name AS municipality_part_name,
|
|
97
|
-
a.wgs84_latitude, a.wgs84_longitude
|
|
100
|
+
m.name AS municipality_part_name, p.name AS prague_district_name,
|
|
101
|
+
d.name AS district_name, a.postal_code, a.wgs84_latitude, a.wgs84_longitude
|
|
98
102
|
FROM address_point a
|
|
99
103
|
LEFT JOIN street s ON a.street_code = s.code
|
|
100
104
|
INNER JOIN object_type o ON o.id = a.object_type_id
|
|
101
105
|
INNER JOIN city c ON c.code = a.city_code
|
|
102
106
|
LEFT JOIN city_district d ON a.city_district_code = d.code
|
|
107
|
+
LEFT JOIN prague_district p ON a.prague_district_code = p.code
|
|
103
108
|
LEFT JOIN municipality_part m ON a.municipality_part_code = m.code`;
|
|
104
109
|
export const getAddressPointById = (addressPointId) => {
|
|
105
110
|
const db = getDb();
|
|
@@ -168,15 +173,16 @@ export const findAddressPoints = (smdLine, municipality) => {
|
|
|
168
173
|
: "JOIN street s ON a.street_code = s.code AND s.name = ? COLLATE NOCASE";
|
|
169
174
|
const statement = db.prepare(`
|
|
170
175
|
SELECT a.id, s.name AS street_name, o.name AS object_type_name, a.descriptive_number,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
176
|
+
a.orientational_number, a.orientational_number_letter, c.name AS city_name,
|
|
177
|
+
d.name AS district_name, m.name AS municipality_part_name, p.name AS prague_district_name,
|
|
178
|
+
a.postal_code, a.wgs84_latitude, a.wgs84_longitude
|
|
174
179
|
FROM address_point a
|
|
175
180
|
${streetJoinCondition}
|
|
176
181
|
INNER JOIN object_type o ON o.id = a.object_type_id
|
|
177
182
|
INNER JOIN city c ON c.code = a.city_code
|
|
178
183
|
LEFT JOIN city_district d ON a.city_district_code = d.code
|
|
179
184
|
LEFT JOIN municipality_part m ON a.municipality_part_code = m.code
|
|
185
|
+
LEFT JOIN prague_district p ON a.prague_district_code = p.code
|
|
180
186
|
WHERE ${getMunicipalityWhere("a", municipality)}`);
|
|
181
187
|
const params = isWholeMunicipalitySmdLine(smdLine)
|
|
182
188
|
? [municipality.code]
|
|
@@ -252,8 +258,7 @@ export const fitsType = (number, type) => {
|
|
|
252
258
|
(type === SeriesType.Even && number % 2 === 0));
|
|
253
259
|
};
|
|
254
260
|
export const equalsFullStreetNumber = (fullStreetNumber, addressPoint) => {
|
|
255
|
-
return (fullStreetNumber.descriptiveNumber.number ===
|
|
256
|
-
addressPoint.descriptiveNumber &&
|
|
261
|
+
return (fullStreetNumber.descriptiveNumber.number === addressPoint.houseNumber &&
|
|
257
262
|
fullStreetNumber.orientationalNumber.number ===
|
|
258
263
|
addressPoint.orientationalNumber &&
|
|
259
264
|
((!fullStreetNumber.orientationalNumber.letter &&
|
|
@@ -264,7 +269,7 @@ export const equalsFullStreetNumber = (fullStreetNumber, addressPoint) => {
|
|
|
264
269
|
const getNumberByType = (type, addressPoint) => {
|
|
265
270
|
var _a;
|
|
266
271
|
return type === SeriesType.Descriptive
|
|
267
|
-
? addressPoint.
|
|
272
|
+
? addressPoint.houseNumber
|
|
268
273
|
: (_a = addressPoint.orientationalNumber) !== null && _a !== void 0 ? _a : null;
|
|
269
274
|
};
|
|
270
275
|
const getMunicipalityWhere = (alias, municipality) => {
|
|
@@ -272,22 +277,16 @@ const getMunicipalityWhere = (alias, municipality) => {
|
|
|
272
277
|
? `${alias}.city_code = ?`
|
|
273
278
|
: `${alias}.city_district_code = ?`;
|
|
274
279
|
};
|
|
275
|
-
const createAddress = (result) => {
|
|
276
|
-
var _a;
|
|
277
|
-
const orientationalPart = result.orientational_number
|
|
278
|
-
? `/${result.orientational_number}${(_a = result.orientational_number_letter) !== null && _a !== void 0 ? _a : ""}`
|
|
279
|
-
: "";
|
|
280
|
-
return `${result.street_name} ${result.descriptive_number}${orientationalPart}, ${result.city_name}`;
|
|
281
|
-
};
|
|
282
280
|
const rowToAddressPoint = (row) => {
|
|
283
281
|
const point = {
|
|
284
282
|
id: row.id,
|
|
285
283
|
address: "",
|
|
286
284
|
type: row.object_type_name === DescriptiveType
|
|
287
|
-
? AddressPointType.
|
|
285
|
+
? AddressPointType.Description
|
|
288
286
|
: AddressPointType.Registration,
|
|
289
|
-
|
|
287
|
+
houseNumber: row.descriptive_number,
|
|
290
288
|
city: row.city_name,
|
|
289
|
+
municipalityPart: row.municipality_part_name,
|
|
291
290
|
postalCode: row.postal_code,
|
|
292
291
|
lat: row.wgs84_latitude,
|
|
293
292
|
lng: row.wgs84_longitude,
|
|
@@ -304,9 +303,9 @@ const rowToAddressPoint = (row) => {
|
|
|
304
303
|
if (row.district_name !== null) {
|
|
305
304
|
point.district = row.district_name;
|
|
306
305
|
}
|
|
307
|
-
if (row.
|
|
308
|
-
point.
|
|
306
|
+
if (row.prague_district !== null) {
|
|
307
|
+
point.pragueDistrict = row.prague_district_name;
|
|
309
308
|
}
|
|
310
|
-
point.address =
|
|
309
|
+
point.address = createSingleLineAddress(point);
|
|
311
310
|
return point;
|
|
312
311
|
};
|
package/dist/db/db.d.ts
CHANGED
|
@@ -15,9 +15,11 @@ export declare const insertMultipleRows: (rows: string[][], table: string, colum
|
|
|
15
15
|
/**
|
|
16
16
|
* Insert a single row and return the autoincremented ID.
|
|
17
17
|
*/
|
|
18
|
-
export declare const insertAutoincrementRow: (row: string[], table: string, columnNames: string[]) => number;
|
|
18
|
+
export declare const insertAutoincrementRow: (row: string[], table: string, columnNames: string[]) => number | null;
|
|
19
19
|
export declare const deleteMultipleRows: (keys: string[], table: string, keyColumnName: string) => void;
|
|
20
20
|
export declare const clearDuplicates: (rows: string[][], table: string, columnNames: string[]) => string[][];
|
|
21
21
|
export declare const disconnect: () => void;
|
|
22
|
+
export declare const generatePlaceholders: (n: number) => string;
|
|
23
|
+
export declare const generate2DPlaceholders: (inner: number, outer: number) => string;
|
|
22
24
|
export declare const extractKeyValuesPairs: (array: string[][], keyIndex: number, valuesIndices: number[]) => string[][];
|
|
23
25
|
export {};
|
package/dist/db/db.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import Database from "better-sqlite3";
|
|
2
2
|
import { existsSync, copyFileSync } from "fs";
|
|
3
|
-
import { join } from "path";
|
|
3
|
+
import { dirname, join } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
4
5
|
let _db;
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = dirname(__filename);
|
|
5
8
|
const defaults = {
|
|
6
9
|
filePath: "address_points.db",
|
|
7
|
-
initFilePath: join("
|
|
10
|
+
initFilePath: join(__dirname, "..", "address_points_init.db"),
|
|
8
11
|
verbose: false,
|
|
9
12
|
};
|
|
10
13
|
export const setDbConfig = (config) => {
|
|
@@ -51,7 +54,8 @@ export const insertMultipleRows = (rows, table, columnNames, preventDuplicatesBy
|
|
|
51
54
|
export const insertAutoincrementRow = (row, table, columnNames) => {
|
|
52
55
|
const db = getDb();
|
|
53
56
|
const insertStatement = db.prepare(`INSERT INTO ${table} (${columnNames.join(",")}) VALUES (${generatePlaceholders(columnNames.length)})`);
|
|
54
|
-
|
|
57
|
+
const result = insertStatement.run(row);
|
|
58
|
+
return result.changes === 1 ? Number(result.lastInsertRowid) : null;
|
|
55
59
|
};
|
|
56
60
|
export const deleteMultipleRows = (keys, table, keyColumnName) => {
|
|
57
61
|
const db = getDb();
|
|
@@ -76,9 +80,12 @@ export const disconnect = () => {
|
|
|
76
80
|
const generateRepetitiveString = (value, glue, n) => {
|
|
77
81
|
return new Array(n).fill(value).join(glue);
|
|
78
82
|
};
|
|
79
|
-
const generatePlaceholders = (n) => {
|
|
83
|
+
export const generatePlaceholders = (n) => {
|
|
80
84
|
return generateRepetitiveString("?", ",", n);
|
|
81
85
|
};
|
|
86
|
+
export const generate2DPlaceholders = (inner, outer) => {
|
|
87
|
+
return generateRepetitiveString(`(${generatePlaceholders(inner)})`, ",", outer);
|
|
88
|
+
};
|
|
82
89
|
export const extractKeyValuesPairs = (array, keyIndex, valuesIndices) => {
|
|
83
90
|
const object = array.reduce((acc, data) => {
|
|
84
91
|
if (data[keyIndex]) {
|
package/dist/db/founders.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { MunicipalityType } from "./types";
|
|
2
|
-
import { getDb, insertAutoincrementRow, insertMultipleRows } from "./db";
|
|
3
|
-
import { extractMunicipalityName, findClosestString } from "../utils/helpers";
|
|
1
|
+
import { MunicipalityType, } from "./types";
|
|
2
|
+
import { generatePlaceholders, getDb, insertAutoincrementRow, insertMultipleRows, } from "./db";
|
|
3
|
+
import { extractMunicipalityName, findClosestString, sanitizeMunicipalityName, } from "../utils/helpers";
|
|
4
|
+
import distance from "@turf/distance";
|
|
4
5
|
const cityTypeCode = 261;
|
|
5
6
|
const cityDistrictTypeCode = 263;
|
|
6
7
|
export const insertFounders = (founders) => {
|
|
@@ -20,48 +21,53 @@ export const insertFounders = (founders) => {
|
|
|
20
21
|
let insertedFounders = 0;
|
|
21
22
|
const schoolFounderConnectionData = [];
|
|
22
23
|
founders.forEach((founder) => {
|
|
24
|
+
var _a;
|
|
23
25
|
if (founder.municipalityType !== MunicipalityType.City &&
|
|
24
26
|
founder.municipalityType !== MunicipalityType.District) {
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
|
-
const
|
|
29
|
+
const extractedMunicipalityName = extractMunicipalityName(founder);
|
|
28
30
|
// check if the extracted municipality name is the same as in all the schools' locations
|
|
29
|
-
let
|
|
30
|
-
let municipalityCode =
|
|
31
|
+
let differingSchools = [];
|
|
32
|
+
let municipalityCode = -1;
|
|
31
33
|
founder.schools.forEach((school) => {
|
|
32
34
|
const result = (founder.municipalityType === MunicipalityType.City
|
|
33
35
|
? selectCityStatement
|
|
34
36
|
: selectDistrictStatement).get(school.izo);
|
|
35
37
|
if (!result) {
|
|
36
|
-
console.log(`izo: ${school.izo}, extracted: ${
|
|
37
|
-
|
|
38
|
+
console.log(`izo: ${school.izo}, extracted: ${extractedMunicipalityName}, RUIAN: UNDEFINED`);
|
|
39
|
+
differingSchools.push(school);
|
|
38
40
|
}
|
|
39
41
|
else {
|
|
40
42
|
const { name, code } = result;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
allEqual = false;
|
|
43
|
+
if (name !== extractedMunicipalityName) {
|
|
44
|
+
console.log(`izo: ${school.izo}, extracted: ${extractedMunicipalityName}, RUIAN: ${name}`);
|
|
45
|
+
differingSchools.push(school);
|
|
45
46
|
}
|
|
47
|
+
// store municipalityCode even if the names don't match, we will use it later
|
|
48
|
+
municipalityCode = parseInt(code);
|
|
46
49
|
}
|
|
47
50
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
municipalityCode = fixFounderProblems(founder, municipalityCode, differingSchools, extractedMunicipalityName);
|
|
52
|
+
const cityDistrictCode = founder.municipalityType === MunicipalityType.District
|
|
53
|
+
? municipalityCode.toString()
|
|
54
|
+
: null;
|
|
55
|
+
let cityCode = null;
|
|
56
|
+
if (founder.municipalityType === MunicipalityType.City) {
|
|
57
|
+
cityCode = (_a = municipalityCode === null || municipalityCode === void 0 ? void 0 : municipalityCode.toString()) !== null && _a !== void 0 ? _a : null;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
cityCode = getCityCodeByDistrictCode(municipalityCode).toString();
|
|
53
61
|
}
|
|
54
62
|
const founderId = insertAutoincrementRow([
|
|
55
|
-
founder.name,
|
|
63
|
+
sanitizeMunicipalityName(founder.name),
|
|
56
64
|
founder.ico,
|
|
57
65
|
String(founder.originalType),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
: null,
|
|
61
|
-
founder.municipalityType === MunicipalityType.City
|
|
62
|
-
? null
|
|
63
|
-
: municipalityCode,
|
|
66
|
+
cityCode,
|
|
67
|
+
cityDistrictCode,
|
|
64
68
|
], "founder", ["name", "ico", "founder_type_code", "city_code", "city_district_code"]);
|
|
69
|
+
// founder table has unique (name, ico) with on conflict ignore, so possibly
|
|
70
|
+
// the row has not been inserted
|
|
65
71
|
if (founderId !== null) {
|
|
66
72
|
insertedFounders++;
|
|
67
73
|
founder.schools.forEach((school) => {
|
|
@@ -72,6 +78,105 @@ export const insertFounders = (founders) => {
|
|
|
72
78
|
const insertedConnections = insertMultipleRows(schoolFounderConnectionData, "school_founder", ["school_izo", "founder_id"]);
|
|
73
79
|
return insertedFounders + insertedConnections;
|
|
74
80
|
};
|
|
81
|
+
const fixFounderProblems = (founder, municipalityCode, differingSchools, extractedMunicipalityName) => {
|
|
82
|
+
if (differingSchools.length === 0 ||
|
|
83
|
+
differingSchools.length < founder.schools.length) {
|
|
84
|
+
return municipalityCode;
|
|
85
|
+
}
|
|
86
|
+
// either the school does not have a position (invalid RUIAN or missing building)
|
|
87
|
+
// or the school is not in the same municipality as the founder
|
|
88
|
+
const db = getDb();
|
|
89
|
+
// find all cities and their position with the same name as municipalityName
|
|
90
|
+
const municipalities = findMunicipalitiesAndPositionsByNameAndType(extractedMunicipalityName, founder.municipalityType);
|
|
91
|
+
// get one school position (if there are more schools, they should be close to each other)
|
|
92
|
+
const schoolPosition = db
|
|
93
|
+
.prepare(`SELECT a.wgs84_latitude, a.wgs84_longitude FROM school s
|
|
94
|
+
JOIN school_location l ON s.izo = l.school_izo
|
|
95
|
+
JOIN address_point a ON l.address_point_id = a.id
|
|
96
|
+
WHERE s.izo IN (${generatePlaceholders(differingSchools.length)})
|
|
97
|
+
LIMIT 1`)
|
|
98
|
+
.get(...differingSchools.map((school) => school.izo));
|
|
99
|
+
if (schoolPosition) {
|
|
100
|
+
if (municipalities.length === 0) {
|
|
101
|
+
if (municipalityCode === -1) {
|
|
102
|
+
console.log(`no municipality by name or by location found for ${founder.name}`);
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
console.log("no municipality matching the extracted name, using the municipality from RUIAN code");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else if (municipalities.length === 1) {
|
|
110
|
+
console.log("using the only municipality found matching the extracted name");
|
|
111
|
+
return municipalities[0].code;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// get code and position of the closest city
|
|
115
|
+
let lowestDistance = Number.MAX_SAFE_INTEGER;
|
|
116
|
+
let municipalityCode = null;
|
|
117
|
+
for (const municipality of municipalities) {
|
|
118
|
+
let municipalityDistance = distance([municipality.lat, municipality.lng], [schoolPosition.wgs84_latitude, schoolPosition.wgs84_longitude]);
|
|
119
|
+
if (municipalityDistance < lowestDistance) {
|
|
120
|
+
lowestDistance = municipalityDistance;
|
|
121
|
+
municipalityCode = municipality.code;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
console.log("using the closest municipality matching the extracted name");
|
|
125
|
+
return municipalityCode;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
if (municipalities.length > 0) {
|
|
130
|
+
if (municipalities.length > 1) {
|
|
131
|
+
console.log(`using the first municipality matching the extracted name (${municipalities.length} matches) - possibly incorrect!`);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
console.log("using the only municipality found matching the extracted name");
|
|
135
|
+
}
|
|
136
|
+
return municipalities[0].code;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
console.log(`no municipality by name or by location found for ${founder.name}`);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const getCityCodeByDistrictCode = (districtCode) => {
|
|
145
|
+
const db = getDb();
|
|
146
|
+
const result = db
|
|
147
|
+
.prepare(`SELECT c.code FROM city_district d
|
|
148
|
+
JOIN city c ON d.city_code = c.code
|
|
149
|
+
WHERE d.code = ?
|
|
150
|
+
LIMIT 1`)
|
|
151
|
+
.get(districtCode);
|
|
152
|
+
if (result) {
|
|
153
|
+
return result.code;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const findMunicipalitiesAndPositionsByNameAndType = (name, type) => {
|
|
160
|
+
const db = getDb();
|
|
161
|
+
return (type === MunicipalityType.City
|
|
162
|
+
? db
|
|
163
|
+
.prepare(`SELECT c.name, c.code, a.wgs84_latitude, a.wgs84_longitude FROM city c
|
|
164
|
+
JOIN address_point a ON c.code = a.city_code
|
|
165
|
+
WHERE c.name = ?
|
|
166
|
+
GROUP BY c.code`)
|
|
167
|
+
.all(name)
|
|
168
|
+
: db
|
|
169
|
+
.prepare(`SELECT d.name, d.code, a.wgs84_latitude, a.wgs84_longitude FROM city_district d
|
|
170
|
+
JOIN address_point a ON d.code = a.city_district_code
|
|
171
|
+
WHERE d.name = ?
|
|
172
|
+
GROUP BY d.code`)
|
|
173
|
+
.all(name)).map((row) => ({
|
|
174
|
+
code: row.code,
|
|
175
|
+
type,
|
|
176
|
+
lat: row.wgs84_latitude,
|
|
177
|
+
lng: row.wgs84_longitude,
|
|
178
|
+
}));
|
|
179
|
+
};
|
|
75
180
|
export const findFounder = (name) => {
|
|
76
181
|
const errors = [];
|
|
77
182
|
const db = getDb();
|
|
@@ -127,18 +232,21 @@ const resultToFounder = (result) => {
|
|
|
127
232
|
municipalityType: result.founder_type_code === cityTypeCode
|
|
128
233
|
? MunicipalityType.City
|
|
129
234
|
: MunicipalityType.District,
|
|
130
|
-
cityOrDistrictCode: result.
|
|
235
|
+
cityOrDistrictCode: result.founder_type_code === cityTypeCode
|
|
236
|
+
? result.city_code
|
|
237
|
+
: result.city_district_code,
|
|
131
238
|
schools: getSchoolsByFounderId(parseInt(result.id)),
|
|
132
239
|
};
|
|
133
240
|
};
|
|
134
241
|
const getSchoolsByFounderId = (founderId) => {
|
|
135
242
|
const db = getDb();
|
|
136
|
-
const statement = db.prepare(`SELECT s.izo, s.name, s.capacity, sl.address_point_id FROM school s
|
|
243
|
+
const statement = db.prepare(`SELECT s.izo, s.redizo, s.name, s.capacity, sl.address_point_id FROM school s
|
|
137
244
|
JOIN school_founder sf ON s.izo = sf.school_izo
|
|
138
245
|
JOIN school_location sl ON s.izo = sl.school_izo
|
|
139
246
|
WHERE sf.founder_id = ?`);
|
|
140
247
|
return statement.all(founderId).map((row) => ({
|
|
141
248
|
izo: String(row.izo),
|
|
249
|
+
redizo: String(row.redizo),
|
|
142
250
|
name: String(row.name),
|
|
143
251
|
capacity: parseInt(row.capacity),
|
|
144
252
|
locations: [
|
package/dist/db/meta.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
/// <reference types="better-sqlite3" />
|
|
2
2
|
export declare const getMetaValue: (key: string) => string | undefined;
|
|
3
3
|
export declare const setMetaValue: (key: string, value: any) => import("better-sqlite3").RunResult;
|
|
4
|
+
export declare const setCurrentDatetimeMetaValue: (key: string) => void;
|
|
5
|
+
export declare const getDatetimeMetaValue: (key: string) => Date | undefined;
|
package/dist/db/meta.js
CHANGED
|
@@ -15,3 +15,13 @@ export const setMetaValue = (key, value) => {
|
|
|
15
15
|
return statement.run(value.toString(), key);
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
+
export const setCurrentDatetimeMetaValue = (key) => {
|
|
19
|
+
setMetaValue(key, new Date().toISOString());
|
|
20
|
+
};
|
|
21
|
+
export const getDatetimeMetaValue = (key) => {
|
|
22
|
+
const value = getMetaValue(key);
|
|
23
|
+
if (value === undefined) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return new Date(value);
|
|
27
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const Column: {
|
|
2
|
+
cityName: number;
|
|
3
|
+
cityCode: number;
|
|
4
|
+
cityType: number;
|
|
5
|
+
orpName: number;
|
|
6
|
+
orpCsuCode65: number;
|
|
7
|
+
orpRuianCode: number;
|
|
8
|
+
orpCityCode: number;
|
|
9
|
+
countyName: number;
|
|
10
|
+
countyCsuCode101Lau: number;
|
|
11
|
+
countyCsuCode109Nuts: number;
|
|
12
|
+
countyRuianCode: number;
|
|
13
|
+
regionName: number;
|
|
14
|
+
regionShortName: number;
|
|
15
|
+
regionCsuCode100: number;
|
|
16
|
+
regionCsuCode108Nuts: number;
|
|
17
|
+
regionRuianCode: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const insertRegionsAndOrps: (data: string[][]) => number;
|
|
20
|
+
export declare const insertRegions: (buffer: string[][]) => number;
|
|
21
|
+
export declare const insertCounties: (buffer: string[][]) => number;
|
|
22
|
+
export declare const insertOrps: (buffer: string[][]) => number;
|
|
23
|
+
export declare const insertCities: (buffer: string[][]) => number;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { extractKeyValuesPairs, getDb, insertMultipleRows } from "./db";
|
|
2
|
+
export const Column = {
|
|
3
|
+
cityName: 0,
|
|
4
|
+
cityCode: 1,
|
|
5
|
+
cityType: 2,
|
|
6
|
+
orpName: 9,
|
|
7
|
+
orpCsuCode65: 10,
|
|
8
|
+
orpRuianCode: 11,
|
|
9
|
+
orpCityCode: 12,
|
|
10
|
+
countyName: 13,
|
|
11
|
+
countyCsuCode101Lau: 14,
|
|
12
|
+
countyCsuCode109Nuts: 15,
|
|
13
|
+
countyRuianCode: 16,
|
|
14
|
+
regionName: 17,
|
|
15
|
+
regionShortName: 18,
|
|
16
|
+
regionCsuCode100: 19,
|
|
17
|
+
regionCsuCode108Nuts: 20,
|
|
18
|
+
regionRuianCode: 21,
|
|
19
|
+
};
|
|
20
|
+
export const insertRegionsAndOrps = (data) => {
|
|
21
|
+
let changes = 0;
|
|
22
|
+
changes += insertRegions(data);
|
|
23
|
+
changes += insertCounties(data);
|
|
24
|
+
changes += insertOrps(data);
|
|
25
|
+
// cities are most likely already inserted, but in case they're not,
|
|
26
|
+
// we need to insert them before updating them with region data
|
|
27
|
+
changes += insertCities(data);
|
|
28
|
+
const db = getDb();
|
|
29
|
+
const updateStatement = db.prepare(`UPDATE city SET
|
|
30
|
+
region_code = ?,
|
|
31
|
+
county_code = ?,
|
|
32
|
+
orp_code = ?
|
|
33
|
+
WHERE code = ?`);
|
|
34
|
+
data.forEach((data) => {
|
|
35
|
+
changes += updateStatement.run(data[Column.regionRuianCode], data[Column.countyRuianCode], data[Column.orpRuianCode], data[Column.cityCode]).changes;
|
|
36
|
+
});
|
|
37
|
+
return changes;
|
|
38
|
+
};
|
|
39
|
+
export const insertRegions = (buffer) => {
|
|
40
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, Column.regionRuianCode, [
|
|
41
|
+
Column.regionName,
|
|
42
|
+
Column.regionShortName,
|
|
43
|
+
Column.regionCsuCode100,
|
|
44
|
+
Column.regionCsuCode108Nuts,
|
|
45
|
+
]), "region", ["code", "name", "short_name", "csu_code_100", "csu_code_108_nuts"]);
|
|
46
|
+
};
|
|
47
|
+
export const insertCounties = (buffer) => {
|
|
48
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, Column.countyRuianCode, [
|
|
49
|
+
Column.countyName,
|
|
50
|
+
Column.countyCsuCode101Lau,
|
|
51
|
+
Column.countyCsuCode109Nuts,
|
|
52
|
+
Column.regionRuianCode,
|
|
53
|
+
]), "county", ["code", "name", "csu_code_101_lau", "csu_code_109_nuts", "region_code"]);
|
|
54
|
+
};
|
|
55
|
+
export const insertOrps = (buffer) => {
|
|
56
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, Column.orpRuianCode, [
|
|
57
|
+
Column.orpName,
|
|
58
|
+
Column.orpCsuCode65,
|
|
59
|
+
Column.regionRuianCode,
|
|
60
|
+
Column.countyRuianCode,
|
|
61
|
+
]), "orp", ["code", "name", "csu_code_65", "region_code", "county_code"]);
|
|
62
|
+
};
|
|
63
|
+
export const insertCities = (buffer) => {
|
|
64
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, Column.cityCode, [Column.cityName]), "city", ["code", "name"]);
|
|
65
|
+
};
|
package/dist/db/schools.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { School } from "./types";
|
|
2
|
-
export declare const insertSchools: (schools: School[]
|
|
2
|
+
export declare const insertSchools: (schools: School[]) => number;
|
|
3
3
|
export declare const findSchool: (name: string, schools: School[]) => {
|
|
4
4
|
school: School | null;
|
|
5
5
|
errors: string[];
|
package/dist/db/schools.js
CHANGED
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
import { getDb, insertMultipleRows } from "./db";
|
|
2
1
|
import { findClosestString } from "../utils/helpers";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
db.
|
|
12
|
-
}
|
|
13
|
-
const insertedSchools = insertMultipleRows(
|
|
2
|
+
import { getDb, insertMultipleRows } from "./db";
|
|
3
|
+
export const insertSchools = (schools) => {
|
|
4
|
+
const db = getDb();
|
|
5
|
+
const uniqueSchools = filterOutDuplicates(schools);
|
|
6
|
+
const existingIzo = db.prepare("SELECT izo FROM school").pluck().all();
|
|
7
|
+
const toInsert = uniqueSchools.filter((school) => !existingIzo.includes(school.izo));
|
|
8
|
+
const toUpdate = uniqueSchools.filter((school) => existingIzo.includes(school.izo));
|
|
9
|
+
toUpdate.forEach((school) => {
|
|
10
|
+
db.prepare("UPDATE school SET name = ?, capacity = ? WHERE izo = ?").run(school.name, school.capacity, school.izo);
|
|
11
|
+
});
|
|
12
|
+
const insertedSchools = insertMultipleRows(toInsert.map((school) => [
|
|
14
13
|
school.izo,
|
|
14
|
+
school.redizo,
|
|
15
15
|
school.name,
|
|
16
16
|
school.capacity.toString(),
|
|
17
|
-
]), "school", ["izo", "name", "capacity"]);
|
|
18
|
-
|
|
19
|
-
// const uniqueAddressPoints = [
|
|
20
|
-
// ...new Set(school.locations.map((location) => location.addressPointId)),
|
|
21
|
-
// ];
|
|
22
|
-
// return uniqueAddressPoints.map((addressPoint) => [
|
|
23
|
-
// school.izo,
|
|
24
|
-
// addressPoint.toString(),
|
|
25
|
-
// ]);
|
|
26
|
-
// });
|
|
27
|
-
const locations = schools
|
|
17
|
+
]), "school", ["izo", "redizo", "name", "capacity"]);
|
|
18
|
+
const locations = toInsert
|
|
28
19
|
.filter((school) => school.locations.length > 0)
|
|
29
20
|
.map((school) => [
|
|
30
21
|
school.izo,
|
|
31
|
-
school.locations[0].addressPointId.toString(),
|
|
22
|
+
school.locations[0].addressPointId.toString(), // add only first location
|
|
32
23
|
]);
|
|
33
24
|
let insertedLocations = 0;
|
|
34
|
-
//
|
|
35
|
-
// plus filter out duplicit locations (same address id + izo)
|
|
25
|
+
// plus filter out duplicate locations (same address id + izo)
|
|
36
26
|
locations.forEach((location) => {
|
|
37
27
|
try {
|
|
38
28
|
insertedLocations += insertMultipleRows([location], "school_location", ["school_izo", "address_point_id"], false);
|
|
@@ -59,3 +49,11 @@ export const findSchool = (name, schools) => {
|
|
|
59
49
|
errors.push(`No exact match for school "${name}", using "${bestMatch}" instead.`);
|
|
60
50
|
return { school, errors };
|
|
61
51
|
};
|
|
52
|
+
const filterOutDuplicates = (schools) => {
|
|
53
|
+
const izoSet = new Set();
|
|
54
|
+
return schools.filter((school) => {
|
|
55
|
+
const duplicate = izoSet.has(school.izo);
|
|
56
|
+
izoSet.add(school.izo);
|
|
57
|
+
return !duplicate;
|
|
58
|
+
});
|
|
59
|
+
};
|
package/dist/db/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface SchoolLocation {
|
|
|
6
6
|
export interface School {
|
|
7
7
|
name: string;
|
|
8
8
|
izo: string;
|
|
9
|
+
redizo: string;
|
|
9
10
|
capacity: number;
|
|
10
11
|
locations: SchoolLocation[];
|
|
11
12
|
}
|
|
@@ -22,10 +23,15 @@ export declare enum MunicipalityType {
|
|
|
22
23
|
District = 1,
|
|
23
24
|
Other = 2
|
|
24
25
|
}
|
|
26
|
+
export interface Position {
|
|
27
|
+
lat: number;
|
|
28
|
+
lng: number;
|
|
29
|
+
}
|
|
25
30
|
export interface Municipality {
|
|
26
31
|
type: MunicipalityType;
|
|
27
32
|
code: number;
|
|
28
33
|
}
|
|
34
|
+
export type MunicipalityWithPosition = Municipality & Position;
|
|
29
35
|
export declare const founderToMunicipality: (founder: Founder) => Municipality;
|
|
30
36
|
export interface DbfStreet {
|
|
31
37
|
KOD: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { downloadAndImportAddressPoints, deleteDb } from "./open-data-sync/address-points";
|
|
2
|
+
import { downloadAndImportRegions } from "./open-data-sync/regions";
|
|
3
|
+
import { downloadAndImportSchools } from "./open-data-sync/schools";
|
|
4
|
+
import { downloadAndImportStreets } from "./open-data-sync/streets";
|
|
5
|
+
import { parseOrdinanceToAddressPoints } from "./street-markdown/smd";
|
|
6
|
+
import { OpenDataSyncOptions } from "./utils/helpers";
|
|
7
|
+
export * from "./street-markdown/types";
|
|
8
|
+
/**
|
|
9
|
+
* Download and import all open data to SQLite DB. The DB file will be located
|
|
10
|
+
* in the `dataDir` folder.
|
|
11
|
+
* @param options Options for the sync
|
|
12
|
+
* @param syncStreets Streets sync takes around 1 hour, so it might be skipped.
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { downloadAndImportEverything } from "text-to-map";
|
|
15
|
+
*
|
|
16
|
+
* await downloadAndImportEverything({ tmpDir: "./tmp", dataDir: "./data" });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function downloadAndImportEverything(options?: OpenDataSyncOptions, syncStreets?: boolean): Promise<void>;
|
|
20
|
+
export { downloadAndImportAddressPoints, deleteDb, downloadAndImportSchools, downloadAndImportStreets, downloadAndImportRegions, parseOrdinanceToAddressPoints, };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { downloadAndImportAddressPoints, deleteDb, } from "./open-data-sync/address-points";
|
|
11
|
+
import { downloadAndImportRegions } from "./open-data-sync/regions";
|
|
12
|
+
import { downloadAndImportSchools } from "./open-data-sync/schools";
|
|
13
|
+
import { downloadAndImportStreets } from "./open-data-sync/streets";
|
|
14
|
+
import { parseOrdinanceToAddressPoints } from "./street-markdown/smd";
|
|
15
|
+
export * from "./street-markdown/types";
|
|
16
|
+
/**
|
|
17
|
+
* Download and import all open data to SQLite DB. The DB file will be located
|
|
18
|
+
* in the `dataDir` folder.
|
|
19
|
+
* @param options Options for the sync
|
|
20
|
+
* @param syncStreets Streets sync takes around 1 hour, so it might be skipped.
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { downloadAndImportEverything } from "text-to-map";
|
|
23
|
+
*
|
|
24
|
+
* await downloadAndImportEverything({ tmpDir: "./tmp", dataDir: "./data" });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function downloadAndImportEverything(options = {}, syncStreets = true) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
yield downloadAndImportAddressPoints(options);
|
|
30
|
+
yield downloadAndImportSchools(options);
|
|
31
|
+
yield downloadAndImportRegions(options);
|
|
32
|
+
if (syncStreets) {
|
|
33
|
+
yield downloadAndImportStreets(options);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export { downloadAndImportAddressPoints, deleteDb, downloadAndImportSchools, downloadAndImportStreets, downloadAndImportRegions, parseOrdinanceToAddressPoints, };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { OpenDataSyncOptions } from "../utils/helpers";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const importAllLatestAddressPoints: (options?: OpenDataSyncOptions) => Promise<void>;
|
|
2
|
+
export declare const downloadAndImportAddressPoints: (options?: OpenDataSyncOptions) => Promise<void>;
|
|
4
3
|
export declare const deleteDb: (options?: OpenDataSyncOptions) => void;
|
|
@@ -54,17 +54,13 @@ const importDataToDb = (options) => __awaiter(void 0, void 0, void 0, function*
|
|
|
54
54
|
console.log(`Import completed. Total imported rows: ${total}`);
|
|
55
55
|
});
|
|
56
56
|
const getExtractionFolder = (options) => join(options.tmpDir, options.addressPointsCsvFolderName);
|
|
57
|
-
export const
|
|
57
|
+
export const downloadAndImportAddressPoints = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
58
|
const completeOptions = prepareOptions(options);
|
|
59
59
|
const datasetFeedLink = yield getLatestUrlFromAtomFeed(completeOptions.addressPointsAtomUrl);
|
|
60
60
|
const zipUrl = yield getLatestUrlFromAtomFeed(datasetFeedLink);
|
|
61
61
|
yield downloadAndUnzip(zipUrl, completeOptions);
|
|
62
62
|
yield importDataToDb(completeOptions);
|
|
63
63
|
});
|
|
64
|
-
export const importAllLatestAddressPoints = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
const completeOptions = prepareOptions(options);
|
|
66
|
-
yield importDataToDb(completeOptions);
|
|
67
|
-
});
|
|
68
64
|
export const deleteDb = (options = {}) => {
|
|
69
65
|
const completeOptions = prepareOptions(options);
|
|
70
66
|
if (existsSync(completeOptions.dbFilePath)) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { parse } from "csv-parse";
|
|
11
|
+
import iconv from "iconv-lite";
|
|
12
|
+
import fetch from "node-fetch";
|
|
13
|
+
import { pipeline } from "stream/promises";
|
|
14
|
+
import { initDb, prepareOptions, } from "../utils/helpers";
|
|
15
|
+
import { insertRegionsAndOrps } from "../db/regions";
|
|
16
|
+
const downloadAndImportDataToDb = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
console.log("Downloading regions and ORP data...");
|
|
18
|
+
const response = yield fetch(options.regionsCsvUrl);
|
|
19
|
+
if (response.status !== 200) {
|
|
20
|
+
throw new Error(`The file could not be downloaded. HTTP Code: ${response.status}`);
|
|
21
|
+
}
|
|
22
|
+
console.log("Download completed. Starting to parse CSV file...");
|
|
23
|
+
const rows = [];
|
|
24
|
+
const parseStream = parse({ delimiter: ",", fromLine: 2 }).on("data", (data) => {
|
|
25
|
+
rows.push(data);
|
|
26
|
+
});
|
|
27
|
+
yield pipeline(response.body, iconv.decodeStream("utf-8"), parseStream);
|
|
28
|
+
console.log("Parsing completed. Starting to import data to DB...");
|
|
29
|
+
initDb(options);
|
|
30
|
+
insertRegionsAndOrps(rows);
|
|
31
|
+
console.log(`Import completed. Total imported rows: ${rows.length}`);
|
|
32
|
+
});
|
|
33
|
+
export const downloadAndImportRegions = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const completeOptions = prepareOptions(options);
|
|
35
|
+
yield downloadAndImportDataToDb(completeOptions);
|
|
36
|
+
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { OpenDataSyncOptions } from "../utils/helpers";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const downloadAndImportSchools: (options: OpenDataSyncOptions) => Promise<void>;
|
|
3
3
|
export declare const deleteSchoolsXmlFile: (options?: OpenDataSyncOptions) => void;
|
|
@@ -32,21 +32,23 @@ const downloadXml = (options) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
32
32
|
var XMLState;
|
|
33
33
|
(function (XMLState) {
|
|
34
34
|
XMLState[XMLState["None"] = 0] = "None";
|
|
35
|
-
XMLState[XMLState["
|
|
36
|
-
XMLState[XMLState["
|
|
37
|
-
XMLState[XMLState["
|
|
38
|
-
XMLState[XMLState["
|
|
39
|
-
XMLState[XMLState["
|
|
40
|
-
XMLState[XMLState["
|
|
41
|
-
XMLState[XMLState["
|
|
42
|
-
XMLState[XMLState["
|
|
43
|
-
XMLState[XMLState["
|
|
44
|
-
XMLState[XMLState["
|
|
35
|
+
XMLState[XMLState["RedIzo"] = 1] = "RedIzo";
|
|
36
|
+
XMLState[XMLState["SchoolName"] = 2] = "SchoolName";
|
|
37
|
+
XMLState[XMLState["Izo"] = 3] = "Izo";
|
|
38
|
+
XMLState[XMLState["Ico"] = 4] = "Ico";
|
|
39
|
+
XMLState[XMLState["SchoolType"] = 5] = "SchoolType";
|
|
40
|
+
XMLState[XMLState["Capacity"] = 6] = "Capacity";
|
|
41
|
+
XMLState[XMLState["RuianCode"] = 7] = "RuianCode";
|
|
42
|
+
XMLState[XMLState["Address"] = 8] = "Address";
|
|
43
|
+
XMLState[XMLState["FounderName"] = 9] = "FounderName";
|
|
44
|
+
XMLState[XMLState["FounderType"] = 10] = "FounderType";
|
|
45
|
+
XMLState[XMLState["FounderIco"] = 11] = "FounderIco";
|
|
45
46
|
})(XMLState || (XMLState = {}));
|
|
46
47
|
const SCHOOL_TYPE_PRIMARY = "B00";
|
|
47
48
|
const createNewSchool = () => {
|
|
48
49
|
return {
|
|
49
50
|
name: "",
|
|
51
|
+
redizo: "",
|
|
50
52
|
izo: "",
|
|
51
53
|
capacity: 0,
|
|
52
54
|
locations: [],
|
|
@@ -91,6 +93,9 @@ const processSchoolRegisterXml = (options) => __awaiter(void 0, void 0, void 0,
|
|
|
91
93
|
isCurrentSchoolPrimary = false;
|
|
92
94
|
isRuianCodeMissing = false;
|
|
93
95
|
break;
|
|
96
|
+
case "RedIzo":
|
|
97
|
+
state = XMLState.RedIzo;
|
|
98
|
+
break;
|
|
94
99
|
case "RedPlnyNazev":
|
|
95
100
|
state = XMLState.SchoolName;
|
|
96
101
|
break;
|
|
@@ -191,6 +196,7 @@ const processSchoolRegisterXml = (options) => __awaiter(void 0, void 0, void 0,
|
|
|
191
196
|
case "MistoRUAINKod":
|
|
192
197
|
isRuianCodeMissing = !isRuianCodeSet;
|
|
193
198
|
case "RedPlnyNazev":
|
|
199
|
+
case "RedIzo":
|
|
194
200
|
case "ICO":
|
|
195
201
|
case "IZO":
|
|
196
202
|
case "SkolaDruhTyp":
|
|
@@ -208,6 +214,8 @@ const processSchoolRegisterXml = (options) => __awaiter(void 0, void 0, void 0,
|
|
|
208
214
|
})
|
|
209
215
|
.on("text", (text) => {
|
|
210
216
|
switch (state) {
|
|
217
|
+
case XMLState.RedIzo:
|
|
218
|
+
currentSchool.redizo = text;
|
|
211
219
|
case XMLState.SchoolName:
|
|
212
220
|
currentSchool.name = text;
|
|
213
221
|
break;
|
|
@@ -295,10 +303,11 @@ const importDataToDb = (options, saveFoundersToCsv = false, saveSchoolsWithoutRu
|
|
|
295
303
|
const getXmlFilePath = (options) => {
|
|
296
304
|
return join(options.tmpDir, options.schoolsXmlFileName);
|
|
297
305
|
};
|
|
298
|
-
export const
|
|
306
|
+
export const downloadAndImportSchools = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
299
307
|
const runOptions = prepareOptions(options);
|
|
300
308
|
yield downloadXml(runOptions);
|
|
301
309
|
yield importDataToDb(runOptions, false, true);
|
|
310
|
+
deleteSchoolsXmlFile(runOptions);
|
|
302
311
|
});
|
|
303
312
|
export const deleteSchoolsXmlFile = (options = {}) => {
|
|
304
313
|
const runOptions = prepareOptions(options);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { OpenDataSyncOptions } from "../utils/helpers";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const downloadAndImportStreets: (options: OpenDataSyncOptions) => Promise<void>;
|
|
@@ -39,13 +39,14 @@ const downloadZipAndParseDbfFile = (url, index, options) => __awaiter(void 0, vo
|
|
|
39
39
|
rmSync(zipFilePath);
|
|
40
40
|
return obj;
|
|
41
41
|
});
|
|
42
|
-
const importDataToDb = (data
|
|
42
|
+
const importDataToDb = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
if (data.length === 0) {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
insertStreetsFromDbf(data);
|
|
47
47
|
});
|
|
48
|
-
export const
|
|
48
|
+
export const downloadAndImportStreets = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
console.log("Starting to download and import streets. This takes up to 1 hour.");
|
|
49
50
|
const completeOptions = prepareOptions(options);
|
|
50
51
|
initDb(completeOptions);
|
|
51
52
|
prepareFolders(completeOptions);
|
|
@@ -69,7 +70,7 @@ export const downloadAndImportAllStreets = (options) => __awaiter(void 0, void 0
|
|
|
69
70
|
for (const link of newLinks) {
|
|
70
71
|
const zipLink = yield getLatestUrlFromAtomFeed(link);
|
|
71
72
|
const dbfObject = yield downloadZipAndParseDbfFile(zipLink, done, completeOptions);
|
|
72
|
-
yield importDataToDb(dbfObject
|
|
73
|
+
yield importDataToDb(dbfObject);
|
|
73
74
|
setStreetAsSynced(link);
|
|
74
75
|
done++;
|
|
75
76
|
console.log(`Loaded links: ${done}/${allDatasetFeedLinks.length}`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Municipality as DbMunicipality } from "../db/types";
|
|
2
|
+
import { AddressPoint as CzechAddressPoint } from "czech-address";
|
|
2
3
|
export interface ProcessedSmdLines {
|
|
3
4
|
smdLines: SmdLine[];
|
|
4
5
|
errors: string[];
|
|
@@ -42,22 +43,9 @@ export declare enum SeriesType {
|
|
|
42
43
|
All = 2,
|
|
43
44
|
Descriptive = 3
|
|
44
45
|
}
|
|
45
|
-
export
|
|
46
|
-
Descriptive = 0,
|
|
47
|
-
Registration = 1
|
|
48
|
-
}
|
|
49
|
-
export interface AddressPoint {
|
|
46
|
+
export interface AddressPoint extends CzechAddressPoint {
|
|
50
47
|
id: number;
|
|
51
48
|
address: string;
|
|
52
|
-
type: AddressPointType;
|
|
53
|
-
street?: string;
|
|
54
|
-
descriptiveNumber: number;
|
|
55
|
-
orientationalNumber?: number;
|
|
56
|
-
orientationalNumberLetter?: string;
|
|
57
|
-
postalCode: string;
|
|
58
|
-
city: string;
|
|
59
|
-
district?: string;
|
|
60
|
-
municipalityPart?: string;
|
|
61
49
|
lat: number;
|
|
62
50
|
lng: number;
|
|
63
51
|
}
|
|
@@ -10,9 +10,4 @@ export var SeriesType;
|
|
|
10
10
|
SeriesType[SeriesType["All"] = 2] = "All";
|
|
11
11
|
SeriesType[SeriesType["Descriptive"] = 3] = "Descriptive";
|
|
12
12
|
})(SeriesType || (SeriesType = {}));
|
|
13
|
-
export var AddressPointType;
|
|
14
|
-
(function (AddressPointType) {
|
|
15
|
-
AddressPointType[AddressPointType["Descriptive"] = 0] = "Descriptive";
|
|
16
|
-
AddressPointType[AddressPointType["Registration"] = 1] = "Registration";
|
|
17
|
-
})(AddressPointType || (AddressPointType = {}));
|
|
18
13
|
export const isAddressPoint = (something) => something.hasOwnProperty("id");
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export interface OpenDataSyncOptions {
|
|
|
12
12
|
streetDbfFileName?: string;
|
|
13
13
|
schoolsXmlUrl?: string;
|
|
14
14
|
schoolsXmlFileName?: string;
|
|
15
|
+
regionsCsvUrl?: string;
|
|
16
|
+
regionsCsvFileName?: string;
|
|
15
17
|
}
|
|
16
18
|
export interface OpenDataSyncOptionsNotEmpty {
|
|
17
19
|
tmpDir: string;
|
|
@@ -26,9 +28,12 @@ export interface OpenDataSyncOptionsNotEmpty {
|
|
|
26
28
|
streetDbfFileName: string;
|
|
27
29
|
schoolsXmlUrl: string;
|
|
28
30
|
schoolsXmlFileName: string;
|
|
31
|
+
regionsCsvUrl: string;
|
|
32
|
+
regionsCsvFileName: string;
|
|
29
33
|
}
|
|
30
34
|
export declare const getAppDataDirPath: () => string;
|
|
31
35
|
export declare const prepareOptions: (options: OpenDataSyncOptions) => OpenDataSyncOptionsNotEmpty;
|
|
32
36
|
export declare const initDb: (options: OpenDataSyncOptionsNotEmpty) => void;
|
|
33
37
|
export declare const extractMunicipalityName: (founder: Founder) => string;
|
|
38
|
+
export declare const sanitizeMunicipalityName: (name: string) => string;
|
|
34
39
|
export declare const findClosestString: (str: string, arr: string[]) => string;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { existsSync, mkdirSync } from "fs";
|
|
2
2
|
import { tmpdir } from "os";
|
|
3
|
-
import { join } from "path";
|
|
3
|
+
import { dirname, join } from "path";
|
|
4
4
|
import { MunicipalityType } from "../db/types";
|
|
5
5
|
import { setDbConfig } from "../db/db";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
6
7
|
const appName = "text-to-map";
|
|
7
8
|
export const getAppDataDirPath = () => join(process.env.APPDATA ||
|
|
8
9
|
(process.platform == "darwin"
|
|
9
10
|
? process.env.HOME + "/Library/Preferences"
|
|
10
11
|
: process.env.HOME + "/.local/share"), appName);
|
|
11
12
|
export const prepareOptions = (options) => {
|
|
12
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
13
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
13
14
|
const dataDir = (_a = options.dataDir) !== null && _a !== void 0 ? _a : getAppDataDirPath();
|
|
14
15
|
if (!existsSync(dataDir)) {
|
|
15
16
|
mkdirSync(dataDir);
|
|
@@ -18,11 +19,13 @@ export const prepareOptions = (options) => {
|
|
|
18
19
|
if (!existsSync(tmpAppDir)) {
|
|
19
20
|
mkdirSync(tmpAppDir);
|
|
20
21
|
}
|
|
22
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
23
|
+
const __dirname = dirname(__filename);
|
|
21
24
|
return {
|
|
22
25
|
tmpDir: (_b = options.tmpDir) !== null && _b !== void 0 ? _b : tmpAppDir,
|
|
23
26
|
dataDir: dataDir,
|
|
24
27
|
dbFilePath: (_c = options.dbFilePath) !== null && _c !== void 0 ? _c : join(dataDir, "address_points.db"),
|
|
25
|
-
dbInitFilePath: (_d = options.dbInitFilePath) !== null && _d !== void 0 ? _d : join("
|
|
28
|
+
dbInitFilePath: (_d = options.dbInitFilePath) !== null && _d !== void 0 ? _d : join(__dirname, "..", "address_points_init.db"),
|
|
26
29
|
addressPointsAtomUrl: (_e = options.addressPointsAtomUrl) !== null && _e !== void 0 ? _e : "https://atom.cuzk.cz/RUIAN-CSV-ADR-ST/RUIAN-CSV-ADR-ST.xml",
|
|
27
30
|
addressPointsZipFileName: (_f = options.addressPointsZipFileName) !== null && _f !== void 0 ? _f : "ruian_csv.zip",
|
|
28
31
|
addressPointsCsvFolderName: (_g = options.addressPointsCsvFolderName) !== null && _g !== void 0 ? _g : "CSV",
|
|
@@ -31,6 +34,8 @@ export const prepareOptions = (options) => {
|
|
|
31
34
|
streetDbfFileName: (_k = options.streetDbfFileName) !== null && _k !== void 0 ? _k : "UL_L.dbf",
|
|
32
35
|
schoolsXmlUrl: (_l = options.schoolsXmlUrl) !== null && _l !== void 0 ? _l : "https://rejstriky.msmt.cz/opendata/vrejcelk.xml",
|
|
33
36
|
schoolsXmlFileName: (_m = options.schoolsXmlFileName) !== null && _m !== void 0 ? _m : "school-register.xml",
|
|
37
|
+
regionsCsvUrl: (_o = options.regionsCsvUrl) !== null && _o !== void 0 ? _o : "https://www.czso.cz/documents/10180/23208674/struktura_uzemi_cr.csv",
|
|
38
|
+
regionsCsvFileName: (_p = options.regionsCsvFileName) !== null && _p !== void 0 ? _p : "struktura_uzemi_cr.csv",
|
|
34
39
|
};
|
|
35
40
|
};
|
|
36
41
|
export const initDb = (options) => {
|
|
@@ -67,6 +72,12 @@ export const extractMunicipalityName = (founder) => {
|
|
|
67
72
|
}
|
|
68
73
|
return founder.name;
|
|
69
74
|
};
|
|
75
|
+
export const sanitizeMunicipalityName = (name) => {
|
|
76
|
+
return name
|
|
77
|
+
.replace(" - ", "-")
|
|
78
|
+
.replace(/\s{2,}/g, " ")
|
|
79
|
+
.trim();
|
|
80
|
+
};
|
|
70
81
|
export const findClosestString = (str, arr) => {
|
|
71
82
|
let closestStr = "";
|
|
72
83
|
let closestDistance = Number.MAX_SAFE_INTEGER;
|
package/package.json
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"dependencies": {
|
|
4
4
|
"@arodax/jtsk2wgs84": "^1.0.2",
|
|
5
|
+
"@turf/distance": "^6.5.0",
|
|
5
6
|
"adm-zip": "^0.5.9",
|
|
6
7
|
"better-sqlite3": "^8.0.1",
|
|
7
8
|
"chevrotain": "^10.4.2",
|
|
8
9
|
"csv-parse": "^5.3.3",
|
|
10
|
+
"czech-address": "^1.0.1",
|
|
9
11
|
"feedparser": "^2.2.10",
|
|
10
12
|
"iconv-lite": "^0.6.3",
|
|
11
13
|
"node-fetch": "^3.3.0",
|
|
@@ -29,12 +31,12 @@
|
|
|
29
31
|
},
|
|
30
32
|
"scripts": {
|
|
31
33
|
"address-points": "ts-node --experimental-specifier-resolution=node --esm src/bin/address-points.ts",
|
|
32
|
-
"address-points-import-only": "ts-node --experimental-specifier-resolution=node --esm src/bin/address-points-import-only.ts",
|
|
33
34
|
"schools": "ts-node --experimental-specifier-resolution=node --esm src/bin/schools.ts",
|
|
34
35
|
"clear-all": "ts-node --experimental-specifier-resolution=node --esm src/bin/clear-all.ts",
|
|
35
36
|
"parse-ordinance": "ts-node --experimental-specifier-resolution=node --esm src/bin/parse-ordinance.ts",
|
|
36
37
|
"diagrams": "ts-node --experimental-specifier-resolution=node --esm src/bin/generate-syntax-diagrams.ts",
|
|
37
38
|
"streets": "ts-node --experimental-specifier-resolution=node --esm src/bin/streets.ts",
|
|
39
|
+
"regions": "ts-node --experimental-specifier-resolution=node --esm src/bin/regions.ts",
|
|
38
40
|
"dbf": "ts-node --experimental-specifier-resolution=node --esm src/bin/dbf.ts",
|
|
39
41
|
"test": "jest",
|
|
40
42
|
"ordinance-to-csv-rules": "node src/smd-to-csv/ordinance-to-csv-rules.js",
|
|
@@ -47,7 +49,7 @@
|
|
|
47
49
|
},
|
|
48
50
|
"name": "text-to-map",
|
|
49
51
|
"description": "Text To Map usiluje o lepší, strojově zpracovatelné využití částí vyhlášek s výčtem ulic a dalších lokací. Jde o rozšiřitelnou sadu konceptů a nástrojů, které zajistí hladký převod výčtu ulic a jejich rozsahů v lidsky srozumitelném jazyce do strojově zpracovatelného, uchopitelného formátu.",
|
|
50
|
-
"version": "1.0.
|
|
52
|
+
"version": "1.0.4",
|
|
51
53
|
"main": "dist/index.js",
|
|
52
54
|
"types": "dist/index.d.ts",
|
|
53
55
|
"files": [
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { importAllLatestAddressPoints } from "../open-data-sync/address-points";
|
|
2
|
-
console.time("importOnly");
|
|
3
|
-
importAllLatestAddressPoints({})
|
|
4
|
-
.then(() => {
|
|
5
|
-
console.timeEnd("importOnly");
|
|
6
|
-
})
|
|
7
|
-
.catch((error) => {
|
|
8
|
-
if (error.hasOwnProperty("stack")) {
|
|
9
|
-
console.log(error, error.stack);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
console.log(error);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { AddressPoint } from "../street-markdown/types";
|
|
2
|
-
export interface ThreeRowsAddress {
|
|
3
|
-
firstRow: string;
|
|
4
|
-
secondRow: string;
|
|
5
|
-
thirdRow: string;
|
|
6
|
-
}
|
|
7
|
-
export declare const buildInline: (address: AddressPoint) => string;
|
|
8
|
-
export declare const build: (address: AddressPoint) => ThreeRowsAddress;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Taken from https://github.com/letomas/RUIAN-search and rewritten to typescript.
|
|
3
|
-
|
|
4
|
-
MIT License
|
|
5
|
-
|
|
6
|
-
Copyright (c) 2020 Tomáš Le
|
|
7
|
-
|
|
8
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
in the Software without restriction, including without limitation the rights
|
|
11
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
furnished to do so, subject to the following conditions:
|
|
14
|
-
|
|
15
|
-
The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
copies or substantial portions of the Software.
|
|
17
|
-
|
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
SOFTWARE.
|
|
25
|
-
*/
|
|
26
|
-
import { AddressPointType } from "../street-markdown/types";
|
|
27
|
-
export const buildInline = (address) => {
|
|
28
|
-
const addressInRows = build(address);
|
|
29
|
-
let result = addressInRows.firstRow + ", " + addressInRows.secondRow;
|
|
30
|
-
if (addressInRows.thirdRow) {
|
|
31
|
-
result += ", " + addressInRows.thirdRow;
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
export const build = (address) => {
|
|
36
|
-
const result = {
|
|
37
|
-
firstRow: "",
|
|
38
|
-
secondRow: "",
|
|
39
|
-
thirdRow: "",
|
|
40
|
-
};
|
|
41
|
-
if (!!address.street && !districtEqualsCity(address)) {
|
|
42
|
-
result.secondRow = address.district;
|
|
43
|
-
}
|
|
44
|
-
if (!address.street) {
|
|
45
|
-
if (address.city === address.district) {
|
|
46
|
-
let buildingType = address.type === AddressPointType.Registration ? " č. ev. " : "č. p. ";
|
|
47
|
-
result.firstRow = buildingType + address.descriptiveNumber;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
result.firstRow = address.district;
|
|
51
|
-
result.firstRow += " " + buildHouseNumber(address);
|
|
52
|
-
}
|
|
53
|
-
result.firstRow += buildOrientationalNumber(address);
|
|
54
|
-
buildLastRow(result, address);
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
result.firstRow = address.street;
|
|
58
|
-
result.firstRow += " " + buildHouseNumber(address);
|
|
59
|
-
result.firstRow += buildOrientationalNumber(address);
|
|
60
|
-
buildLastRow(result, address);
|
|
61
|
-
return result;
|
|
62
|
-
};
|
|
63
|
-
const buildHouseNumber = (address) => {
|
|
64
|
-
if (address.type === AddressPointType.Registration) {
|
|
65
|
-
return "č. ev. " + address.descriptiveNumber;
|
|
66
|
-
}
|
|
67
|
-
return address.descriptiveNumber;
|
|
68
|
-
};
|
|
69
|
-
const buildOrientationalNumber = (address) => {
|
|
70
|
-
var _a;
|
|
71
|
-
if (address.orientationalNumber) {
|
|
72
|
-
return ("/" +
|
|
73
|
-
address.orientationalNumber +
|
|
74
|
-
((_a = address.orientationalNumberLetter) !== null && _a !== void 0 ? _a : ""));
|
|
75
|
-
}
|
|
76
|
-
return "";
|
|
77
|
-
};
|
|
78
|
-
const buildLastRow = (result, address) => {
|
|
79
|
-
// if (!result.secondRow) {
|
|
80
|
-
// if (address.city === "Praha") {
|
|
81
|
-
// result.secondRow = address.postalCode + " " + address.pragueBoroughName;
|
|
82
|
-
// } else {
|
|
83
|
-
// result.secondRow = address.postalCode + " " + address.cityName;
|
|
84
|
-
// }
|
|
85
|
-
// } else {
|
|
86
|
-
// if (address.cityName === "Praha") {
|
|
87
|
-
// result.thirdRow = address.postalCode + " " + address.pragueBoroughName;
|
|
88
|
-
// } else {
|
|
89
|
-
// result.thirdRow = address.postalCode + " " + address.cityName;
|
|
90
|
-
// }
|
|
91
|
-
// }
|
|
92
|
-
if (!result.secondRow) {
|
|
93
|
-
result.secondRow = address.postalCode + " " + address.city;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
result.thirdRow = address.postalCode + " " + address.city;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const districtEqualsCity = (address) => {
|
|
100
|
-
return address.district === address.city;
|
|
101
|
-
};
|
|
File without changes
|