text-to-map 1.1.24 → 1.1.25

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.
@@ -14,6 +14,7 @@ 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";
17
18
  export const municipalityToPolygons = (municipality) => __awaiter(void 0, void 0, void 0, function* () {
18
19
  const cityPolygons = yield getCityPolygonGeojsons(municipality.cityCodes);
19
20
  return createPolygons(municipality, Object.values(cityPolygons));
@@ -24,16 +25,7 @@ export const createPolygons = (municipality, cityPolygons) => {
24
25
  for (const school of municipality.schools) {
25
26
  for (const point of school.addresses) {
26
27
  if (!uniquePoints.has(point.address)) {
27
- uniquePoints.set(point.address, {
28
- type: "Feature",
29
- geometry: {
30
- type: "Point",
31
- coordinates: [point.lng, point.lat],
32
- },
33
- properties: {
34
- schools: [school.izo],
35
- },
36
- });
28
+ addPoint(uniquePoints, point, school.izo);
37
29
  }
38
30
  else {
39
31
  uniquePoints.get(point.address).properties.schools.push(school.izo);
@@ -41,16 +33,7 @@ export const createPolygons = (municipality, cityPolygons) => {
41
33
  }
42
34
  }
43
35
  for (const point of municipality.unmappedPoints) {
44
- uniquePoints.set(point.address, {
45
- type: "Feature",
46
- geometry: {
47
- type: "Point",
48
- coordinates: [point.lng, point.lat],
49
- },
50
- properties: {
51
- schools: ["unmapped"],
52
- },
53
- });
36
+ addPoint(uniquePoints, point, unmappedIzo);
54
37
  }
55
38
  const points = {
56
39
  type: "FeatureCollection",
@@ -59,7 +42,7 @@ export const createPolygons = (municipality, cityPolygons) => {
59
42
  const polygons = d3DelaunayVoronoi(points);
60
43
  const unitedPolygons = [];
61
44
  let colorIndex = 0;
62
- for (const school of [...municipality.schools, { izo: "unmapped" }]) {
45
+ for (const school of [...municipality.schools, { izo: unmappedIzo }]) {
63
46
  const schoolPolygons = polygons.features.filter((polygon) => polygon.properties.schools.includes(school.izo));
64
47
  if (schoolPolygons.length === 0) {
65
48
  continue;
@@ -69,7 +52,7 @@ export const createPolygons = (municipality, cityPolygons) => {
69
52
  : schoolPolygons[0], citiesMultipolygon);
70
53
  unitedPolygons.push(Object.assign(Object.assign({}, schoolPolygon), { properties: {
71
54
  schoolIzo: school.izo,
72
- colorIndex: school.izo === "unmapped" ? -1 : colorIndex,
55
+ colorIndex: school.izo === unmappedIzo ? -1 : colorIndex,
73
56
  } }));
74
57
  colorIndex++;
75
58
  }
@@ -79,8 +62,25 @@ export const createPolygons = (municipality, cityPolygons) => {
79
62
  features: [...unitedPolygons],
80
63
  });
81
64
  };
65
+ const addPoint = (uniquePoints, point, schoolIzo) => {
66
+ if (point.lat === null || point.lng === null) {
67
+ return;
68
+ }
69
+ uniquePoints.set(point.address, {
70
+ type: "Feature",
71
+ geometry: {
72
+ type: "Point",
73
+ coordinates: [point.lng, point.lat],
74
+ },
75
+ properties: {
76
+ schools: [schoolIzo],
77
+ },
78
+ });
79
+ };
82
80
  const d3DelaunayVoronoi = (points) => {
83
- const converted = points.features.map((p) => toMercator([p.geometry.coordinates[0], p.geometry.coordinates[1]]));
81
+ const converted = points.features.map((p) => {
82
+ return toMercator([p.geometry.coordinates[0], p.geometry.coordinates[1]]);
83
+ });
84
84
  const bbox = [...toMercator([-180, -85]), ...toMercator([180, 85])];
85
85
  const delaunay = new Delaunay(Float64Array.of(...converted.flat()));
86
86
  const voronoi = delaunay.voronoi(bbox);
@@ -65,7 +65,7 @@ export const convertMunicipality = (municipality) => {
65
65
  return {
66
66
  name: school.name,
67
67
  izo: school.izo,
68
- addresses: Array.from(school.addressMap.values()),
68
+ addresses: Array.from(school.addressMap.values()).filter((point) => point.lat !== null && point.lng !== null),
69
69
  position: school.position,
70
70
  };
71
71
  }),
package/package.json CHANGED
@@ -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.24",
72
+ "version": "1.1.25",
73
73
  "main": "dist/index.js",
74
74
  "types": "dist/index.d.ts",
75
75
  "files": [