osm2geojson-lite 1.2.0 → 2.1.0

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.
@@ -0,0 +1,226 @@
1
+ /**
2
+ * The value values for the "type" property of GeoJSON Objects.
3
+ * https://tools.ietf.org/html/rfc7946#section-1.4
4
+ */
5
+ type GeoJsonTypes = GeoJSON["type"];
6
+ /**
7
+ * Bounding box
8
+ * https://tools.ietf.org/html/rfc7946#section-5
9
+ */
10
+ type BBox = [number, number, number, number] | [number, number, number, number, number, number];
11
+ /**
12
+ * A Position is an array of coordinates.
13
+ * https://tools.ietf.org/html/rfc7946#section-3.1.1
14
+ * Array should contain between two and three elements.
15
+ * The previous GeoJSON specification allowed more elements (e.g., which could be used to represent M values),
16
+ * but the current specification only allows X, Y, and (optionally) Z to be defined.
17
+ *
18
+ * Note: the type will not be narrowed down to `[number, number] | [number, number, number]` due to
19
+ * marginal benefits and the large impact of breaking change.
20
+ *
21
+ * See previous discussions on the type narrowing:
22
+ * - {@link https://github.com/DefinitelyTyped/DefinitelyTyped/pull/21590|Nov 2017}
23
+ * - {@link https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/67773|Dec 2023}
24
+ * - {@link https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/71441| Dec 2024}
25
+ *
26
+ * One can use a
27
+ * {@link https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates|user-defined type guard that returns a type predicate}
28
+ * to determine if a position is a 2D or 3D position.
29
+ *
30
+ * @example
31
+ * import type { Position } from 'geojson';
32
+ *
33
+ * type StrictPosition = [x: number, y: number] | [x: number, y: number, z: number]
34
+ *
35
+ * function isStrictPosition(position: Position): position is StrictPosition {
36
+ * return position.length === 2 || position.length === 3
37
+ * };
38
+ *
39
+ * let position: Position = [-116.91, 45.54];
40
+ *
41
+ * let x: number;
42
+ * let y: number;
43
+ * let z: number | undefined;
44
+ *
45
+ * if (isStrictPosition(position)) {
46
+ * // `tsc` would throw an error if we tried to destructure a fourth parameter
47
+ * [x, y, z] = position;
48
+ * } else {
49
+ * throw new TypeError("Position is not a 2D or 3D point");
50
+ * }
51
+ */
52
+ type Position = number[];
53
+ /**
54
+ * The base GeoJSON object.
55
+ * https://tools.ietf.org/html/rfc7946#section-3
56
+ * The GeoJSON specification also allows foreign members
57
+ * (https://tools.ietf.org/html/rfc7946#section-6.1)
58
+ * Developers should use "&" type in TypeScript or extend the interface
59
+ * to add these foreign members.
60
+ */
61
+ interface GeoJsonObject {
62
+ // Don't include foreign members directly into this type def.
63
+ // in order to preserve type safety.
64
+ // [key: string]: any;
65
+ /**
66
+ * Specifies the type of GeoJSON object.
67
+ */
68
+ type: GeoJsonTypes;
69
+ /**
70
+ * Bounding box of the coordinate range of the object's Geometries, Features, or Feature Collections.
71
+ * The value of the bbox member is an array of length 2*n where n is the number of dimensions
72
+ * represented in the contained geometries, with all axes of the most southwesterly point
73
+ * followed by all axes of the more northeasterly point.
74
+ * The axes order of a bbox follows the axes order of geometries.
75
+ * https://tools.ietf.org/html/rfc7946#section-5
76
+ */
77
+ bbox?: BBox | undefined;
78
+ }
79
+ /**
80
+ * Union of GeoJSON objects.
81
+ */
82
+ type GeoJSON<G extends Geometry | null = Geometry, P = GeoJsonProperties> = G | Feature<G, P> | FeatureCollection<G, P>;
83
+ /**
84
+ * Geometry object.
85
+ * https://tools.ietf.org/html/rfc7946#section-3
86
+ */
87
+ type Geometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon | GeometryCollection;
88
+ type GeometryObject = Geometry;
89
+ /**
90
+ * Point geometry object.
91
+ * https://tools.ietf.org/html/rfc7946#section-3.1.2
92
+ */
93
+ interface Point extends GeoJsonObject {
94
+ type: "Point";
95
+ coordinates: Position;
96
+ }
97
+ /**
98
+ * MultiPoint geometry object.
99
+ * https://tools.ietf.org/html/rfc7946#section-3.1.3
100
+ */
101
+ interface MultiPoint extends GeoJsonObject {
102
+ type: "MultiPoint";
103
+ coordinates: Position[];
104
+ }
105
+ /**
106
+ * LineString geometry object.
107
+ * https://tools.ietf.org/html/rfc7946#section-3.1.4
108
+ */
109
+ interface LineString extends GeoJsonObject {
110
+ type: "LineString";
111
+ coordinates: Position[];
112
+ }
113
+ /**
114
+ * MultiLineString geometry object.
115
+ * https://tools.ietf.org/html/rfc7946#section-3.1.5
116
+ */
117
+ interface MultiLineString extends GeoJsonObject {
118
+ type: "MultiLineString";
119
+ coordinates: Position[][];
120
+ }
121
+ /**
122
+ * Polygon geometry object.
123
+ * https://tools.ietf.org/html/rfc7946#section-3.1.6
124
+ */
125
+ interface Polygon extends GeoJsonObject {
126
+ type: "Polygon";
127
+ coordinates: Position[][];
128
+ }
129
+ /**
130
+ * MultiPolygon geometry object.
131
+ * https://tools.ietf.org/html/rfc7946#section-3.1.7
132
+ */
133
+ interface MultiPolygon extends GeoJsonObject {
134
+ type: "MultiPolygon";
135
+ coordinates: Position[][][];
136
+ }
137
+ /**
138
+ * Geometry Collection
139
+ * https://tools.ietf.org/html/rfc7946#section-3.1.8
140
+ */
141
+ interface GeometryCollection<G extends Geometry = Geometry> extends GeoJsonObject {
142
+ type: "GeometryCollection";
143
+ geometries: G[];
144
+ }
145
+ type GeoJsonProperties = {
146
+ [name: string]: any;
147
+ } | null;
148
+ /**
149
+ * A feature object which contains a geometry and associated properties.
150
+ * https://tools.ietf.org/html/rfc7946#section-3.2
151
+ */
152
+ interface Feature<G extends Geometry | null = Geometry, P = GeoJsonProperties> extends GeoJsonObject {
153
+ type: "Feature";
154
+ /**
155
+ * The feature's geometry
156
+ */
157
+ geometry: G;
158
+ /**
159
+ * A value that uniquely identifies this feature in a
160
+ * https://tools.ietf.org/html/rfc7946#section-3.2.
161
+ */
162
+ id?: string | number | undefined;
163
+ /**
164
+ * Properties associated with this feature.
165
+ */
166
+ properties: P;
167
+ }
168
+ /**
169
+ * A collection of feature objects.
170
+ * https://tools.ietf.org/html/rfc7946#section-3.3
171
+ */
172
+ interface FeatureCollection<G extends Geometry | null = Geometry, P = GeoJsonProperties> extends GeoJsonObject {
173
+ type: "FeatureCollection";
174
+ features: Array<Feature<G, P>>;
175
+ }
176
+ type PolygonRule = {
177
+ ignore?: string[];
178
+ include?: string[];
179
+ exclude?: string[];
180
+ whitelist?: string[];
181
+ blacklist?: string[];
182
+ };
183
+ type PolygonTags = Record<string, PolygonRule>;
184
+ interface IOptions {
185
+ /**
186
+ * When it's set to `true`, the returned geojson will include all elements that meet the specified conditions in `FeatureCollection` format;
187
+ * otherwise, only the bare geometry of the first `relation` element will be returned.
188
+ * @default false
189
+ */
190
+ completeFeature?: boolean;
191
+ /**
192
+ * When it's set to `true`, the returned geojson will include all elements with tags (i.e., tagged)
193
+ * until `suppressWay` changes its behavior a bit; otherwise only the unreferenced ones get returned.
194
+ * @default false
195
+ */
196
+ renderTagged?: boolean;
197
+ /**
198
+ * When it's set to `true`, the returned `FeatureCollection` will exclude all referenced `way`s even though they are tagged;
199
+ * otherwise the features of those `way`s will be included in the resulted result as well.
200
+ * @default true
201
+ */
202
+ excludeWay?: boolean;
203
+ /**
204
+ * An OSM element ID in the form of `type/id`, e.g. `way/123`. When set, only that
205
+ * feature is returned instead of a `FeatureCollection`.
206
+ * @default undefined
207
+ */
208
+ elementId?: string;
209
+ /**
210
+ * When set to `true`, features that reference missing nodes/ways/relations
211
+ * receive an `@tainted: true` property. Matches `osm2geojson-ultra`.
212
+ * @default false
213
+ */
214
+ tainted?: boolean;
215
+ /**
216
+ * Alternate polygon tag rules for ways. The shape matches `polytags.json`:
217
+ * `{ key: { ignore?, include?, exclude? } }`. Legacy `whitelist` /
218
+ * `blacklist` spellings are also accepted.
219
+ * @default undefined (built-in rules)
220
+ */
221
+ polygonTags?: PolygonTags;
222
+ }
223
+ declare function osm2geojson(osm: string | {
224
+ [k: string]: any;
225
+ }, opts?: IOptions): FeatureCollection<GeometryObject> | Feature<any, any> | GeometryObject | undefined;
226
+ export { osm2geojson as default };