text-to-map 1.1.21 → 1.1.23

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.
@@ -13,6 +13,7 @@ import intersect from "@turf/intersect";
13
13
  import { toMercator, toWgs84 } from "@turf/projection";
14
14
  import union from "@turf/union";
15
15
  import { getCityPolygonGeojsons } from "../db/cities";
16
+ import truncate from "@turf/truncate";
16
17
  export const municipalityToPolygons = (municipality) => __awaiter(void 0, void 0, void 0, function* () {
17
18
  const cityPolygons = yield getCityPolygonGeojsons(municipality.cityCodes);
18
19
  return createPolygons(municipality, Object.values(cityPolygons));
@@ -39,6 +40,18 @@ export const createPolygons = (municipality, cityPolygons) => {
39
40
  }
40
41
  }
41
42
  }
43
+ 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
+ });
54
+ }
42
55
  const points = {
43
56
  type: "FeatureCollection",
44
57
  features: Array.from(uniquePoints.values()),
@@ -46,22 +59,23 @@ export const createPolygons = (municipality, cityPolygons) => {
46
59
  const polygons = d3DelaunayVoronoi(points);
47
60
  const unitedPolygons = [];
48
61
  let colorIndex = 0;
49
- for (const school of municipality.schools) {
62
+ const unmapped = municipality.unmappedPoints.length > 0 ? [{ izo: "unmapped" }] : [];
63
+ for (const school of [...municipality.schools, ...unmapped]) {
50
64
  const schoolPolygons = polygons.features.filter((polygon) => polygon.properties.schools.includes(school.izo));
51
65
  const schoolPolygon = intersect(schoolPolygons.length > 1
52
66
  ? union(featureCollection(schoolPolygons))
53
67
  : schoolPolygons[0], citiesMultipolygon);
54
68
  unitedPolygons.push(Object.assign(Object.assign({}, schoolPolygon), { properties: {
55
69
  schoolIzo: school.izo,
56
- colorIndex,
70
+ colorIndex: school.izo === "unmapped" ? -1 : colorIndex,
57
71
  } }));
58
72
  colorIndex++;
59
73
  }
60
74
  const { type } = polygons;
61
- return {
75
+ return truncate({
62
76
  type,
63
77
  features: [...unitedPolygons],
64
- };
78
+ });
65
79
  };
66
80
  const d3DelaunayVoronoi = (points) => {
67
81
  const converted = points.features.map((p) => toMercator([p.geometry.coordinates[0], p.geometry.coordinates[1]]));
@@ -290,7 +290,7 @@ const addRestOfMunicipality = (lineNumber, state) => __awaiter(void 0, void 0, v
290
290
  addRestToSchool(yield getRestOfMunicipality(state), state.rests.wholeMunicipalitySchool.izo, lineNumber, state);
291
291
  });
292
292
  const addRestOfMunicipalityToUnmappedPoints = (state) => __awaiter(void 0, void 0, void 0, function* () {
293
- state.currentMunicipality.unmappedPoints = (yield getRestOfMunicipality(state)).map(mapAddressPointForExport);
293
+ state.currentMunicipality.unmappedPoints = (yield getRestOfMunicipality(state)).map((point) => mapAddressPointForExport(point));
294
294
  });
295
295
  const getRestOfMunicipality = (state) => __awaiter(void 0, void 0, void 0, function* () {
296
296
  // get all address points for current municipality
@@ -370,7 +370,7 @@ const getAllAddressPointsIds = (municipality) => {
370
370
  return addressPointsIds;
371
371
  };
372
372
  const mapAddressPointForExport = (addressPoint, lineNumber) => {
373
- return Object.assign({ address: addressPoint.address, lat: addressPoint.lat, lng: addressPoint.lng }, (lineNumber ? { lineNumbers: [lineNumber - 1] } : {}));
373
+ return Object.assign({ address: addressPoint.address, lat: roundToNDecimalPlaces(addressPoint.lat, 6), lng: roundToNDecimalPlaces(addressPoint.lng, 6) }, (lineNumber !== undefined ? { lineNumbers: [lineNumber - 1] } : {}));
374
374
  };
375
375
  const mapSchoolForExport = (school) => (Object.assign(Object.assign({}, school), { position: school.position ? mapAddressPointForExport(school.position) : null }));
376
376
  const cleanLine = (line) => {
@@ -381,3 +381,7 @@ export const wholeLineError = (message, line) => ({
381
381
  startOffset: 0,
382
382
  endOffset: line.length + 1,
383
383
  });
384
+ const roundToNDecimalPlaces = (toRound, decimalPlaces) => {
385
+ return (Math.round(toRound * Math.pow(10, decimalPlaces)) /
386
+ Math.pow(10, decimalPlaces));
387
+ };
package/package.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "@turf/intersect": "^6.5.0",
7
7
  "@turf/meta": "^7.0.0-alpha.110",
8
8
  "@turf/projection": "^7.0.0-alpha.2",
9
+ "@turf/truncate": "^6.5.0",
9
10
  "@turf/union": "^7.0.0-alpha.113",
10
11
  "adm-zip": "^0.5.9",
11
12
  "better-sqlite3": "^8.0.1",
@@ -68,7 +69,7 @@
68
69
  },
69
70
  "name": "text-to-map",
70
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.",
71
- "version": "1.1.21",
72
+ "version": "1.1.23",
72
73
  "main": "dist/index.js",
73
74
  "types": "dist/index.d.ts",
74
75
  "files": [