@osmix/geojson 0.0.7 → 0.0.10

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,65 +0,0 @@
1
- /**
2
- * GeoJSON-to-OSM conversion utilities.
3
- *
4
- * Imports GeoJSON FeatureCollections into Osm indexes, mapping geometry
5
- * types to appropriate OSM entity structures.
6
- *
7
- * @module
8
- */
9
- import { Osm, type OsmOptions } from "@osmix/core";
10
- import { type ProgressEvent } from "@osmix/shared/progress";
11
- import type { FeatureCollection, LineString, MultiPolygon, Point, Polygon } from "geojson";
12
- import type { ReadOsmDataTypes } from "./types";
13
- /**
14
- * Create an Osm index from GeoJSON data.
15
- *
16
- * Accepts various input formats (string, stream, buffer, or parsed object)
17
- * and converts features to OSM entities:
18
- * - Point → Node
19
- * - LineString → Way with nodes
20
- * - Polygon → Way (simple) or Relation (with holes)
21
- * - MultiPolygon → Relation
22
- *
23
- * Feature IDs are preserved if numeric; otherwise sequential negative IDs are assigned.
24
- * Feature properties become OSM tags.
25
- *
26
- * @param data - GeoJSON data in any supported format.
27
- * @param options - Osm index options (id, header).
28
- * @param onProgress - Progress callback for UI feedback.
29
- * @returns Populated Osm index with built indexes.
30
- *
31
- * @example
32
- * ```ts
33
- * import { fromGeoJSON } from "@osmix/geojson"
34
- *
35
- * // From file
36
- * const geojson = await Bun.file('./roads.geojson').json()
37
- * const osm = await fromGeoJSON(geojson, { id: "roads" })
38
- *
39
- * // Query the imported data
40
- * const highways = osm.ways.search("highway")
41
- * ```
42
- */
43
- export declare function fromGeoJSON(data: ReadOsmDataTypes, options?: Partial<OsmOptions>, onProgress?: (progress: ProgressEvent) => void): Promise<Osm>;
44
- /**
45
- * Generator that converts GeoJSON features to OSM entities.
46
- *
47
- * This is the core conversion logic, yielding progress events as features
48
- * are processed. Called by `fromGeoJSON` with progress handling.
49
- *
50
- * Geometry mapping:
51
- * - **Point**: Creates a single node with feature properties as tags.
52
- * - **LineString**: Creates nodes for each coordinate, then a way referencing them.
53
- * - **Polygon**: Creates a way for simple polygons; for polygons with holes,
54
- * creates separate ways for outer and inner rings plus a multipolygon relation.
55
- * - **MultiPolygon**: Creates a multipolygon relation with all rings as way members.
56
- *
57
- * Coordinates are normalized using `rewind` to ensure correct winding order
58
- * (outer rings counterclockwise, inner rings clockwise per OSM conventions).
59
- *
60
- * @param osm - Target Osm index to populate.
61
- * @param geojson - Parsed GeoJSON FeatureCollection.
62
- * @yields Progress events during conversion.
63
- */
64
- export declare function startCreateOsmFromGeoJSON(osm: Osm, geojson: FeatureCollection<Point | LineString | Polygon | MultiPolygon>): Generator<ProgressEvent>;
65
- //# sourceMappingURL=osm-from-geojson.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"osm-from-geojson.d.ts","sourceRoot":"","sources":["../../src/osm-from-geojson.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,GAAG,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAEN,KAAK,aAAa,EAElB,MAAM,wBAAwB,CAAA;AAG/B,OAAO,KAAK,EACX,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,KAAK,EACL,OAAO,EACP,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,WAAW,CAChC,IAAI,EAAE,gBAAgB,EACtB,OAAO,GAAE,OAAO,CAAC,UAAU,CAAM,EACjC,UAAU,GAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAkB,GACzD,OAAO,CAAC,GAAG,CAAC,CASd;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAiB,yBAAyB,CACzC,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,iBAAiB,CAAC,KAAK,GAAG,UAAU,GAAG,OAAO,GAAG,YAAY,CAAC,GACrE,SAAS,CAAC,aAAa,CAAC,CAsO1B"}
@@ -1,303 +0,0 @@
1
- /**
2
- * GeoJSON-to-OSM conversion utilities.
3
- *
4
- * Imports GeoJSON FeatureCollections into Osm indexes, mapping geometry
5
- * types to appropriate OSM entity structures.
6
- *
7
- * @module
8
- */
9
- import { Osm } from "@osmix/core";
10
- import { logProgress, progressEvent, } from "@osmix/shared/progress";
11
- import { rewindFeature } from "@placemarkio/geojson-rewind";
12
- import { readDataAsGeoJSON } from "./utils";
13
- /**
14
- * Create an Osm index from GeoJSON data.
15
- *
16
- * Accepts various input formats (string, stream, buffer, or parsed object)
17
- * and converts features to OSM entities:
18
- * - Point → Node
19
- * - LineString → Way with nodes
20
- * - Polygon → Way (simple) or Relation (with holes)
21
- * - MultiPolygon → Relation
22
- *
23
- * Feature IDs are preserved if numeric; otherwise sequential negative IDs are assigned.
24
- * Feature properties become OSM tags.
25
- *
26
- * @param data - GeoJSON data in any supported format.
27
- * @param options - Osm index options (id, header).
28
- * @param onProgress - Progress callback for UI feedback.
29
- * @returns Populated Osm index with built indexes.
30
- *
31
- * @example
32
- * ```ts
33
- * import { fromGeoJSON } from "@osmix/geojson"
34
- *
35
- * // From file
36
- * const geojson = await Bun.file('./roads.geojson').json()
37
- * const osm = await fromGeoJSON(geojson, { id: "roads" })
38
- *
39
- * // Query the imported data
40
- * const highways = osm.ways.search("highway")
41
- * ```
42
- */
43
- export async function fromGeoJSON(data, options = {}, onProgress = logProgress) {
44
- const osm = new Osm(options);
45
- for (const update of startCreateOsmFromGeoJSON(osm, await readDataAsGeoJSON(data))) {
46
- onProgress(update);
47
- }
48
- return osm;
49
- }
50
- /**
51
- * Generator that converts GeoJSON features to OSM entities.
52
- *
53
- * This is the core conversion logic, yielding progress events as features
54
- * are processed. Called by `fromGeoJSON` with progress handling.
55
- *
56
- * Geometry mapping:
57
- * - **Point**: Creates a single node with feature properties as tags.
58
- * - **LineString**: Creates nodes for each coordinate, then a way referencing them.
59
- * - **Polygon**: Creates a way for simple polygons; for polygons with holes,
60
- * creates separate ways for outer and inner rings plus a multipolygon relation.
61
- * - **MultiPolygon**: Creates a multipolygon relation with all rings as way members.
62
- *
63
- * Coordinates are normalized using `rewind` to ensure correct winding order
64
- * (outer rings counterclockwise, inner rings clockwise per OSM conventions).
65
- *
66
- * @param osm - Target Osm index to populate.
67
- * @param geojson - Parsed GeoJSON FeatureCollection.
68
- * @yields Progress events during conversion.
69
- */
70
- export function* startCreateOsmFromGeoJSON(osm, geojson) {
71
- yield progressEvent("Converting GeoJSON to Osmix...");
72
- // Map to track nodes by coordinate string for reuse when creating ways and relations
73
- const nodeMap = new Map();
74
- let nextNodeId = -1;
75
- let nextWayId = -1;
76
- let nextRelationId = -1;
77
- // Helper to get or create a node for a coordinate
78
- const getOrCreateNode = (lon, lat) => {
79
- const coordKey = `${lon},${lat}`;
80
- const existingNodeId = nodeMap.get(coordKey);
81
- if (existingNodeId !== undefined) {
82
- return existingNodeId;
83
- }
84
- const nodeId = nextNodeId--;
85
- nodeMap.set(coordKey, nodeId);
86
- osm.nodes.addNode({
87
- id: nodeId,
88
- lon,
89
- lat,
90
- });
91
- return nodeId;
92
- };
93
- // Process each feature
94
- let count = 0;
95
- for (const feature of geojson.features) {
96
- // Normalize winding order using rewind (outer rings counterclockwise, inner rings clockwise)
97
- const normalizedFeature = rewindFeature(feature);
98
- const tags = propertiesToTags(normalizedFeature.properties);
99
- const featureId = extractFeatureId(normalizedFeature.id);
100
- if (normalizedFeature.geometry?.type === "Point") {
101
- const [lon, lat] = normalizedFeature.geometry.coordinates;
102
- if (lon === undefined || lat === undefined)
103
- throw Error("Invalid GeoJSON coordinates in Point.");
104
- const nodeId = featureId ?? nextNodeId--;
105
- osm.nodes.addNode({
106
- id: nodeId,
107
- lon,
108
- lat,
109
- tags,
110
- });
111
- nodeMap.set(`${lon},${lat}`, nodeId);
112
- }
113
- else if (normalizedFeature.geometry?.type === "LineString") {
114
- const coordinates = normalizedFeature.geometry.coordinates;
115
- if (coordinates.length < 2)
116
- throw Error("Invalid GeoJSON coordinates in LineString.");
117
- // Create or get nodes for each coordinate
118
- const nodeRefs = [];
119
- for (const [lon, lat] of coordinates) {
120
- if (lon === undefined || lat === undefined)
121
- throw Error("Invalid GeoJSON coordinates in LineString.");
122
- const nodeId = getOrCreateNode(lon, lat);
123
- nodeRefs.push(nodeId);
124
- }
125
- // Create the way
126
- const wayId = featureId ?? nextWayId--;
127
- osm.ways.addWay({
128
- id: wayId,
129
- refs: nodeRefs,
130
- tags,
131
- });
132
- }
133
- else if (normalizedFeature.geometry?.type === "Polygon") {
134
- const coordinates = normalizedFeature.geometry.coordinates;
135
- if (coordinates.length === 0)
136
- continue;
137
- // If the polygon contains holes, create a relation
138
- const createRelation = coordinates.length > 1;
139
- // First ring is outer boundary, subsequent rings are holes
140
- const outerRing = coordinates[0];
141
- if (!outerRing || outerRing.length < 3)
142
- continue; // Need at least 3 points for a polygon
143
- // Create nodes for outer ring
144
- const outerNodeRefs = [];
145
- for (const [lon, lat] of outerRing) {
146
- if (lon === undefined || lat === undefined)
147
- throw Error("Invalid GeoJSON coordinates in Polygon.");
148
- const nodeId = getOrCreateNode(lon, lat);
149
- outerNodeRefs.push(nodeId);
150
- }
151
- // Ensure the outer ring is closed (first and last node are the same)
152
- if (outerNodeRefs[0] !== outerNodeRefs[outerNodeRefs.length - 1])
153
- throw Error("Outer ring of Polygon is not closed.");
154
- // Create way for outer ring with area tags
155
- const outerWayId = createRelation
156
- ? nextWayId--
157
- : (featureId ?? nextWayId--);
158
- osm.ways.addWay({
159
- id: outerWayId,
160
- refs: outerNodeRefs,
161
- tags: createRelation ? { area: "yes" } : { area: "yes", ...tags },
162
- });
163
- // Create separate ways for holes
164
- const holeWayIds = [];
165
- for (let i = 1; i < coordinates.length; i++) {
166
- const holeRing = coordinates[i];
167
- if (!holeRing || holeRing.length < 3)
168
- throw Error("Hole ring of Polygon has less than 3 coordinates.");
169
- const holeNodeRefs = [];
170
- for (const [lon, lat] of holeRing) {
171
- if (lon === undefined || lat === undefined)
172
- throw Error("Invalid GeoJSON coordinates in Polygon.");
173
- const nodeId = getOrCreateNode(lon, lat);
174
- holeNodeRefs.push(nodeId);
175
- }
176
- // Ensure the ring is closed
177
- if (holeNodeRefs[0] !== holeNodeRefs[holeNodeRefs.length - 1])
178
- throw Error("Hole ring of Polygon is not closed.");
179
- // Create way for hole
180
- const holeWayId = nextWayId--;
181
- osm.ways.addWay({
182
- id: holeWayId,
183
- refs: holeNodeRefs,
184
- tags: { area: "yes" },
185
- });
186
- holeWayIds.push(holeWayId);
187
- }
188
- if (createRelation) {
189
- osm.relations.addRelation({
190
- id: featureId ?? nextRelationId--,
191
- members: [
192
- { type: "way", ref: outerWayId, role: "outer" },
193
- ...holeWayIds.map((id) => ({ type: "way", ref: id, role: "inner" })),
194
- ],
195
- tags: {
196
- type: "multipolygon",
197
- ...tags,
198
- },
199
- });
200
- }
201
- }
202
- else if (normalizedFeature.geometry?.type === "MultiPolygon") {
203
- const coordinates = normalizedFeature.geometry.coordinates;
204
- if (coordinates.length === 0)
205
- continue;
206
- // Process each polygon in the MultiPolygon
207
- const relationMembers = [];
208
- for (const polygon of coordinates) {
209
- if (polygon.length === 0)
210
- continue;
211
- const outerRing = polygon[0];
212
- if (!outerRing || outerRing.length < 3)
213
- continue;
214
- // Create nodes for outer ring
215
- const outerNodeRefs = [];
216
- for (const [lon, lat] of outerRing) {
217
- if (lon === undefined || lat === undefined)
218
- throw Error("Invalid GeoJSON coordinates in Polygon.");
219
- const nodeId = getOrCreateNode(lon, lat);
220
- outerNodeRefs.push(nodeId);
221
- }
222
- // Ensure the ring is closed
223
- if (outerNodeRefs[0] !== outerNodeRefs[outerNodeRefs.length - 1])
224
- throw Error("Outer ring of Polygon is not closed.");
225
- // Create way for outer ring
226
- const outerWayId = nextWayId--;
227
- osm.ways.addWay({
228
- id: outerWayId,
229
- refs: outerNodeRefs,
230
- tags: { area: "yes" },
231
- });
232
- relationMembers.push({ type: "way", ref: outerWayId, role: "outer" });
233
- // Create separate ways for holes in this polygon
234
- for (let i = 1; i < polygon.length; i++) {
235
- const holeRing = polygon[i];
236
- if (!holeRing || holeRing.length < 3)
237
- throw Error("Hole ring of Polygon has less than 3 coordinates.");
238
- const holeNodeRefs = [];
239
- for (const [lon, lat] of holeRing) {
240
- if (lon === undefined || lat === undefined)
241
- throw Error("Invalid GeoJSON coordinates in Polygon.");
242
- const nodeId = getOrCreateNode(lon, lat);
243
- holeNodeRefs.push(nodeId);
244
- }
245
- // Ensure the ring is closed
246
- if (holeNodeRefs[0] !== holeNodeRefs[holeNodeRefs.length - 1])
247
- throw Error("Hole ring of Polygon is not closed.");
248
- const holeWayId = nextWayId--;
249
- osm.ways.addWay({
250
- id: holeWayId,
251
- refs: holeNodeRefs,
252
- tags: { area: "yes" },
253
- });
254
- relationMembers.push({ type: "way", ref: holeWayId, role: "inner" });
255
- }
256
- }
257
- if (relationMembers.length > 0) {
258
- osm.relations.addRelation({
259
- id: featureId ?? nextRelationId--,
260
- members: relationMembers,
261
- tags: { type: "multipolygon", ...tags },
262
- });
263
- }
264
- }
265
- yield progressEvent(`Processed ${count++} features...`);
266
- }
267
- yield progressEvent("Finished converting GeoJSON to Osmix, building indexes...");
268
- // Build indexes
269
- osm.buildIndexes();
270
- osm.buildSpatialIndexes();
271
- }
272
- // Helper to convert properties to tags
273
- function propertiesToTags(properties) {
274
- if (!properties || Object.keys(properties).length === 0) {
275
- return undefined;
276
- }
277
- const tags = {};
278
- for (const [key, value] of Object.entries(properties)) {
279
- // Convert value to string or number
280
- if (typeof value === "string" || typeof value === "number") {
281
- tags[key] = value;
282
- }
283
- else if (value != null) {
284
- // Convert other types to string
285
- tags[key] = String(value);
286
- }
287
- }
288
- return Object.keys(tags).length > 0 ? tags : undefined;
289
- }
290
- // Helper to extract numeric ID from feature
291
- function extractFeatureId(featureId) {
292
- if (featureId === undefined)
293
- return undefined;
294
- if (typeof featureId === "number")
295
- return featureId;
296
- if (typeof featureId === "string") {
297
- const numId = Number.parseInt(featureId, 10);
298
- if (!Number.isNaN(numId))
299
- return numId;
300
- }
301
- return undefined;
302
- }
303
- //# sourceMappingURL=osm-from-geojson.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"osm-from-geojson.js","sourceRoot":"","sources":["../../src/osm-from-geojson.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,GAAG,EAAmB,MAAM,aAAa,CAAA;AAClD,OAAO,EACN,WAAW,EAEX,aAAa,GACb,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAS3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,IAAsB,EACtB,UAA+B,EAAE,EACjC,aAAgD,WAAW;IAE3D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;IAC5B,KAAK,MAAM,MAAM,IAAI,yBAAyB,CAC7C,GAAG,EACH,MAAM,iBAAiB,CAAC,IAAI,CAAC,CAC7B,EAAE,CAAC;QACH,UAAU,CAAC,MAAM,CAAC,CAAA;IACnB,CAAC;IACD,OAAO,GAAG,CAAA;AACX,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,SAAS,CAAC,CAAC,yBAAyB,CACzC,GAAQ,EACR,OAAuE;IAEvE,MAAM,aAAa,CAAC,gCAAgC,CAAC,CAAA;IAErD,qFAAqF;IACrF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAA;IACzC,IAAI,UAAU,GAAG,CAAC,CAAC,CAAA;IACnB,IAAI,SAAS,GAAG,CAAC,CAAC,CAAA;IAClB,IAAI,cAAc,GAAG,CAAC,CAAC,CAAA;IAEvB,kDAAkD;IAClD,MAAM,eAAe,GAAG,CAAC,GAAW,EAAE,GAAW,EAAU,EAAE;QAC5D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M,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AACvD,CAAC;AAED,4CAA4C;AAC5C,SAAS,gBAAgB,CACxB,SAAsC;IAEtC,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC7C,IAAI,OAAO,SAAS,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IACnD,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;QAC5C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;IACvC,CAAC;IACD,OAAO,SAAS,CAAA;AACjB,CAAC"}
@@ -1,49 +0,0 @@
1
- /**
2
- * Type definitions for OSM-GeoJSON conversion.
3
- * @module
4
- */
5
- import type { OsmEntityType, OsmInfoParsed, OsmTags } from "@osmix/shared/types";
6
- import type { Feature, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon } from "geojson";
7
- /**
8
- * GeoJSON Feature properties for OSM entities.
9
- *
10
- * Includes the OSM entity ID, type, and optionally tags and metadata.
11
- * All OSM tags are spread into the properties object.
12
- */
13
- export type OsmGeoJSONProperties = {
14
- /** OSM entity ID. */
15
- id: number;
16
- /** Entity type: "node", "way", or "relation". */
17
- type: OsmEntityType;
18
- /** OSM tags (key-value pairs). */
19
- tags?: OsmTags;
20
- /** Entity metadata (version, timestamp, user, etc.). */
21
- info?: OsmInfoParsed;
22
- };
23
- /**
24
- * GeoJSON Feature with OSM-specific properties.
25
- *
26
- * Generic over geometry type to support all OSM entity conversions:
27
- * - Nodes → Point
28
- * - Ways → LineString or Polygon
29
- * - Relations → MultiPolygon, MultiLineString, MultiPoint, or GeometryCollection
30
- */
31
- export type OsmGeoJSONFeature<T extends Point | LineString | Polygon | MultiPolygon | MultiLineString | MultiPoint | GeometryCollection> = Feature<T, OsmGeoJSONProperties>;
32
- /**
33
- * GeoJSON FeatureCollection types that can be imported into an Osm index.
34
- *
35
- * Supports Point, LineString, Polygon, and MultiPolygon geometries.
36
- * Other geometry types are not supported for import.
37
- */
38
- export type ImportableGeoJSON = GeoJSON.FeatureCollection<GeoJSON.Point | GeoJSON.LineString | GeoJSON.Polygon | GeoJSON.MultiPolygon>;
39
- /**
40
- * Input types accepted by `fromGeoJSON`.
41
- *
42
- * Supports multiple formats:
43
- * - `ArrayBufferLike` - Binary GeoJSON data
44
- * - `ReadableStream` - Streaming GeoJSON
45
- * - `string` - JSON string
46
- * - `ImportableGeoJSON` - Already-parsed FeatureCollection
47
- */
48
- export type ReadOsmDataTypes = ArrayBufferLike | ReadableStream | string | ImportableGeoJSON;
49
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,KAAK,EACX,OAAO,EACP,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,UAAU,EACV,YAAY,EACZ,KAAK,EACL,OAAO,EACP,MAAM,SAAS,CAAA;AAEhB;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAClC,qBAAqB;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,iDAAiD;IACjD,IAAI,EAAE,aAAa,CAAA;IACnB,kCAAkC;IAClC,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,wDAAwD;IACxD,IAAI,CAAC,EAAE,aAAa,CAAA;CACpB,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,CAC5B,CAAC,SACE,KAAK,GACL,UAAU,GACV,OAAO,GACP,YAAY,GACZ,eAAe,GACf,UAAU,GACV,kBAAkB,IAClB,OAAO,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAA;AAEpC;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CACxD,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,YAAY,CAC3E,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,GACzB,eAAe,GACf,cAAc,GACd,MAAM,GACN,iBAAiB,CAAA"}
package/dist/src/types.js DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Type definitions for OSM-GeoJSON conversion.
3
- * @module
4
- */
5
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -1,30 +0,0 @@
1
- /**
2
- * Utility functions for GeoJSON data handling.
3
- * @module
4
- */
5
- import type { ImportableGeoJSON, ReadOsmDataTypes } from "./types";
6
- /**
7
- * Parse GeoJSON from various input formats.
8
- *
9
- * Supports multiple input types for flexibility:
10
- * - **string**: JSON string to parse
11
- * - **ReadableStream**: Streaming JSON data
12
- * - **ArrayBuffer/SharedArrayBuffer**: Binary data to decode and parse
13
- * - **Object**: Already-parsed FeatureCollection (passed through)
14
- *
15
- * @param data - GeoJSON data in any supported format.
16
- * @returns Parsed GeoJSON FeatureCollection.
17
- * @throws If data is null or an unsupported type.
18
- *
19
- * @example
20
- * ```ts
21
- * // From string
22
- * const geojson = await readDataAsGeoJSON('{"type":"FeatureCollection","features":[]}')
23
- *
24
- * // From fetch response
25
- * const response = await fetch('/data.geojson')
26
- * const geojson = await readDataAsGeoJSON(response.body!)
27
- * ```
28
- */
29
- export declare function readDataAsGeoJSON(data: ReadOsmDataTypes): Promise<ImportableGeoJSON>;
30
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAElE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,iBAAiB,CACtC,IAAI,EAAE,gBAAgB,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAyB5B"}
package/dist/src/utils.js DELETED
@@ -1,54 +0,0 @@
1
- /**
2
- * Utility functions for GeoJSON data handling.
3
- * @module
4
- */
5
- /**
6
- * Parse GeoJSON from various input formats.
7
- *
8
- * Supports multiple input types for flexibility:
9
- * - **string**: JSON string to parse
10
- * - **ReadableStream**: Streaming JSON data
11
- * - **ArrayBuffer/SharedArrayBuffer**: Binary data to decode and parse
12
- * - **Object**: Already-parsed FeatureCollection (passed through)
13
- *
14
- * @param data - GeoJSON data in any supported format.
15
- * @returns Parsed GeoJSON FeatureCollection.
16
- * @throws If data is null or an unsupported type.
17
- *
18
- * @example
19
- * ```ts
20
- * // From string
21
- * const geojson = await readDataAsGeoJSON('{"type":"FeatureCollection","features":[]}')
22
- *
23
- * // From fetch response
24
- * const response = await fetch('/data.geojson')
25
- * const geojson = await readDataAsGeoJSON(response.body!)
26
- * ```
27
- */
28
- export async function readDataAsGeoJSON(data) {
29
- if (data == null)
30
- throw new Error("Data is null");
31
- if (typeof data === "string")
32
- return JSON.parse(data);
33
- if (data instanceof ReadableStream) {
34
- const reader = data.pipeThrough(new TextDecoderStream()).getReader();
35
- let result = "";
36
- while (true) {
37
- const { done, value } = await reader.read();
38
- result += value;
39
- if (done)
40
- break;
41
- }
42
- return JSON.parse(result);
43
- }
44
- if (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {
45
- const decoder = new TextDecoder();
46
- const text = decoder.decode(new Uint8Array(data));
47
- return JSON.parse(text);
48
- }
49
- if (typeof data === "object" && "type" in data && "features" in data) {
50
- return data;
51
- }
52
- throw new Error("Invalid data type. Accepts string, ReadableStream, ArrayBufferLike, or GeoJSON FeatureCollection.");
53
- }
54
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,IAAsB;IAEtB,IAAI,IAAI,IAAI,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAA;IACjD,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAsB,CAAA;IAE1E,IAAI,IAAI,YAAY,cAAc,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,iBAAiB,EAAE,CAAC,CAAC,SAAS,EAAE,CAAA;QACpE,IAAI,MAAM,GAAG,EAAE,CAAA;QACf,OAAO,IAAI,EAAE,CAAC;YACb,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;YAC3C,MAAM,IAAI,KAAK,CAAA;YACf,IAAI,IAAI;gBAAE,MAAK;QAChB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAsB,CAAA;IAC/C,CAAC;IACD,IAAI,IAAI,YAAY,WAAW,IAAI,IAAI,YAAY,iBAAiB,EAAE,CAAC;QACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;QACjC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;QACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAsB,CAAA;IAC7C,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAI,IAAI,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;QACtE,OAAO,IAAyB,CAAA;IACjC,CAAC;IACD,MAAM,IAAI,KAAK,CACd,mGAAmG,CACnG,CAAA;AACF,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=entity-to-feature.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"entity-to-feature.test.d.ts","sourceRoot":"","sources":["../../test/entity-to-feature.test.ts"],"names":[],"mappings":""}
@@ -1,57 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
- import { nodeToFeature, relationToFeature, wayToFeature, } from "../src/entity-to-feature";
3
- describe("geojson helpers", () => {
4
- const node0 = { id: 1, lat: 0, lon: 0, tags: { amenity: "cafe" } };
5
- const node1 = { id: 2, lat: 1, lon: 1 };
6
- const nodes = [node0, node1];
7
- const nodeMap = new Map(nodes.map((n) => [n.id, n]));
8
- const refToPosition = (id) => {
9
- const node = nodeMap.get(id);
10
- if (!node)
11
- throw new Error(`Node ${id} not found`);
12
- return [node.lon, node.lat];
13
- };
14
- it("converts node to GeoJSON Point", () => {
15
- const feature = nodeToFeature(node0);
16
- expect(feature.type).toBe("Feature");
17
- expect(feature.geometry.type).toBe("Point");
18
- expect(feature.geometry.coordinates).toEqual([node0.lon, node0.lat]);
19
- expect(feature.properties).toEqual({
20
- id: node0.id,
21
- type: "node",
22
- ...node0.tags,
23
- ...node0.info,
24
- });
25
- });
26
- it("creates polygon for closed ways", () => {
27
- const way = {
28
- id: 10,
29
- refs: [1, 2, 1],
30
- tags: { area: "yes" },
31
- };
32
- const feature = wayToFeature(way, refToPosition);
33
- expect(feature.geometry.type).toBe("Polygon");
34
- });
35
- it("builds relation geometry collection", () => {
36
- // Create a way that forms a closed ring
37
- const way = {
38
- id: 10,
39
- refs: [1, 2, 1], // Closed way
40
- tags: { area: "yes" },
41
- };
42
- const wayMap = new Map([[way.id, way]]);
43
- const getWay = (wayId) => wayMap.get(wayId) ?? null;
44
- const relation = {
45
- id: 20,
46
- members: [{ type: "way", ref: 10, role: "outer" }],
47
- tags: { type: "multipolygon" },
48
- };
49
- const feature = relationToFeature(relation, refToPosition, getWay);
50
- expect(feature.geometry.type).toBe("Polygon");
51
- if (feature.geometry.type === "Polygon") {
52
- expect(feature.geometry.coordinates?.[0]).toBeDefined();
53
- expect(feature.geometry.coordinates[0]).toHaveLength(3); // Should have 3 coordinates (closed ring)
54
- }
55
- });
56
- });
57
- //# sourceMappingURL=entity-to-feature.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"entity-to-feature.test.js","sourceRoot":"","sources":["../../test/entity-to-feature.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,EACN,aAAa,EACb,iBAAiB,EACjB,YAAY,GACZ,MAAM,0BAA0B,CAAA;AAEjC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAChC,MAAM,KAAK,GAAY,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAA;IAC3E,MAAM,KAAK,GAAY,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAA;IAChD,MAAM,KAAK,GAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IACvC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,MAAM,aAAa,GAAG,CAAC,EAAU,EAAE,EAAE;QACpC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,K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geojson.test.d.ts","sourceRoot":"","sources":["../../test/osm-from-geojson.test.ts"],"names":[],"mappings":""}