@osmix/geojson 0.0.8 → 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.
- package/CHANGELOG.md +19 -0
- package/dist/utils.js +2 -1
- package/dist/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/utils.ts +1 -1
- package/dist/src/entity-to-feature.d.ts +0 -86
- package/dist/src/entity-to-feature.d.ts.map +0 -1
- package/dist/src/entity-to-feature.js +0 -345
- package/dist/src/entity-to-feature.js.map +0 -1
- package/dist/src/index.d.ts +0 -35
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -35
- package/dist/src/index.js.map +0 -1
- package/dist/src/osm-from-geojson.d.ts +0 -65
- package/dist/src/osm-from-geojson.d.ts.map +0 -1
- package/dist/src/osm-from-geojson.js +0 -303
- package/dist/src/osm-from-geojson.js.map +0 -1
- package/dist/src/types.d.ts +0 -49
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -5
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils.d.ts +0 -30
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -54
- package/dist/src/utils.js.map +0 -1
- package/dist/test/entity-to-feature.test.d.ts +0 -2
- package/dist/test/entity-to-feature.test.d.ts.map +0 -1
- package/dist/test/entity-to-feature.test.js +0 -57
- package/dist/test/entity-to-feature.test.js.map +0 -1
- package/dist/test/osm-from-geojson.test.d.ts +0 -2
- package/dist/test/osm-from-geojson.test.d.ts.map +0 -1
- package/dist/test/osm-from-geojson.test.js +0 -778
- package/dist/test/osm-from-geojson.test.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @osmix/geojson
|
|
2
2
|
|
|
3
|
+
## 0.0.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [12728ed]
|
|
8
|
+
- @osmix/shared@0.0.10
|
|
9
|
+
- @osmix/core@0.1.5
|
|
10
|
+
- @osmix/pbf@0.0.6
|
|
11
|
+
|
|
12
|
+
## 0.0.9
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- f32e4ee: General cleanup
|
|
17
|
+
- Updated dependencies [f32e4ee]
|
|
18
|
+
- @osmix/core@0.1.4
|
|
19
|
+
- @osmix/pbf@0.0.6
|
|
20
|
+
- @osmix/shared@0.0.9
|
|
21
|
+
|
|
3
22
|
## 0.0.8
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/utils.js
CHANGED
|
@@ -35,9 +35,10 @@ export async function readDataAsGeoJSON(data) {
|
|
|
35
35
|
let result = "";
|
|
36
36
|
while (true) {
|
|
37
37
|
const { done, value } = await reader.read();
|
|
38
|
-
result += value;
|
|
39
38
|
if (done)
|
|
40
39
|
break;
|
|
40
|
+
if (value !== undefined)
|
|
41
|
+
result += value;
|
|
41
42
|
}
|
|
42
43
|
return JSON.parse(result);
|
|
43
44
|
}
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;YAC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IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;QACtE,OAAO,IAAyB,CAAA;IACjC,CAAC;IACD,MAAM,IAAI,KAAK,CACd,mGAAmG,CACnG,CAAA;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@osmix/geojson",
|
|
4
4
|
"description": "Convert OSM files to and from GeoJSON.",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.10",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./src/index.ts",
|
|
8
8
|
"types": "./src/index.ts",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"typescript": "^5.9.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@osmix/core": "0.1.
|
|
51
|
-
"@osmix/pbf": "0.0.
|
|
52
|
-
"@osmix/shared": "0.0.
|
|
50
|
+
"@osmix/core": "0.1.5",
|
|
51
|
+
"@osmix/pbf": "0.0.6",
|
|
52
|
+
"@osmix/shared": "0.0.10",
|
|
53
53
|
"@placemarkio/geojson-rewind": "^1.0.3",
|
|
54
54
|
"dequal": "^2.0.3"
|
|
55
55
|
}
|
package/src/utils.ts
CHANGED
|
@@ -39,8 +39,8 @@ export async function readDataAsGeoJSON(
|
|
|
39
39
|
let result = ""
|
|
40
40
|
while (true) {
|
|
41
41
|
const { done, value } = await reader.read()
|
|
42
|
-
result += value
|
|
43
42
|
if (done) break
|
|
43
|
+
if (value !== undefined) result += value
|
|
44
44
|
}
|
|
45
45
|
return JSON.parse(result) as ImportableGeoJSON
|
|
46
46
|
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OSM entity to GeoJSON Feature conversion.
|
|
3
|
-
*
|
|
4
|
-
* Converts OSM nodes, ways, and relations into GeoJSON Features with
|
|
5
|
-
* appropriate geometry types and preserved properties.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import type { Osm } from "@osmix/core";
|
|
10
|
-
import type { OsmEntity, OsmNode, OsmRelation, OsmWay } from "@osmix/shared/types";
|
|
11
|
-
import type { GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon } from "geojson";
|
|
12
|
-
import type { OsmGeoJSONFeature } from "./types";
|
|
13
|
-
/**
|
|
14
|
-
* Convert an OSM node to a GeoJSON Point feature.
|
|
15
|
-
*
|
|
16
|
-
* @param node - OSM node with id, lon, lat, and optional tags.
|
|
17
|
-
* @returns GeoJSON Point Feature with OSM properties.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* const feature = nodeToFeature({ id: 1, lon: -122.4, lat: 47.6, tags: { name: "Seattle" } })
|
|
22
|
-
* // { type: "Feature", geometry: { type: "Point", coordinates: [-122.4, 47.6] }, ... }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export declare function nodeToFeature(node: OsmNode): OsmGeoJSONFeature<Point>;
|
|
26
|
-
/**
|
|
27
|
-
* Convert an OSM way to a GeoJSON LineString or Polygon feature.
|
|
28
|
-
*
|
|
29
|
-
* Geometry type is determined by the `wayIsArea` helper, which checks for
|
|
30
|
-
* area-indicating tags (building, landuse, etc.) and ring closure.
|
|
31
|
-
*
|
|
32
|
-
* @param way - OSM way with id, refs, and optional tags.
|
|
33
|
-
* @param refToPosition - Function to resolve node ID to [lon, lat] coordinates.
|
|
34
|
-
* @returns GeoJSON LineString or Polygon Feature with OSM properties.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* const feature = wayToFeature(way, (ref) => osm.nodes.getNodeLonLat({ id: ref }))
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare function wayToFeature(way: OsmWay, refToPosition: (id: number) => [number, number]): OsmGeoJSONFeature<LineString | Polygon>;
|
|
42
|
-
/**
|
|
43
|
-
* Convert an OSM relation to a GeoJSON feature.
|
|
44
|
-
*
|
|
45
|
-
* Geometry type is determined by relation type and tags:
|
|
46
|
-
* - **Multipolygon/boundary**: MultiPolygon or Polygon
|
|
47
|
-
* - **Route/multilinestring**: MultiLineString or LineString
|
|
48
|
-
* - **Site/collection**: MultiPoint or Point
|
|
49
|
-
* - **Other**: GeometryCollection (empty for logical relations)
|
|
50
|
-
*
|
|
51
|
-
* @param relation - OSM relation with id, members, and optional tags.
|
|
52
|
-
* @param refToPosition - Function to resolve node ID to [lon, lat] coordinates.
|
|
53
|
-
* @param getWay - Optional function to resolve way ID to OsmWay (required for polygons/lines).
|
|
54
|
-
* @returns GeoJSON Feature with appropriate geometry type.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```ts
|
|
58
|
-
* const feature = relationToFeature(
|
|
59
|
-
* relation,
|
|
60
|
-
* (ref) => osm.nodes.getNodeLonLat({ id: ref }),
|
|
61
|
-
* (ref) => osm.ways.getById(ref)
|
|
62
|
-
* )
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export declare function relationToFeature(relation: OsmRelation, refToPosition: (id: number) => [number, number], getWay?: (wayId: number) => OsmWay | null): OsmGeoJSONFeature<Polygon | MultiPolygon | LineString | MultiLineString | Point | MultiPoint | GeometryCollection>;
|
|
66
|
-
/**
|
|
67
|
-
* Convert any OSM entity to a GeoJSON feature using an Osm index.
|
|
68
|
-
*
|
|
69
|
-
* Convenience function that handles entity type detection and coordinate
|
|
70
|
-
* resolution automatically using the provided Osm index.
|
|
71
|
-
*
|
|
72
|
-
* @param osm - Osm index for coordinate lookups.
|
|
73
|
-
* @param entity - Any OSM entity (node, way, or relation).
|
|
74
|
-
* @returns GeoJSON Feature with appropriate geometry.
|
|
75
|
-
* @throws If entity type is unknown.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```ts
|
|
79
|
-
* for (const way of osm.ways) {
|
|
80
|
-
* const feature = osmEntityToGeoJSONFeature(osm, way)
|
|
81
|
-
* features.push(feature)
|
|
82
|
-
* }
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export declare function osmEntityToGeoJSONFeature(osm: Osm, entity: OsmEntity): OsmGeoJSONFeature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.Polygon | GeoJSON.MultiPolygon | GeoJSON.MultiLineString | GeoJSON.MultiPoint | GeoJSON.GeometryCollection>;
|
|
86
|
-
//# sourceMappingURL=entity-to-feature.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entity-to-feature.d.ts","sourceRoot":"","sources":["../../src/entity-to-feature.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAWtC,OAAO,KAAK,EAEX,SAAS,EACT,OAAO,EACP,WAAW,EACX,MAAM,EACN,MAAM,qBAAqB,CAAA;AAG5B,OAAO,KAAK,EACX,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,UAAU,EACV,YAAY,EACZ,KAAK,EACL,OAAO,EACP,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAerE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC3B,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7C,iBAAiB,CAAC,UAAU,GAAG,OAAO,CAAC,CAoBzC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,WAAW,EACrB,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/C,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GACvC,iBAAiB,CACjB,OAAO,GACP,YAAY,GACZ,UAAU,GACV,eAAe,GACf,KAAK,GACL,UAAU,GACV,kBAAkB,CACpB,CA2OA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,SAAS,GACf,iBAAiB,CACjB,OAAO,CAAC,KAAK,GACb,OAAO,CAAC,UAAU,GAClB,OAAO,CAAC,OAAO,GACf,OAAO,CAAC,YAAY,GACpB,OAAO,CAAC,eAAe,GACvB,OAAO,CAAC,UAAU,GAClB,OAAO,CAAC,kBAAkB,CAC5B,CAeA"}
|
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OSM entity to GeoJSON Feature conversion.
|
|
3
|
-
*
|
|
4
|
-
* Converts OSM nodes, ways, and relations into GeoJSON Features with
|
|
5
|
-
* appropriate geometry types and preserved properties.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import { buildRelationLineStrings, collectRelationPoints, getRelationKind, isAreaRelation, } from "@osmix/shared/relation-kind";
|
|
10
|
-
import { buildRelationRings, getWayMembersByRole, } from "@osmix/shared/relation-multipolygon";
|
|
11
|
-
import { isNode, isRelation, isWay } from "@osmix/shared/utils";
|
|
12
|
-
import { wayIsArea } from "@osmix/shared/way-is-area";
|
|
13
|
-
/**
|
|
14
|
-
* Convert an OSM node to a GeoJSON Point feature.
|
|
15
|
-
*
|
|
16
|
-
* @param node - OSM node with id, lon, lat, and optional tags.
|
|
17
|
-
* @returns GeoJSON Point Feature with OSM properties.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* const feature = nodeToFeature({ id: 1, lon: -122.4, lat: 47.6, tags: { name: "Seattle" } })
|
|
22
|
-
* // { type: "Feature", geometry: { type: "Point", coordinates: [-122.4, 47.6] }, ... }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export function nodeToFeature(node) {
|
|
26
|
-
return {
|
|
27
|
-
type: "Feature",
|
|
28
|
-
id: node.id,
|
|
29
|
-
geometry: {
|
|
30
|
-
type: "Point",
|
|
31
|
-
coordinates: [node.lon, node.lat],
|
|
32
|
-
},
|
|
33
|
-
properties: {
|
|
34
|
-
id: node.id,
|
|
35
|
-
type: "node",
|
|
36
|
-
...node.info,
|
|
37
|
-
...node.tags,
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Convert an OSM way to a GeoJSON LineString or Polygon feature.
|
|
43
|
-
*
|
|
44
|
-
* Geometry type is determined by the `wayIsArea` helper, which checks for
|
|
45
|
-
* area-indicating tags (building, landuse, etc.) and ring closure.
|
|
46
|
-
*
|
|
47
|
-
* @param way - OSM way with id, refs, and optional tags.
|
|
48
|
-
* @param refToPosition - Function to resolve node ID to [lon, lat] coordinates.
|
|
49
|
-
* @returns GeoJSON LineString or Polygon Feature with OSM properties.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* const feature = wayToFeature(way, (ref) => osm.nodes.getNodeLonLat({ id: ref }))
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export function wayToFeature(way, refToPosition) {
|
|
57
|
-
return {
|
|
58
|
-
type: "Feature",
|
|
59
|
-
id: way.id,
|
|
60
|
-
geometry: wayIsArea(way)
|
|
61
|
-
? {
|
|
62
|
-
type: "Polygon",
|
|
63
|
-
coordinates: [way.refs.map((r) => refToPosition(r))],
|
|
64
|
-
}
|
|
65
|
-
: {
|
|
66
|
-
type: "LineString",
|
|
67
|
-
coordinates: way.refs.map((r) => refToPosition(r)),
|
|
68
|
-
},
|
|
69
|
-
properties: {
|
|
70
|
-
id: way.id,
|
|
71
|
-
type: "way",
|
|
72
|
-
...way.info,
|
|
73
|
-
...way.tags,
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Convert an OSM relation to a GeoJSON feature.
|
|
79
|
-
*
|
|
80
|
-
* Geometry type is determined by relation type and tags:
|
|
81
|
-
* - **Multipolygon/boundary**: MultiPolygon or Polygon
|
|
82
|
-
* - **Route/multilinestring**: MultiLineString or LineString
|
|
83
|
-
* - **Site/collection**: MultiPoint or Point
|
|
84
|
-
* - **Other**: GeometryCollection (empty for logical relations)
|
|
85
|
-
*
|
|
86
|
-
* @param relation - OSM relation with id, members, and optional tags.
|
|
87
|
-
* @param refToPosition - Function to resolve node ID to [lon, lat] coordinates.
|
|
88
|
-
* @param getWay - Optional function to resolve way ID to OsmWay (required for polygons/lines).
|
|
89
|
-
* @returns GeoJSON Feature with appropriate geometry type.
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```ts
|
|
93
|
-
* const feature = relationToFeature(
|
|
94
|
-
* relation,
|
|
95
|
-
* (ref) => osm.nodes.getNodeLonLat({ id: ref }),
|
|
96
|
-
* (ref) => osm.ways.getById(ref)
|
|
97
|
-
* )
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
export function relationToFeature(relation, refToPosition, getWay) {
|
|
101
|
-
const getNodeCoordinates = (nodeId) => {
|
|
102
|
-
const pos = refToPosition(nodeId);
|
|
103
|
-
return pos ? [pos[0], pos[1]] : undefined;
|
|
104
|
-
};
|
|
105
|
-
const kind = getRelationKind(relation);
|
|
106
|
-
// Handle area relations (multipolygon, boundary)
|
|
107
|
-
if (isAreaRelation(relation) && getWay) {
|
|
108
|
-
const rings = buildRelationRings(relation, getWay, getNodeCoordinates);
|
|
109
|
-
if (rings.length === 0) {
|
|
110
|
-
// Fallback to simple MultiPolygon if we can't build rings
|
|
111
|
-
return {
|
|
112
|
-
type: "Feature",
|
|
113
|
-
id: relation.id,
|
|
114
|
-
geometry: {
|
|
115
|
-
type: "MultiPolygon",
|
|
116
|
-
coordinates: [],
|
|
117
|
-
},
|
|
118
|
-
properties: {
|
|
119
|
-
id: relation.id,
|
|
120
|
-
type: "relation",
|
|
121
|
-
...relation.info,
|
|
122
|
-
...relation.tags,
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
// If only one polygon, return Polygon; otherwise MultiPolygon
|
|
127
|
-
if (rings.length === 1) {
|
|
128
|
-
return {
|
|
129
|
-
type: "Feature",
|
|
130
|
-
id: relation.id,
|
|
131
|
-
geometry: {
|
|
132
|
-
type: "Polygon",
|
|
133
|
-
coordinates: rings[0],
|
|
134
|
-
},
|
|
135
|
-
properties: {
|
|
136
|
-
id: relation.id,
|
|
137
|
-
type: "relation",
|
|
138
|
-
...relation.info,
|
|
139
|
-
...relation.tags,
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
return {
|
|
144
|
-
type: "Feature",
|
|
145
|
-
id: relation.id,
|
|
146
|
-
geometry: {
|
|
147
|
-
type: "MultiPolygon",
|
|
148
|
-
coordinates: rings,
|
|
149
|
-
},
|
|
150
|
-
properties: {
|
|
151
|
-
id: relation.id,
|
|
152
|
-
type: "relation",
|
|
153
|
-
...relation.info,
|
|
154
|
-
...relation.tags,
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
// Handle line relations (route, multilinestring)
|
|
159
|
-
if (kind === "line" && getWay) {
|
|
160
|
-
const lineStrings = buildRelationLineStrings(relation, getWay, getNodeCoordinates);
|
|
161
|
-
if (lineStrings.length === 0) {
|
|
162
|
-
return {
|
|
163
|
-
type: "Feature",
|
|
164
|
-
id: relation.id,
|
|
165
|
-
geometry: {
|
|
166
|
-
type: "MultiLineString",
|
|
167
|
-
coordinates: [],
|
|
168
|
-
},
|
|
169
|
-
properties: {
|
|
170
|
-
id: relation.id,
|
|
171
|
-
type: "relation",
|
|
172
|
-
...relation.info,
|
|
173
|
-
...relation.tags,
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
if (lineStrings.length === 1) {
|
|
178
|
-
return {
|
|
179
|
-
type: "Feature",
|
|
180
|
-
id: relation.id,
|
|
181
|
-
geometry: {
|
|
182
|
-
type: "LineString",
|
|
183
|
-
coordinates: lineStrings[0],
|
|
184
|
-
},
|
|
185
|
-
properties: {
|
|
186
|
-
id: relation.id,
|
|
187
|
-
type: "relation",
|
|
188
|
-
...relation.info,
|
|
189
|
-
...relation.tags,
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
return {
|
|
194
|
-
type: "Feature",
|
|
195
|
-
id: relation.id,
|
|
196
|
-
geometry: {
|
|
197
|
-
type: "MultiLineString",
|
|
198
|
-
coordinates: lineStrings,
|
|
199
|
-
},
|
|
200
|
-
properties: {
|
|
201
|
-
id: relation.id,
|
|
202
|
-
type: "relation",
|
|
203
|
-
...relation.info,
|
|
204
|
-
...relation.tags,
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
// Handle point relations (multipoint)
|
|
209
|
-
if (kind === "point") {
|
|
210
|
-
const points = collectRelationPoints(relation, getNodeCoordinates);
|
|
211
|
-
if (points.length === 0) {
|
|
212
|
-
return {
|
|
213
|
-
type: "Feature",
|
|
214
|
-
id: relation.id,
|
|
215
|
-
geometry: {
|
|
216
|
-
type: "MultiPoint",
|
|
217
|
-
coordinates: [],
|
|
218
|
-
},
|
|
219
|
-
properties: {
|
|
220
|
-
id: relation.id,
|
|
221
|
-
type: "relation",
|
|
222
|
-
...relation.info,
|
|
223
|
-
...relation.tags,
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
if (points.length === 1) {
|
|
228
|
-
return {
|
|
229
|
-
type: "Feature",
|
|
230
|
-
id: relation.id,
|
|
231
|
-
geometry: {
|
|
232
|
-
type: "Point",
|
|
233
|
-
coordinates: points[0],
|
|
234
|
-
},
|
|
235
|
-
properties: {
|
|
236
|
-
id: relation.id,
|
|
237
|
-
type: "relation",
|
|
238
|
-
...relation.info,
|
|
239
|
-
...relation.tags,
|
|
240
|
-
},
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
return {
|
|
244
|
-
type: "Feature",
|
|
245
|
-
id: relation.id,
|
|
246
|
-
geometry: {
|
|
247
|
-
type: "MultiPoint",
|
|
248
|
-
coordinates: points,
|
|
249
|
-
},
|
|
250
|
-
properties: {
|
|
251
|
-
id: relation.id,
|
|
252
|
-
type: "relation",
|
|
253
|
-
...relation.info,
|
|
254
|
-
...relation.tags,
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
// Fallback for logical relations or when getWay is not provided
|
|
259
|
-
// Return GeometryCollection or null geometry for logic-only relations
|
|
260
|
-
if (kind === "logic" || kind === "super") {
|
|
261
|
-
return {
|
|
262
|
-
type: "Feature",
|
|
263
|
-
id: relation.id,
|
|
264
|
-
geometry: {
|
|
265
|
-
type: "GeometryCollection",
|
|
266
|
-
geometries: [],
|
|
267
|
-
},
|
|
268
|
-
properties: {
|
|
269
|
-
id: relation.id,
|
|
270
|
-
type: "relation",
|
|
271
|
-
...relation.info,
|
|
272
|
-
...relation.tags,
|
|
273
|
-
},
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
// Final fallback: try to create a simple representation from way members
|
|
277
|
-
if (getWay) {
|
|
278
|
-
const { outer } = getWayMembersByRole(relation);
|
|
279
|
-
const coordinates = [];
|
|
280
|
-
if (outer.length > 0) {
|
|
281
|
-
coordinates.push([outer.map((member) => refToPosition(member.ref))]);
|
|
282
|
-
}
|
|
283
|
-
return {
|
|
284
|
-
type: "Feature",
|
|
285
|
-
id: relation.id,
|
|
286
|
-
geometry: {
|
|
287
|
-
type: "MultiPolygon",
|
|
288
|
-
coordinates: coordinates.length > 0 ? coordinates : [],
|
|
289
|
-
},
|
|
290
|
-
properties: {
|
|
291
|
-
id: relation.id,
|
|
292
|
-
type: "relation",
|
|
293
|
-
...relation.info,
|
|
294
|
-
...relation.tags,
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
// No geometry available
|
|
299
|
-
return {
|
|
300
|
-
type: "Feature",
|
|
301
|
-
id: relation.id,
|
|
302
|
-
geometry: {
|
|
303
|
-
type: "GeometryCollection",
|
|
304
|
-
geometries: [],
|
|
305
|
-
},
|
|
306
|
-
properties: {
|
|
307
|
-
id: relation.id,
|
|
308
|
-
type: "relation",
|
|
309
|
-
...relation.info,
|
|
310
|
-
...relation.tags,
|
|
311
|
-
},
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Convert any OSM entity to a GeoJSON feature using an Osm index.
|
|
316
|
-
*
|
|
317
|
-
* Convenience function that handles entity type detection and coordinate
|
|
318
|
-
* resolution automatically using the provided Osm index.
|
|
319
|
-
*
|
|
320
|
-
* @param osm - Osm index for coordinate lookups.
|
|
321
|
-
* @param entity - Any OSM entity (node, way, or relation).
|
|
322
|
-
* @returns GeoJSON Feature with appropriate geometry.
|
|
323
|
-
* @throws If entity type is unknown.
|
|
324
|
-
*
|
|
325
|
-
* @example
|
|
326
|
-
* ```ts
|
|
327
|
-
* for (const way of osm.ways) {
|
|
328
|
-
* const feature = osmEntityToGeoJSONFeature(osm, way)
|
|
329
|
-
* features.push(feature)
|
|
330
|
-
* }
|
|
331
|
-
* ```
|
|
332
|
-
*/
|
|
333
|
-
export function osmEntityToGeoJSONFeature(osm, entity) {
|
|
334
|
-
if (isNode(entity)) {
|
|
335
|
-
return nodeToFeature(entity);
|
|
336
|
-
}
|
|
337
|
-
if (isWay(entity)) {
|
|
338
|
-
return wayToFeature(entity, (ref) => osm.nodes.getNodeLonLat({ id: ref }));
|
|
339
|
-
}
|
|
340
|
-
if (isRelation(entity)) {
|
|
341
|
-
return relationToFeature(entity, (ref) => osm.nodes.getNodeLonLat({ id: ref }), (ref) => osm.ways.getById(ref));
|
|
342
|
-
}
|
|
343
|
-
throw new Error("Unknown entity type");
|
|
344
|
-
}
|
|
345
|
-
//# sourceMappingURL=entity-to-feature.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entity-to-feature.js","sourceRoot":"","sources":["../../src/entity-to-feature.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACN,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,cAAc,GACd,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACN,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,qCAAqC,CAAA;AAQ5C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAYrD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,IAAa;IAC1C,OAAO;QACN,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,QAAQ,EAAE;YACT,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;SACjC;QACD,UAAU,EAAE;YACX,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,MAAM;YACZ,GAAG,IAAI,CAAC,IAAI;YACZ,GAAG,IAAI,CAAC,IAAI;SACZ;KACD,CAAA;AACF,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAC3B,GAAW,EACX,aAA+C;IAE/C,OAAO;QACN,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC;YACvB,CAAC,CAAC;gBACA,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,C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AC7B,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACnB,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;IAC3E,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACxB,OAAO,iBAAiB,CACvB,MAAM,EACN,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAC7C,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAC9B,CAAA;IACF,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;AACvC,CAAC"}
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @osmix/geojson - Convert between OSM entities and GeoJSON.
|
|
3
|
-
*
|
|
4
|
-
* Provides bidirectional conversion between Osmix data structures and GeoJSON:
|
|
5
|
-
* - **Export**: Convert OSM nodes, ways, and relations to GeoJSON Features.
|
|
6
|
-
* - **Import**: Build an Osm index from a GeoJSON FeatureCollection.
|
|
7
|
-
*
|
|
8
|
-
* Handles geometry mapping:
|
|
9
|
-
* - Nodes → Point
|
|
10
|
-
* - Ways → LineString or Polygon (based on tags and closure)
|
|
11
|
-
* - Relations → MultiPolygon, MultiLineString, or GeometryCollection (by type)
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Export OSM entity to GeoJSON
|
|
16
|
-
* import { nodeToFeature, wayToFeature } from "@osmix/geojson"
|
|
17
|
-
*
|
|
18
|
-
* const pointFeature = nodeToFeature(node)
|
|
19
|
-
* const lineFeature = wayToFeature(way, (ref) => osm.nodes.getNodeLonLat({ id: ref }))
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* // Import GeoJSON to Osm index
|
|
25
|
-
* import { fromGeoJSON } from "@osmix/geojson"
|
|
26
|
-
*
|
|
27
|
-
* const osm = await fromGeoJSON(geojsonFile, { id: "imported" })
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @module @osmix/geojson
|
|
31
|
-
*/
|
|
32
|
-
export * from "./entity-to-feature";
|
|
33
|
-
export * from "./osm-from-geojson";
|
|
34
|
-
export * from "./types";
|
|
35
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,SAAS,CAAA"}
|
package/dist/src/index.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @osmix/geojson - Convert between OSM entities and GeoJSON.
|
|
3
|
-
*
|
|
4
|
-
* Provides bidirectional conversion between Osmix data structures and GeoJSON:
|
|
5
|
-
* - **Export**: Convert OSM nodes, ways, and relations to GeoJSON Features.
|
|
6
|
-
* - **Import**: Build an Osm index from a GeoJSON FeatureCollection.
|
|
7
|
-
*
|
|
8
|
-
* Handles geometry mapping:
|
|
9
|
-
* - Nodes → Point
|
|
10
|
-
* - Ways → LineString or Polygon (based on tags and closure)
|
|
11
|
-
* - Relations → MultiPolygon, MultiLineString, or GeometryCollection (by type)
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Export OSM entity to GeoJSON
|
|
16
|
-
* import { nodeToFeature, wayToFeature } from "@osmix/geojson"
|
|
17
|
-
*
|
|
18
|
-
* const pointFeature = nodeToFeature(node)
|
|
19
|
-
* const lineFeature = wayToFeature(way, (ref) => osm.nodes.getNodeLonLat({ id: ref }))
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* // Import GeoJSON to Osm index
|
|
25
|
-
* import { fromGeoJSON } from "@osmix/geojson"
|
|
26
|
-
*
|
|
27
|
-
* const osm = await fromGeoJSON(geojsonFile, { id: "imported" })
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @module @osmix/geojson
|
|
31
|
-
*/
|
|
32
|
-
export * from "./entity-to-feature";
|
|
33
|
-
export * from "./osm-from-geojson";
|
|
34
|
-
export * from "./types";
|
|
35
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,SAAS,CAAA"}
|
|
@@ -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"}
|