text-to-map 1.0.4 → 1.0.6
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/bin/address-points.js +1 -1
- package/dist/bin/regions.js +1 -1
- package/dist/bin/schools.js +1 -1
- package/dist/bin/streets.js +1 -1
- package/dist/bin/sync-all.d.ts +1 -0
- package/dist/bin/sync-all.js +2 -0
- package/dist/db/address-points.js +6 -6
- package/dist/db/regions.d.ts +15 -7
- package/dist/db/regions.js +56 -44
- package/dist/open-data-sync/regions.js +7 -1
- package/dist/street-markdown/smd-parser.js +4 -4
- package/dist/street-markdown/types.d.ts +2 -2
- package/dist/street-markdown/types.js +1 -1
- package/dist/utils/helpers.d.ts +2 -0
- package/dist/utils/helpers.js +3 -2
- package/dist/utils/jtsk2wgs84.d.ts +17 -0
- package/dist/utils/jtsk2wgs84.js +80 -0
- package/package.json +6 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { downloadAndImportAddressPoints } from "../open-data-sync/address-points";
|
|
2
2
|
console.time("downloadAndImportAllLatestAddressPoints");
|
|
3
|
-
downloadAndImportAddressPoints()
|
|
3
|
+
downloadAndImportAddressPoints({ dataDir: "./tmp/db" })
|
|
4
4
|
.then(() => {
|
|
5
5
|
console.timeEnd("downloadAndImportAllLatestAddressPoints");
|
|
6
6
|
})
|
package/dist/bin/regions.js
CHANGED
package/dist/bin/schools.js
CHANGED
package/dist/bin/streets.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { downloadAndImportStreets } from "../open-data-sync/streets";
|
|
2
2
|
console.time("downloadAndImportAllStreets");
|
|
3
|
-
downloadAndImportStreets({})
|
|
3
|
+
downloadAndImportStreets({ dataDir: "./tmp/db" })
|
|
4
4
|
.then(() => {
|
|
5
5
|
console.timeEnd("downloadAndImportAllStreets");
|
|
6
6
|
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import jtsk2wgs84 from "
|
|
1
|
+
import jtsk2wgs84 from "../utils/jtsk2wgs84";
|
|
2
2
|
import { AddressPointType, createSingleLineAddress } from "czech-address";
|
|
3
3
|
import { SeriesType, isNegativeSeriesSpec, isRange, isSeriesSpecArray, isWholeMunicipalitySmdLine, } from "../street-markdown/types";
|
|
4
4
|
import { findClosestString } from "../utils/helpers";
|
|
@@ -216,7 +216,7 @@ const filterAddressPointsByRanges = (addressPoints, seriesSpec) => {
|
|
|
216
216
|
var _a;
|
|
217
217
|
if (isRange(range)) {
|
|
218
218
|
const number = getNumberByType(seriesSpec.type, addressPoint);
|
|
219
|
-
return (isInRange(number, seriesSpec.type !== SeriesType.
|
|
219
|
+
return (isInRange(number, seriesSpec.type !== SeriesType.Description
|
|
220
220
|
? (_a = addressPoint.orientationalNumberLetter) !== null && _a !== void 0 ? _a : null
|
|
221
221
|
: null, range) && fitsType(number, seriesSpec.type));
|
|
222
222
|
}
|
|
@@ -252,13 +252,13 @@ export const isInRange = (number, letter, range) => {
|
|
|
252
252
|
return satisfiesFrom && satisfiesTo;
|
|
253
253
|
};
|
|
254
254
|
export const fitsType = (number, type) => {
|
|
255
|
-
return (type === SeriesType.
|
|
255
|
+
return (type === SeriesType.Description ||
|
|
256
256
|
type === SeriesType.All ||
|
|
257
257
|
(type === SeriesType.Odd && number % 2 === 1) ||
|
|
258
258
|
(type === SeriesType.Even && number % 2 === 0));
|
|
259
259
|
};
|
|
260
260
|
export const equalsFullStreetNumber = (fullStreetNumber, addressPoint) => {
|
|
261
|
-
return (fullStreetNumber.
|
|
261
|
+
return (fullStreetNumber.descriptionNumber.number === addressPoint.houseNumber &&
|
|
262
262
|
fullStreetNumber.orientationalNumber.number ===
|
|
263
263
|
addressPoint.orientationalNumber &&
|
|
264
264
|
((!fullStreetNumber.orientationalNumber.letter &&
|
|
@@ -268,7 +268,7 @@ export const equalsFullStreetNumber = (fullStreetNumber, addressPoint) => {
|
|
|
268
268
|
};
|
|
269
269
|
const getNumberByType = (type, addressPoint) => {
|
|
270
270
|
var _a;
|
|
271
|
-
return type === SeriesType.
|
|
271
|
+
return type === SeriesType.Description
|
|
272
272
|
? addressPoint.houseNumber
|
|
273
273
|
: (_a = addressPoint.orientationalNumber) !== null && _a !== void 0 ? _a : null;
|
|
274
274
|
};
|
|
@@ -303,7 +303,7 @@ const rowToAddressPoint = (row) => {
|
|
|
303
303
|
if (row.district_name !== null) {
|
|
304
304
|
point.district = row.district_name;
|
|
305
305
|
}
|
|
306
|
-
if (row.
|
|
306
|
+
if (row.prague_district_name !== null) {
|
|
307
307
|
point.pragueDistrict = row.prague_district_name;
|
|
308
308
|
}
|
|
309
309
|
point.address = createSingleLineAddress(point);
|
package/dist/db/regions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
interface RegionsColumn {
|
|
2
2
|
cityName: number;
|
|
3
3
|
cityCode: number;
|
|
4
4
|
cityType: number;
|
|
@@ -15,9 +15,17 @@ export declare const Column: {
|
|
|
15
15
|
regionCsuCode100: number;
|
|
16
16
|
regionCsuCode108Nuts: number;
|
|
17
17
|
regionRuianCode: number;
|
|
18
|
-
}
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
}
|
|
19
|
+
export interface RegionsTableSchema {
|
|
20
|
+
tableSchema: {
|
|
21
|
+
columns: {
|
|
22
|
+
name: string;
|
|
23
|
+
}[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare const insertRegionsAndOrps: (data: string[][], schema: RegionsTableSchema) => number;
|
|
27
|
+
export declare const insertRegions: (buffer: string[][], columnIndex: RegionsColumn) => number;
|
|
28
|
+
export declare const insertCounties: (buffer: string[][], columnIndex: RegionsColumn) => number;
|
|
29
|
+
export declare const insertOrps: (buffer: string[][], columnIndex: RegionsColumn) => number;
|
|
30
|
+
export declare const insertCities: (buffer: string[][], columnIndex: RegionsColumn) => number;
|
|
31
|
+
export {};
|
package/dist/db/regions.js
CHANGED
|
@@ -1,30 +1,13 @@
|
|
|
1
1
|
import { extractKeyValuesPairs, getDb, insertMultipleRows } from "./db";
|
|
2
|
-
export const
|
|
3
|
-
|
|
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) => {
|
|
2
|
+
export const insertRegionsAndOrps = (data, schema) => {
|
|
3
|
+
const columnIndex = getColumnIndexFromSchema(schema);
|
|
21
4
|
let changes = 0;
|
|
22
|
-
changes += insertRegions(data);
|
|
23
|
-
changes += insertCounties(data);
|
|
24
|
-
changes += insertOrps(data);
|
|
5
|
+
changes += insertRegions(data, columnIndex);
|
|
6
|
+
changes += insertCounties(data, columnIndex);
|
|
7
|
+
changes += insertOrps(data, columnIndex);
|
|
25
8
|
// cities are most likely already inserted, but in case they're not,
|
|
26
9
|
// we need to insert them before updating them with region data
|
|
27
|
-
changes += insertCities(data);
|
|
10
|
+
changes += insertCities(data, columnIndex);
|
|
28
11
|
const db = getDb();
|
|
29
12
|
const updateStatement = db.prepare(`UPDATE city SET
|
|
30
13
|
region_code = ?,
|
|
@@ -32,34 +15,63 @@ export const insertRegionsAndOrps = (data) => {
|
|
|
32
15
|
orp_code = ?
|
|
33
16
|
WHERE code = ?`);
|
|
34
17
|
data.forEach((data) => {
|
|
35
|
-
changes += updateStatement.run(data[
|
|
18
|
+
changes += updateStatement.run(data[columnIndex.regionRuianCode], data[columnIndex.countyRuianCode], data[columnIndex.orpRuianCode], data[columnIndex.cityCode]).changes;
|
|
36
19
|
});
|
|
37
20
|
return changes;
|
|
38
21
|
};
|
|
39
|
-
export const insertRegions = (buffer) => {
|
|
40
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
22
|
+
export const insertRegions = (buffer, columnIndex) => {
|
|
23
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, columnIndex.regionRuianCode, [
|
|
24
|
+
columnIndex.regionName,
|
|
25
|
+
columnIndex.regionShortName,
|
|
26
|
+
columnIndex.regionCsuCode100,
|
|
27
|
+
columnIndex.regionCsuCode108Nuts,
|
|
45
28
|
]), "region", ["code", "name", "short_name", "csu_code_100", "csu_code_108_nuts"]);
|
|
46
29
|
};
|
|
47
|
-
export const insertCounties = (buffer) => {
|
|
48
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
export const insertCounties = (buffer, columnIndex) => {
|
|
31
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, columnIndex.countyRuianCode, [
|
|
32
|
+
columnIndex.countyName,
|
|
33
|
+
columnIndex.countyCsuCode101Lau,
|
|
34
|
+
columnIndex.countyCsuCode109Nuts,
|
|
35
|
+
columnIndex.regionRuianCode,
|
|
53
36
|
]), "county", ["code", "name", "csu_code_101_lau", "csu_code_109_nuts", "region_code"]);
|
|
54
37
|
};
|
|
55
|
-
export const insertOrps = (buffer) => {
|
|
56
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
38
|
+
export const insertOrps = (buffer, columnIndex) => {
|
|
39
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, columnIndex.orpRuianCode, [
|
|
40
|
+
columnIndex.orpName,
|
|
41
|
+
columnIndex.orpCsuCode65,
|
|
42
|
+
columnIndex.regionRuianCode,
|
|
43
|
+
columnIndex.countyRuianCode,
|
|
61
44
|
]), "orp", ["code", "name", "csu_code_65", "region_code", "county_code"]);
|
|
62
45
|
};
|
|
63
|
-
export const insertCities = (buffer) => {
|
|
64
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer,
|
|
46
|
+
export const insertCities = (buffer, columnIndex) => {
|
|
47
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, columnIndex.cityCode, [columnIndex.cityName]), "city", ["code", "name"]);
|
|
48
|
+
};
|
|
49
|
+
const getColumnIndexFromSchema = (schema) => {
|
|
50
|
+
const names = schema.tableSchema.columns.map((column) => column.name);
|
|
51
|
+
const columnIndex = {
|
|
52
|
+
cityName: findOrDie(names, "obec_text"),
|
|
53
|
+
cityCode: findOrDie(names, "obec_kod"),
|
|
54
|
+
cityType: findOrDie(names, "obec_typ"),
|
|
55
|
+
orpName: findOrDie(names, "orp_text"),
|
|
56
|
+
orpCsuCode65: findOrDie(names, "orp_csu_cis65_kod"),
|
|
57
|
+
orpRuianCode: findOrDie(names, "orp_ruian_kod"),
|
|
58
|
+
orpCityCode: findOrDie(names, "orp_sidlo_obec_kod"),
|
|
59
|
+
countyName: findOrDie(names, "okres_text"),
|
|
60
|
+
countyCsuCode101Lau: findOrDie(names, "okres_csu_cis101_lau_kod"),
|
|
61
|
+
countyCsuCode109Nuts: findOrDie(names, "okres_csu_cis109_nuts_kod"),
|
|
62
|
+
countyRuianCode: findOrDie(names, "okres_ruian_kod"),
|
|
63
|
+
regionName: findOrDie(names, "kraj_text"),
|
|
64
|
+
regionShortName: findOrDie(names, "kraj_zkratka"),
|
|
65
|
+
regionCsuCode100: findOrDie(names, "kraj_csu_cis100_kod"),
|
|
66
|
+
regionCsuCode108Nuts: findOrDie(names, "kraj_csu_cis108_nuts_kod"),
|
|
67
|
+
regionRuianCode: findOrDie(names, "kraj_ruian_vusc_kod"),
|
|
68
|
+
};
|
|
69
|
+
return columnIndex;
|
|
70
|
+
};
|
|
71
|
+
const findOrDie = (columnNames, name) => {
|
|
72
|
+
const index = columnNames.indexOf(name);
|
|
73
|
+
if (index < 0) {
|
|
74
|
+
throw new Error(`Column '${name}' not found in region schema. Check https://data.gov.cz/datov%C3%A1-sada?iri=https%3A%2F%2Fdata.gov.cz%2Fzdroj%2Fdatov%C3%A9-sady%2F00025593%2F271b0fb7c2abb7f44e12ad57617821b2 for current dataset info or search for 'Struktura území ČR se všemi kódy území od obcí po stát dle číselníků ČSÚ, klasifikace NUTS a kódů RÚIAN.'.`);
|
|
75
|
+
}
|
|
76
|
+
return index;
|
|
65
77
|
};
|
|
@@ -25,9 +25,15 @@ const downloadAndImportDataToDb = (options) => __awaiter(void 0, void 0, void 0,
|
|
|
25
25
|
rows.push(data);
|
|
26
26
|
});
|
|
27
27
|
yield pipeline(response.body, iconv.decodeStream("utf-8"), parseStream);
|
|
28
|
+
const schemaResponse = yield fetch(options.regionsSchemaUrl);
|
|
29
|
+
if (schemaResponse.status !== 200) {
|
|
30
|
+
throw new Error(`The file could not be downloaded. HTTP Code: ${schemaResponse.status}`);
|
|
31
|
+
}
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
const schema = yield schemaResponse.json();
|
|
28
34
|
console.log("Parsing completed. Starting to import data to DB...");
|
|
29
35
|
initDb(options);
|
|
30
|
-
insertRegionsAndOrps(rows);
|
|
36
|
+
insertRegionsAndOrps(rows, schema);
|
|
31
37
|
console.log(`Import completed. Total imported rows: ${rows.length}`);
|
|
32
38
|
});
|
|
33
39
|
export const downloadAndImportRegions = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -178,7 +178,7 @@ export class SmdParser extends EmbeddedActionsParser {
|
|
|
178
178
|
{
|
|
179
179
|
ALT: () => {
|
|
180
180
|
this.CONSUME3(DescriptiveType);
|
|
181
|
-
type = SeriesType.
|
|
181
|
+
type = SeriesType.Description;
|
|
182
182
|
},
|
|
183
183
|
},
|
|
184
184
|
]);
|
|
@@ -265,7 +265,7 @@ export class SmdParser extends EmbeddedActionsParser {
|
|
|
265
265
|
},
|
|
266
266
|
{
|
|
267
267
|
ALT: () => {
|
|
268
|
-
type = SeriesType.
|
|
268
|
+
type = SeriesType.Description;
|
|
269
269
|
this.CONSUME(DescriptiveType);
|
|
270
270
|
},
|
|
271
271
|
},
|
|
@@ -308,7 +308,7 @@ export class SmdParser extends EmbeddedActionsParser {
|
|
|
308
308
|
},
|
|
309
309
|
{
|
|
310
310
|
ALT: () => {
|
|
311
|
-
type = SeriesType.
|
|
311
|
+
type = SeriesType.Description;
|
|
312
312
|
this.CONSUME(DescriptiveType);
|
|
313
313
|
},
|
|
314
314
|
},
|
|
@@ -321,7 +321,7 @@ export class SmdParser extends EmbeddedActionsParser {
|
|
|
321
321
|
const descriptiveNumber = parseRichNumber(this.CONSUME(Number).image);
|
|
322
322
|
this.CONSUME(Slash);
|
|
323
323
|
const orientationNumber = parseRichNumber(this.CONSUME2(Number).image);
|
|
324
|
-
return { descriptiveNumber, orientationalNumber: orientationNumber };
|
|
324
|
+
return { descriptionNumber: descriptiveNumber, orientationalNumber: orientationNumber };
|
|
325
325
|
});
|
|
326
326
|
this.performSelfAnalysis();
|
|
327
327
|
}
|
|
@@ -32,7 +32,7 @@ export interface RichNumber {
|
|
|
32
32
|
letter?: string;
|
|
33
33
|
}
|
|
34
34
|
export interface FullStreetNumber {
|
|
35
|
-
|
|
35
|
+
descriptionNumber: RichNumber;
|
|
36
36
|
orientationalNumber: RichNumber;
|
|
37
37
|
}
|
|
38
38
|
export declare const isFullStreetNumber: (something: RangeSpec | FullStreetNumber) => something is FullStreetNumber;
|
|
@@ -41,7 +41,7 @@ export declare enum SeriesType {
|
|
|
41
41
|
Even = 0,
|
|
42
42
|
Odd = 1,
|
|
43
43
|
All = 2,
|
|
44
|
-
|
|
44
|
+
Description = 3
|
|
45
45
|
}
|
|
46
46
|
export interface AddressPoint extends CzechAddressPoint {
|
|
47
47
|
id: number;
|
|
@@ -8,6 +8,6 @@ export var SeriesType;
|
|
|
8
8
|
SeriesType[SeriesType["Even"] = 0] = "Even";
|
|
9
9
|
SeriesType[SeriesType["Odd"] = 1] = "Odd";
|
|
10
10
|
SeriesType[SeriesType["All"] = 2] = "All";
|
|
11
|
-
SeriesType[SeriesType["
|
|
11
|
+
SeriesType[SeriesType["Description"] = 3] = "Description";
|
|
12
12
|
})(SeriesType || (SeriesType = {}));
|
|
13
13
|
export const isAddressPoint = (something) => something.hasOwnProperty("id");
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface OpenDataSyncOptions {
|
|
|
13
13
|
schoolsXmlUrl?: string;
|
|
14
14
|
schoolsXmlFileName?: string;
|
|
15
15
|
regionsCsvUrl?: string;
|
|
16
|
+
regionsSchemaUrl?: string;
|
|
16
17
|
regionsCsvFileName?: string;
|
|
17
18
|
}
|
|
18
19
|
export interface OpenDataSyncOptionsNotEmpty {
|
|
@@ -29,6 +30,7 @@ export interface OpenDataSyncOptionsNotEmpty {
|
|
|
29
30
|
schoolsXmlUrl: string;
|
|
30
31
|
schoolsXmlFileName: string;
|
|
31
32
|
regionsCsvUrl: string;
|
|
33
|
+
regionsSchemaUrl: string;
|
|
32
34
|
regionsCsvFileName: string;
|
|
33
35
|
}
|
|
34
36
|
export declare const getAppDataDirPath: () => string;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -10,7 +10,7 @@ export const getAppDataDirPath = () => join(process.env.APPDATA ||
|
|
|
10
10
|
? process.env.HOME + "/Library/Preferences"
|
|
11
11
|
: process.env.HOME + "/.local/share"), appName);
|
|
12
12
|
export const prepareOptions = (options) => {
|
|
13
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
13
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
14
14
|
const dataDir = (_a = options.dataDir) !== null && _a !== void 0 ? _a : getAppDataDirPath();
|
|
15
15
|
if (!existsSync(dataDir)) {
|
|
16
16
|
mkdirSync(dataDir);
|
|
@@ -35,7 +35,8 @@ export const prepareOptions = (options) => {
|
|
|
35
35
|
schoolsXmlUrl: (_l = options.schoolsXmlUrl) !== null && _l !== void 0 ? _l : "https://rejstriky.msmt.cz/opendata/vrejcelk.xml",
|
|
36
36
|
schoolsXmlFileName: (_m = options.schoolsXmlFileName) !== null && _m !== void 0 ? _m : "school-register.xml",
|
|
37
37
|
regionsCsvUrl: (_o = options.regionsCsvUrl) !== null && _o !== void 0 ? _o : "https://www.czso.cz/documents/10180/23208674/struktura_uzemi_cr.csv",
|
|
38
|
-
|
|
38
|
+
regionsSchemaUrl: (_p = options.regionsSchemaUrl) !== null && _p !== void 0 ? _p : "https://www.czso.cz/documents/10180/23208674/struktura_uzemi_cr-metadata.json",
|
|
39
|
+
regionsCsvFileName: (_q = options.regionsCsvFileName) !== null && _q !== void 0 ? _q : "struktura_uzemi_cr.csv",
|
|
39
40
|
};
|
|
40
41
|
};
|
|
41
42
|
export const initDb = (options) => {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ConversionResult {
|
|
2
|
+
jtsk_x: number;
|
|
3
|
+
jtsk_y: number;
|
|
4
|
+
lat: number;
|
|
5
|
+
lon: number;
|
|
6
|
+
altitude: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Convert JTSK to WGS84 - taken from @arodax/jtsk2wgs84 package that had some
|
|
10
|
+
* import issues.
|
|
11
|
+
*
|
|
12
|
+
* @param x
|
|
13
|
+
* @param y
|
|
14
|
+
* @param h
|
|
15
|
+
* @return {{jtsk_x: number, jtsk_y: number, lon: number, lat: number, altitude: number}}
|
|
16
|
+
*/
|
|
17
|
+
export default function jtsk2wgs84(x: number, y: number, h?: number): ConversionResult;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert JTSK to WGS84 - taken from @arodax/jtsk2wgs84 package that had some
|
|
3
|
+
* import issues.
|
|
4
|
+
*
|
|
5
|
+
* @param x
|
|
6
|
+
* @param y
|
|
7
|
+
* @param h
|
|
8
|
+
* @return {{jtsk_x: number, jtsk_y: number, lon: number, lat: number, altitude: number}}
|
|
9
|
+
*/
|
|
10
|
+
export default function jtsk2wgs84(x, y, h = 200) {
|
|
11
|
+
const originalX = x;
|
|
12
|
+
const originalY = y;
|
|
13
|
+
let a = 6377397.15508;
|
|
14
|
+
let e = 0.081696831215303;
|
|
15
|
+
let n = 0.97992470462083;
|
|
16
|
+
let uRo = 12310230.12797036;
|
|
17
|
+
let sinUQ = 0.863499969506341;
|
|
18
|
+
let cosUQ = 0.504348889819882;
|
|
19
|
+
let sinVQ = 0.420215144586493;
|
|
20
|
+
let cosVQ = 0.907424504992097;
|
|
21
|
+
let alpha = 1.000597498371542;
|
|
22
|
+
let k = 1.003419163966575;
|
|
23
|
+
let ro = Math.sqrt(x * x + y * y);
|
|
24
|
+
let epsilon = 2 * Math.atan(y / (ro + x));
|
|
25
|
+
let D = epsilon / n;
|
|
26
|
+
let S = 2 * Math.atan(Math.exp((1 / n) * Math.log(uRo / ro))) - Math.PI / 2;
|
|
27
|
+
let sinS = Math.sin(S);
|
|
28
|
+
let cosS = Math.cos(S);
|
|
29
|
+
let sinU = sinUQ * sinS - cosUQ * cosS * Math.cos(D);
|
|
30
|
+
let cosU = Math.sqrt(1 - sinU * sinU);
|
|
31
|
+
let sinDV = (Math.sin(D) * cosS) / cosU;
|
|
32
|
+
let cosDV = Math.sqrt(1 - sinDV * sinDV);
|
|
33
|
+
let sinV = sinVQ * cosDV - cosVQ * sinDV;
|
|
34
|
+
let cosV = cosVQ * cosDV + sinVQ * sinDV;
|
|
35
|
+
let lJtsk = (2 * Math.atan(sinV / (1 + cosV))) / alpha;
|
|
36
|
+
let t = Math.exp((2 / alpha) * Math.log((1 + sinU) / cosU / k));
|
|
37
|
+
let pom = (t - 1) / (t + 1);
|
|
38
|
+
let sinB = pom;
|
|
39
|
+
do {
|
|
40
|
+
sinB = pom;
|
|
41
|
+
pom = t * Math.exp(e * Math.log((1 + e * sinB) / (1 - e * sinB)));
|
|
42
|
+
pom = (pom - 1) / (pom + 1);
|
|
43
|
+
} while (Math.abs(pom - sinB) > 1e-15);
|
|
44
|
+
let bJtsk = Math.atan(pom / Math.sqrt(1 - pom * pom));
|
|
45
|
+
let f1 = 299.152812853;
|
|
46
|
+
let e2 = 1 - (1 - 1 / f1) * (1 - 1 / f1);
|
|
47
|
+
ro = a / Math.sqrt(1 - e2 * Math.sin(bJtsk) * Math.sin(bJtsk));
|
|
48
|
+
x = (ro + h) * Math.cos(bJtsk) * Math.cos(lJtsk);
|
|
49
|
+
y = (ro + h) * Math.cos(bJtsk) * Math.sin(lJtsk);
|
|
50
|
+
let z = ((1 - e2) * ro + h) * Math.sin(bJtsk);
|
|
51
|
+
let dx = 570.69;
|
|
52
|
+
let dy = 85.69;
|
|
53
|
+
let dz = 462.84;
|
|
54
|
+
let wz = ((-5.2611 / 3600) * Math.PI) / 180;
|
|
55
|
+
let wy = ((-1.58676 / 3600) * Math.PI) / 180;
|
|
56
|
+
let wx = ((-4.99821 / 3600) * Math.PI) / 180;
|
|
57
|
+
let m = 3.543e-6;
|
|
58
|
+
let xn = dx + (1 + m) * (x + wz * y - wy * z);
|
|
59
|
+
let yn = dy + (1 + m) * (-wz * x + y + wx * z);
|
|
60
|
+
let zn = dz + (1 + m) * (wy * x - wx * y + z);
|
|
61
|
+
a = 6378137.0;
|
|
62
|
+
f1 = 298.257223563;
|
|
63
|
+
let aB = f1 / (f1 - 1);
|
|
64
|
+
let p = Math.sqrt(xn * xn + yn * yn);
|
|
65
|
+
e2 = 1 - (1 - 1 / f1) * (1 - 1 / f1);
|
|
66
|
+
let theta = Math.atan((zn * aB) / p);
|
|
67
|
+
let st = Math.sin(theta);
|
|
68
|
+
let ct = Math.cos(theta);
|
|
69
|
+
t = (zn + e2 * aB * a * st * st * st) / (p - e2 * a * ct * ct * ct);
|
|
70
|
+
let B = Math.atan(t);
|
|
71
|
+
let L = 2 * Math.atan(yn / (p + xn));
|
|
72
|
+
h = Math.sqrt(1 + t * t) * (p - a / Math.sqrt(1 + (1 - e2) * t * t));
|
|
73
|
+
return {
|
|
74
|
+
jtsk_x: originalX,
|
|
75
|
+
jtsk_y: originalY,
|
|
76
|
+
lat: (B / Math.PI) * 180,
|
|
77
|
+
lon: (L / Math.PI) * 180,
|
|
78
|
+
altitude: Math.round(h * 100) / 100,
|
|
79
|
+
};
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@arodax/jtsk2wgs84": "^1.0.2",
|
|
5
4
|
"@turf/distance": "^6.5.0",
|
|
6
5
|
"adm-zip": "^0.5.9",
|
|
7
6
|
"better-sqlite3": "^8.0.1",
|
|
@@ -30,15 +29,15 @@
|
|
|
30
29
|
"ts-node": "^10.9.1"
|
|
31
30
|
},
|
|
32
31
|
"scripts": {
|
|
32
|
+
"sync-all": "ts-node --experimental-specifier-resolution=node --esm src/bin/sync-all.ts",
|
|
33
33
|
"address-points": "ts-node --experimental-specifier-resolution=node --esm src/bin/address-points.ts",
|
|
34
|
+
"regions": "ts-node --experimental-specifier-resolution=node --esm src/bin/regions.ts",
|
|
34
35
|
"schools": "ts-node --experimental-specifier-resolution=node --esm src/bin/schools.ts",
|
|
36
|
+
"streets": "ts-node --experimental-specifier-resolution=node --esm src/bin/streets.ts",
|
|
37
|
+
"diagrams": "ts-node --experimental-specifier-resolution=node --esm src/bin/generate-syntax-diagrams.ts",
|
|
35
38
|
"clear-all": "ts-node --experimental-specifier-resolution=node --esm src/bin/clear-all.ts",
|
|
36
39
|
"parse-ordinance": "ts-node --experimental-specifier-resolution=node --esm src/bin/parse-ordinance.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",
|
|
40
|
-
"dbf": "ts-node --experimental-specifier-resolution=node --esm src/bin/dbf.ts",
|
|
41
|
-
"test": "jest",
|
|
40
|
+
"test": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js -c=jest-esm.config.mjs --no-cache",
|
|
42
41
|
"ordinance-to-csv-rules": "node src/smd-to-csv/ordinance-to-csv-rules.js",
|
|
43
42
|
"clean": "rimraf dist",
|
|
44
43
|
"copyfiles": "copyfiles -u 1 src/address_points_init.db dist",
|
|
@@ -49,7 +48,7 @@
|
|
|
49
48
|
},
|
|
50
49
|
"name": "text-to-map",
|
|
51
50
|
"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.",
|
|
52
|
-
"version": "1.0.
|
|
51
|
+
"version": "1.0.6",
|
|
53
52
|
"main": "dist/index.js",
|
|
54
53
|
"types": "dist/index.d.ts",
|
|
55
54
|
"files": [
|