text-to-map 1.1.26 → 1.1.28

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.
@@ -1,4 +1,4 @@
1
1
  import { Municipality } from "./types";
2
2
  import { FeatureCollection, MultiPolygon, Polygon } from "@turf/helpers";
3
3
  export declare const municipalityToPolygons: (municipality: Municipality) => Promise<FeatureCollection>;
4
- export declare const createPolygons: (municipality: Municipality, cityPolygons: FeatureCollection<Polygon | MultiPolygon>[]) => FeatureCollection;
4
+ export declare const createPolygons: (municipality: Municipality, cityPolygons: Record<number, FeatureCollection<Polygon | MultiPolygon>>) => FeatureCollection;
@@ -14,13 +14,12 @@ import { toMercator, toWgs84 } from "@turf/projection";
14
14
  import union from "@turf/union";
15
15
  import { getCityPolygonGeojsons } from "../db/cities";
16
16
  import truncate from "@turf/truncate";
17
- const unmappedIzo = "unmapped";
18
17
  export const municipalityToPolygons = (municipality) => __awaiter(void 0, void 0, void 0, function* () {
19
18
  const cityPolygons = yield getCityPolygonGeojsons(municipality.cityCodes);
20
- return createPolygons(municipality, Object.values(cityPolygons));
19
+ return createPolygons(municipality, cityPolygons);
21
20
  });
22
21
  export const createPolygons = (municipality, cityPolygons) => {
23
- const citiesMultipolygon = createCitiesMultipolygon(cityPolygons);
22
+ const citiesMultipolygon = createCitiesMultipolygon(Object.values(cityPolygons));
24
23
  const uniquePoints = new Map();
25
24
  for (const school of municipality.schools) {
26
25
  for (const point of school.addresses) {
@@ -32,9 +31,6 @@ export const createPolygons = (municipality, cityPolygons) => {
32
31
  }
33
32
  }
34
33
  }
35
- for (const point of municipality.unmappedPoints) {
36
- addPoint(uniquePoints, point, unmappedIzo);
37
- }
38
34
  const points = {
39
35
  type: "FeatureCollection",
40
36
  features: Array.from(uniquePoints.values()),
@@ -42,8 +38,12 @@ export const createPolygons = (municipality, cityPolygons) => {
42
38
  const polygons = d3DelaunayVoronoi(points);
43
39
  const unitedPolygons = [];
44
40
  let colorIndex = 0;
45
- for (const school of [...municipality.schools, { izo: unmappedIzo }]) {
41
+ for (const school of municipality.schools) {
46
42
  const schoolPolygons = polygons.features.filter((polygon) => polygon.properties.schools.includes(school.izo));
43
+ if (school.isWholeMunicipality) {
44
+ // TODO: in future add support for districts
45
+ schoolPolygons.push(...cityPolygons[municipality.cityOrDistrictCode].features);
46
+ }
47
47
  if (schoolPolygons.length === 0) {
48
48
  continue;
49
49
  }
@@ -52,7 +52,7 @@ export const createPolygons = (municipality, cityPolygons) => {
52
52
  : schoolPolygons[0], citiesMultipolygon);
53
53
  unitedPolygons.push(Object.assign(Object.assign({}, schoolPolygon), { properties: {
54
54
  schoolIzo: school.izo,
55
- colorIndex: school.izo === unmappedIzo ? -1 : colorIndex,
55
+ colorIndex,
56
56
  } }));
57
57
  colorIndex++;
58
58
  }
@@ -86,15 +86,15 @@ const d3DelaunayVoronoi = (points) => {
86
86
  const voronoi = delaunay.voronoi(bbox);
87
87
  return {
88
88
  type: "FeatureCollection",
89
- features: Array.from(voronoi.cellPolygons()).map((polygon, i) => ({
89
+ features: Array.from(voronoi.cellPolygons()).map((polygon) => ({
90
90
  type: "Feature",
91
91
  geometry: {
92
92
  type: "Polygon",
93
93
  coordinates: [polygon.map((p) => toWgs84(p))],
94
94
  },
95
95
  properties: {
96
- schools: points.features[i].properties.schools,
97
- index: i,
96
+ schools: points.features[polygon.index].properties.schools,
97
+ index: polygon.index,
98
98
  neighbors: new Set(voronoi.neighbors(polygon.index)),
99
99
  },
100
100
  })),
@@ -1,5 +1,5 @@
1
1
  import { Founder } from "../db/types";
2
- import { ErrorCallbackParams, IntermediateMunicipality, IntermediateSchool, Municipality, IntermediateMunicipalityResult, ProcessLineCallbackParams, SmdError, SmdState } from "./types";
2
+ import { ErrorCallbackParams, IntermediateMunicipality, IntermediateMunicipalityResult, IntermediateSchool, Municipality, ProcessLineCallbackParams, SmdError, SmdState } from "./types";
3
3
  interface ParseOrdinanceProps {
4
4
  lines: string[];
5
5
  initialState?: Partial<SmdState>;
@@ -66,11 +66,17 @@ export const convertMunicipality = (municipality) => {
66
66
  name: school.name,
67
67
  izo: school.izo,
68
68
  addresses: Array.from(school.addressMap.values()).filter((point) => point.lat !== 0 && point.lng !== 0),
69
+ isWholeMunicipality: school.isWholeMunicipality,
69
70
  position: school.position,
70
71
  };
71
72
  }),
73
+ cityOrDistrictCode: municipality.founder.cityOrDistrictCode,
74
+ municipalityType: municipality.founder.municipalityType === MunicipalityType.City
75
+ ? "city"
76
+ : "district",
72
77
  cityCodes: [...new Set(municipality.cityCodes)],
73
78
  districtCodes: [...new Set(municipality.districtCodes)],
79
+ wholeMunicipalityPoints: municipality.wholeMunicipalityPoints,
74
80
  unmappedPoints: municipality.unmappedPoints.filter((point) => point.lat !== 0 && point.lng !== 0),
75
81
  };
76
82
  };
@@ -194,11 +200,26 @@ const processWholeMunicipalityLine = ({ line, state, lineNumber, onError, }) =>
194
200
  else {
195
201
  state.currentMunicipality.districtCodes.push(municipality.code);
196
202
  }
197
- const addressPoints = yield findAddressPoints({
198
- type: "wholeMunicipality",
199
- municipality,
200
- });
201
- addAddressPointsToSchool(state.currentSchool, addressPoints, lineNumber);
203
+ if (state.currentMunicipality.founder.cityOrDistrictCode ===
204
+ municipality.code &&
205
+ state.currentMunicipality.founder.municipalityType === municipality.type) {
206
+ // whole municipality, since there is higher likelyhood of multiple schools having
207
+ // the whole municipality area, we will add the address points to the municipality
208
+ if (state.currentMunicipality.wholeMunicipalityPoints.length === 0) {
209
+ state.currentMunicipality.wholeMunicipalityPoints = (yield findAddressPoints({
210
+ type: "wholeMunicipality",
211
+ municipality,
212
+ })).map((point) => mapAddressPointForExport(point));
213
+ }
214
+ state.currentSchool.isWholeMunicipality = true;
215
+ }
216
+ else {
217
+ const addressPoints = yield findAddressPoints({
218
+ type: "wholeMunicipality",
219
+ municipality,
220
+ });
221
+ addAddressPointsToSchool(state.currentSchool, addressPoints, lineNumber);
222
+ }
202
223
  }
203
224
  });
204
225
  const addAddressPointsToSchool = (school, addressPoints, lineNumber) => {
@@ -293,6 +314,9 @@ const addRestOfMunicipalityToUnmappedPoints = (state) => __awaiter(void 0, void
293
314
  state.currentMunicipality.unmappedPoints = (yield getRestOfMunicipality(state)).map((point) => mapAddressPointForExport(point));
294
315
  });
295
316
  const getRestOfMunicipality = (state) => __awaiter(void 0, void 0, void 0, function* () {
317
+ if (state.currentMunicipality.wholeMunicipalityPoints.length > 0) {
318
+ return [];
319
+ }
296
320
  // get all address points for current municipality
297
321
  const allPoints = yield findAddressPoints({
298
322
  type: "wholeMunicipality",
@@ -326,12 +350,15 @@ const getNewMunicipality = (founder, errors) => ({
326
350
  municipalityName: founder ? founder.name : "Neznámá obec",
327
351
  founder,
328
352
  schools: [],
353
+ cityOrDistrictCode: founder ? founder.cityOrDistrictCode : 0,
354
+ municipalityType: founder.municipalityType === MunicipalityType.City ? "city" : "district",
329
355
  cityCodes: founder.municipalityType === MunicipalityType.City
330
356
  ? [founder.cityOrDistrictCode]
331
357
  : [],
332
358
  districtCodes: founder.municipalityType === MunicipalityType.District
333
359
  ? [founder.cityOrDistrictCode]
334
360
  : [],
361
+ wholeMunicipalityPoints: [],
335
362
  unmappedPoints: [],
336
363
  },
337
364
  errors,
@@ -340,6 +367,7 @@ export const getNewSchool = (name, founder, lineNumber, onError) => __awaiter(vo
340
367
  let exportSchool = {
341
368
  name,
342
369
  izo: "",
370
+ isWholeMunicipality: false,
343
371
  addresses: [],
344
372
  };
345
373
  if (founder !== null) {
@@ -353,7 +381,7 @@ export const getNewSchool = (name, founder, lineNumber, onError) => __awaiter(vo
353
381
  if (school.locations.length > 0) {
354
382
  const position = yield getAddressPointById(school.locations[0].addressPointId);
355
383
  if (position !== null) {
356
- exportSchool.position = position;
384
+ exportSchool.position = mapAddressPointForExport(position);
357
385
  }
358
386
  }
359
387
  }
@@ -60,6 +60,7 @@ export interface School {
60
60
  name: string;
61
61
  izo: string;
62
62
  position?: AddressPoint | ExportAddressPoint;
63
+ isWholeMunicipality: boolean;
63
64
  addresses: ExportAddressPoint[];
64
65
  }
65
66
  export interface IntermediateSchool extends School {
@@ -67,9 +68,12 @@ export interface IntermediateSchool extends School {
67
68
  }
68
69
  export interface Municipality {
69
70
  municipalityName: string;
71
+ cityOrDistrictCode: number;
72
+ municipalityType: "city" | "district";
70
73
  cityCodes: number[];
71
74
  districtCodes: number[];
72
75
  schools: School[];
76
+ wholeMunicipalityPoints: ExportAddressPoint[];
73
77
  unmappedPoints: ExportAddressPoint[];
74
78
  }
75
79
  export interface DbMunicipalityResult {
package/package.json CHANGED
@@ -43,21 +43,21 @@
43
43
  "npm-run-all": "^1.7.0",
44
44
  "rimraf": "^5.0.1",
45
45
  "ts-jest": "^29.1.1",
46
- "ts-node": "^10.9.1"
46
+ "tsx": "^4.7.1"
47
47
  },
48
48
  "scripts": {
49
- "sync-all": "ts-node --experimental-specifier-resolution=node --esm src/bin/sync-all.ts",
50
- "address-points": "ts-node --experimental-specifier-resolution=node --esm src/bin/address-points.ts",
51
- "regions": "ts-node --experimental-specifier-resolution=node --esm src/bin/regions.ts",
52
- "cities": "ts-node --experimental-specifier-resolution=node --esm src/bin/cities.ts",
53
- "polygons": "ts-node --experimental-specifier-resolution=node --esm src/bin/polygons.ts",
54
- "schools": "ts-node --experimental-specifier-resolution=node --esm src/bin/schools.ts",
55
- "streets": "ts-node --experimental-specifier-resolution=node --esm src/bin/streets.ts",
56
- "diagrams": "ts-node --experimental-specifier-resolution=node --esm src/bin/generate-syntax-diagrams.ts",
57
- "clear-all": "ts-node --experimental-specifier-resolution=node --esm src/bin/clear-all.ts",
58
- "init-db": "ts-node --experimental-specifier-resolution=node --esm src/bin/init-db.ts",
59
- "parse-ordinance": "ts-node --experimental-specifier-resolution=node --esm src/bin/parse-ordinance.ts",
60
- "knex": "ts-node --experimental-specifier-resolution=node --esm src/bin/knex.ts",
49
+ "sync-all": "tsx src/bin/sync-all.ts",
50
+ "address-points": "tsx src/bin/address-points.ts",
51
+ "regions": "tsx src/bin/regions.ts",
52
+ "cities": "tsx src/bin/cities.ts",
53
+ "polygons": "tsx src/bin/polygons.ts",
54
+ "schools": "tsx src/bin/schools.ts",
55
+ "streets": "tsx src/bin/streets.ts",
56
+ "diagrams": "tsx src/bin/generate-syntax-diagrams.ts",
57
+ "clear-all": "tsx src/bin/clear-all.ts",
58
+ "init-db": "tsx src/bin/init-db.ts",
59
+ "parse-ordinance": "tsx src/bin/parse-ordinance.ts",
60
+ "knex": "tsx src/bin/knex.ts",
61
61
  "test": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js -c=jest-esm.config.mjs --no-cache",
62
62
  "ordinance-to-csv-rules": "node src/smd-to-csv/ordinance-to-csv-rules.js",
63
63
  "clean": "rimraf dist",
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "name": "text-to-map",
71
71
  "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.",
72
- "version": "1.1.26",
72
+ "version": "1.1.28",
73
73
  "main": "dist/index.js",
74
74
  "types": "dist/index.d.ts",
75
75
  "files": [