@osmix/shapefile 0.0.2
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 +14 -0
- package/README.md +64 -0
- package/dist/src/index.d.ts +33 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +33 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/osm-from-shapefile.d.ts +67 -0
- package/dist/src/osm-from-shapefile.d.ts.map +1 -0
- package/dist/src/osm-from-shapefile.js +335 -0
- package/dist/src/osm-from-shapefile.js.map +1 -0
- package/dist/src/types.d.ts +24 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +5 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +28 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +71 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/test/osm-from-shapefile.test.d.ts +2 -0
- package/dist/test/osm-from-shapefile.test.d.ts.map +1 -0
- package/dist/test/osm-from-shapefile.test.js +460 -0
- package/dist/test/osm-from-shapefile.test.js.map +1 -0
- package/package.json +53 -0
- package/src/index.ts +33 -0
- package/src/osm-from-shapefile.ts +409 -0
- package/src/shpjs.d.ts +27 -0
- package/src/types.ts +24 -0
- package/src/utils.ts +82 -0
- package/test/osm-from-shapefile.test.ts +511 -0
- package/tsconfig.json +9 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# @osmix/shapefile
|
|
2
|
+
|
|
3
|
+
Import Shapefiles into Osmix indexes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @osmix/shapefile
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { fromShapefile } from "@osmix/shapefile"
|
|
15
|
+
|
|
16
|
+
// From a ZIP file buffer
|
|
17
|
+
const zipBuffer = await Bun.file("./buildings.zip").arrayBuffer()
|
|
18
|
+
const osm = await fromShapefile(zipBuffer, { id: "buildings" })
|
|
19
|
+
|
|
20
|
+
// From a URL
|
|
21
|
+
const osm = await fromShapefile("https://example.com/data.zip")
|
|
22
|
+
|
|
23
|
+
// Query the imported data
|
|
24
|
+
const buildings = osm.ways.search("building")
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## How It Works
|
|
28
|
+
|
|
29
|
+
This package uses [shpjs](https://github.com/calvinmetcalf/shapefile-js) to parse Shapefiles.
|
|
30
|
+
The library automatically:
|
|
31
|
+
|
|
32
|
+
- Extracts Shapefile components (`.shp`, `.dbf`, `.prj`) from ZIP archives
|
|
33
|
+
- Projects coordinates to WGS84 (lat/lon)
|
|
34
|
+
- Converts geometries to GeoJSON
|
|
35
|
+
|
|
36
|
+
The GeoJSON is then converted to OSM entities:
|
|
37
|
+
|
|
38
|
+
| Shapefile Geometry | OSM Entity |
|
|
39
|
+
| ------------------ | ----------------------------------- |
|
|
40
|
+
| Point | Node |
|
|
41
|
+
| MultiPoint | Multiple Nodes |
|
|
42
|
+
| PolyLine | Way |
|
|
43
|
+
| Polygon | Way (simple) or Relation (w/ holes) |
|
|
44
|
+
| MultiPolygon | Relation |
|
|
45
|
+
|
|
46
|
+
DBF attributes become OSM tags.
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
### `fromShapefile(data, options?, onProgress?)`
|
|
51
|
+
|
|
52
|
+
Create an Osm index from Shapefile data.
|
|
53
|
+
|
|
54
|
+
**Parameters:**
|
|
55
|
+
|
|
56
|
+
- `data` - URL string or ArrayBuffer containing a ZIP file
|
|
57
|
+
- `options` - Optional Osm options (`{ id?: string }`)
|
|
58
|
+
- `onProgress` - Optional progress callback
|
|
59
|
+
|
|
60
|
+
**Returns:** `Promise<Osm>` - Populated Osm index with built indexes
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
MIT
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @osmix/shapefile - Import Shapefiles into Osmix indexes.
|
|
3
|
+
*
|
|
4
|
+
* Provides Shapefile import functionality for Osmix using shpjs:
|
|
5
|
+
* - **Import**: Build an Osm index from Shapefile data (ZIP archive or URL).
|
|
6
|
+
*
|
|
7
|
+
* Shapefiles are first parsed to GeoJSON by shpjs (with automatic projection
|
|
8
|
+
* to WGS84), then converted to OSM entities:
|
|
9
|
+
* - Point/MultiPoint → Node(s)
|
|
10
|
+
* - LineString/MultiLineString → Way(s)
|
|
11
|
+
* - Polygon → Way or Relation (based on ring count)
|
|
12
|
+
* - MultiPolygon → Relation
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Import Shapefile to Osm index
|
|
17
|
+
* import { fromShapefile } from "@osmix/shapefile"
|
|
18
|
+
*
|
|
19
|
+
* const zipBuffer = await Bun.file('./buildings.zip').arrayBuffer()
|
|
20
|
+
* const osm = await fromShapefile(zipBuffer, { id: "buildings" })
|
|
21
|
+
*
|
|
22
|
+
* // Or from URL
|
|
23
|
+
* const osm = await fromShapefile('https://example.com/data.zip')
|
|
24
|
+
*
|
|
25
|
+
* // Query the imported data
|
|
26
|
+
* const buildings = osm.ways.search("building")
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @module @osmix/shapefile
|
|
30
|
+
*/
|
|
31
|
+
export * from "./osm-from-shapefile";
|
|
32
|
+
export * from "./types";
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,cAAc,sBAAsB,CAAA;AACpC,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @osmix/shapefile - Import Shapefiles into Osmix indexes.
|
|
3
|
+
*
|
|
4
|
+
* Provides Shapefile import functionality for Osmix using shpjs:
|
|
5
|
+
* - **Import**: Build an Osm index from Shapefile data (ZIP archive or URL).
|
|
6
|
+
*
|
|
7
|
+
* Shapefiles are first parsed to GeoJSON by shpjs (with automatic projection
|
|
8
|
+
* to WGS84), then converted to OSM entities:
|
|
9
|
+
* - Point/MultiPoint → Node(s)
|
|
10
|
+
* - LineString/MultiLineString → Way(s)
|
|
11
|
+
* - Polygon → Way or Relation (based on ring count)
|
|
12
|
+
* - MultiPolygon → Relation
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Import Shapefile to Osm index
|
|
17
|
+
* import { fromShapefile } from "@osmix/shapefile"
|
|
18
|
+
*
|
|
19
|
+
* const zipBuffer = await Bun.file('./buildings.zip').arrayBuffer()
|
|
20
|
+
* const osm = await fromShapefile(zipBuffer, { id: "buildings" })
|
|
21
|
+
*
|
|
22
|
+
* // Or from URL
|
|
23
|
+
* const osm = await fromShapefile('https://example.com/data.zip')
|
|
24
|
+
*
|
|
25
|
+
* // Query the imported data
|
|
26
|
+
* const buildings = osm.ways.search("building")
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @module @osmix/shapefile
|
|
30
|
+
*/
|
|
31
|
+
export * from "./osm-from-shapefile";
|
|
32
|
+
export * from "./types";
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,cAAc,sBAAsB,CAAA;AACpC,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shapefile-to-OSM conversion utilities.
|
|
3
|
+
*
|
|
4
|
+
* Imports Shapefiles into Osm indexes by first parsing them to GeoJSON
|
|
5
|
+
* using shpjs, then converting the GeoJSON to OSM entities.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { Osm, type OsmOptions } from "@osmix/core";
|
|
10
|
+
import { type ProgressEvent } from "@osmix/shared/progress";
|
|
11
|
+
import type { FeatureCollection } from "geojson";
|
|
12
|
+
import type { ReadShapefileDataTypes } from "./types";
|
|
13
|
+
/**
|
|
14
|
+
* Create an Osm index from Shapefile data.
|
|
15
|
+
*
|
|
16
|
+
* Parses Shapefiles using shpjs (which returns GeoJSON) and converts
|
|
17
|
+
* the features to OSM entities:
|
|
18
|
+
* - Point → Node
|
|
19
|
+
* - LineString/MultiLineString → Way(s) with nodes
|
|
20
|
+
* - Polygon → Way (simple) or Relation (with holes)
|
|
21
|
+
* - MultiPolygon → Relation
|
|
22
|
+
*
|
|
23
|
+
* Feature properties become OSM tags.
|
|
24
|
+
*
|
|
25
|
+
* @param data - Shapefile data (URL string or ArrayBuffer of ZIP).
|
|
26
|
+
* @param options - Osm index options (id, header).
|
|
27
|
+
* @param onProgress - Progress callback for UI feedback.
|
|
28
|
+
* @returns Populated Osm index with built indexes.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { fromShapefile } from "@osmix/shapefile"
|
|
33
|
+
*
|
|
34
|
+
* // From file
|
|
35
|
+
* const zipBuffer = await Bun.file('./buildings.zip').arrayBuffer()
|
|
36
|
+
* const osm = await fromShapefile(zipBuffer, { id: "buildings" })
|
|
37
|
+
*
|
|
38
|
+
* // From URL
|
|
39
|
+
* const osm = await fromShapefile('https://example.com/data.zip')
|
|
40
|
+
*
|
|
41
|
+
* // Query the imported data
|
|
42
|
+
* const buildings = osm.ways.search("building")
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function fromShapefile(data: ReadShapefileDataTypes, options?: Partial<OsmOptions>, onProgress?: (progress: ProgressEvent) => void): Promise<Osm>;
|
|
46
|
+
/**
|
|
47
|
+
* Generator that converts GeoJSON features from a shapefile to OSM entities.
|
|
48
|
+
*
|
|
49
|
+
* This is the core conversion logic, yielding progress events as features
|
|
50
|
+
* are processed.
|
|
51
|
+
*
|
|
52
|
+
* Geometry mapping:
|
|
53
|
+
* - **Point**: Creates a single node with feature properties as tags.
|
|
54
|
+
* - **MultiPoint**: Creates multiple nodes.
|
|
55
|
+
* - **LineString**: Creates nodes for each coordinate, then a way referencing them.
|
|
56
|
+
* - **MultiLineString**: Creates multiple ways.
|
|
57
|
+
* - **Polygon**: Creates a way for simple polygons; for polygons with holes,
|
|
58
|
+
* creates separate ways for outer and inner rings plus a multipolygon relation.
|
|
59
|
+
* - **MultiPolygon**: Creates a multipolygon relation with all rings as way members.
|
|
60
|
+
*
|
|
61
|
+
* @param osm - Target Osm index to populate.
|
|
62
|
+
* @param geojson - Parsed GeoJSON FeatureCollection from shapefile.
|
|
63
|
+
* @param name - Name for progress reporting.
|
|
64
|
+
* @yields Progress events during conversion.
|
|
65
|
+
*/
|
|
66
|
+
export declare function startCreateOsmFromShapefile(osm: Osm, geojson: FeatureCollection, name: string): Generator<ProgressEvent>;
|
|
67
|
+
//# sourceMappingURL=osm-from-shapefile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osm-from-shapefile.d.ts","sourceRoot":"","sources":["../../src/osm-from-shapefile.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,EAEX,iBAAiB,EAKjB,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,aAAa,CAClC,IAAI,EAAE,sBAAsB,EAC5B,OAAO,GAAE,OAAO,CAAC,UAAU,CAAM,EACjC,UAAU,GAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAkB,GACzD,OAAO,CAAC,GAAG,CAAC,CAmBd;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAiB,2BAA2B,CAC3C,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,MAAM,GACV,SAAS,CAAC,aAAa,CAAC,CAiK1B"}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shapefile-to-OSM conversion utilities.
|
|
3
|
+
*
|
|
4
|
+
* Imports Shapefiles into Osm indexes by first parsing them to GeoJSON
|
|
5
|
+
* using shpjs, then converting the GeoJSON to OSM entities.
|
|
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 { parseShapefile } from "./utils";
|
|
13
|
+
/**
|
|
14
|
+
* Create an Osm index from Shapefile data.
|
|
15
|
+
*
|
|
16
|
+
* Parses Shapefiles using shpjs (which returns GeoJSON) and converts
|
|
17
|
+
* the features to OSM entities:
|
|
18
|
+
* - Point → Node
|
|
19
|
+
* - LineString/MultiLineString → Way(s) with nodes
|
|
20
|
+
* - Polygon → Way (simple) or Relation (with holes)
|
|
21
|
+
* - MultiPolygon → Relation
|
|
22
|
+
*
|
|
23
|
+
* Feature properties become OSM tags.
|
|
24
|
+
*
|
|
25
|
+
* @param data - Shapefile data (URL string or ArrayBuffer of ZIP).
|
|
26
|
+
* @param options - Osm index options (id, header).
|
|
27
|
+
* @param onProgress - Progress callback for UI feedback.
|
|
28
|
+
* @returns Populated Osm index with built indexes.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { fromShapefile } from "@osmix/shapefile"
|
|
33
|
+
*
|
|
34
|
+
* // From file
|
|
35
|
+
* const zipBuffer = await Bun.file('./buildings.zip').arrayBuffer()
|
|
36
|
+
* const osm = await fromShapefile(zipBuffer, { id: "buildings" })
|
|
37
|
+
*
|
|
38
|
+
* // From URL
|
|
39
|
+
* const osm = await fromShapefile('https://example.com/data.zip')
|
|
40
|
+
*
|
|
41
|
+
* // Query the imported data
|
|
42
|
+
* const buildings = osm.ways.search("building")
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export async function fromShapefile(data, options = {}, onProgress = logProgress) {
|
|
46
|
+
const osm = new Osm(options);
|
|
47
|
+
onProgress(progressEvent("Parsing Shapefile..."));
|
|
48
|
+
const collections = await parseShapefile(data);
|
|
49
|
+
for (const collection of collections) {
|
|
50
|
+
const name = collection.fileName ?? "shapefile";
|
|
51
|
+
for (const update of startCreateOsmFromShapefile(osm, collection, name)) {
|
|
52
|
+
onProgress(update);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Build indexes after all collections are processed
|
|
56
|
+
onProgress(progressEvent("Building indexes..."));
|
|
57
|
+
osm.buildIndexes();
|
|
58
|
+
osm.buildSpatialIndexes();
|
|
59
|
+
return osm;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Generator that converts GeoJSON features from a shapefile to OSM entities.
|
|
63
|
+
*
|
|
64
|
+
* This is the core conversion logic, yielding progress events as features
|
|
65
|
+
* are processed.
|
|
66
|
+
*
|
|
67
|
+
* Geometry mapping:
|
|
68
|
+
* - **Point**: Creates a single node with feature properties as tags.
|
|
69
|
+
* - **MultiPoint**: Creates multiple nodes.
|
|
70
|
+
* - **LineString**: Creates nodes for each coordinate, then a way referencing them.
|
|
71
|
+
* - **MultiLineString**: Creates multiple ways.
|
|
72
|
+
* - **Polygon**: Creates a way for simple polygons; for polygons with holes,
|
|
73
|
+
* creates separate ways for outer and inner rings plus a multipolygon relation.
|
|
74
|
+
* - **MultiPolygon**: Creates a multipolygon relation with all rings as way members.
|
|
75
|
+
*
|
|
76
|
+
* @param osm - Target Osm index to populate.
|
|
77
|
+
* @param geojson - Parsed GeoJSON FeatureCollection from shapefile.
|
|
78
|
+
* @param name - Name for progress reporting.
|
|
79
|
+
* @yields Progress events during conversion.
|
|
80
|
+
*/
|
|
81
|
+
export function* startCreateOsmFromShapefile(osm, geojson, name) {
|
|
82
|
+
yield progressEvent(`Converting "${name}" to Osmix...`);
|
|
83
|
+
// Map to track nodes by coordinate string for reuse when creating ways and relations
|
|
84
|
+
const nodeMap = new Map();
|
|
85
|
+
let nextNodeId = osm.nodes.size > 0 ? -osm.nodes.size - 1 : -1;
|
|
86
|
+
let nextWayId = osm.ways.size > 0 ? -osm.ways.size - 1 : -1;
|
|
87
|
+
let nextRelationId = osm.relations.size > 0 ? -osm.relations.size - 1 : -1;
|
|
88
|
+
// Helper to get or create a node for a coordinate
|
|
89
|
+
const getOrCreateNode = (lon, lat) => {
|
|
90
|
+
const coordKey = `${lon},${lat}`;
|
|
91
|
+
const existingNodeId = nodeMap.get(coordKey);
|
|
92
|
+
if (existingNodeId !== undefined) {
|
|
93
|
+
return existingNodeId;
|
|
94
|
+
}
|
|
95
|
+
const nodeId = nextNodeId--;
|
|
96
|
+
nodeMap.set(coordKey, nodeId);
|
|
97
|
+
osm.nodes.addNode({
|
|
98
|
+
id: nodeId,
|
|
99
|
+
lon,
|
|
100
|
+
lat,
|
|
101
|
+
});
|
|
102
|
+
return nodeId;
|
|
103
|
+
};
|
|
104
|
+
// Process each feature
|
|
105
|
+
let count = 0;
|
|
106
|
+
for (const feature of geojson.features) {
|
|
107
|
+
const geometry = feature.geometry;
|
|
108
|
+
if (!geometry)
|
|
109
|
+
continue;
|
|
110
|
+
// Normalize winding order for polygons
|
|
111
|
+
const normalizedFeature = geometry.type === "Polygon" || geometry.type === "MultiPolygon"
|
|
112
|
+
? rewindFeature(feature)
|
|
113
|
+
: feature;
|
|
114
|
+
const tags = propertiesToTags(normalizedFeature.properties);
|
|
115
|
+
const featureId = extractFeatureId(normalizedFeature.id);
|
|
116
|
+
const geomType = normalizedFeature.geometry?.type;
|
|
117
|
+
if (geomType === "Point") {
|
|
118
|
+
const coords = normalizedFeature.geometry.coordinates;
|
|
119
|
+
const [lon, lat] = coords;
|
|
120
|
+
if (lon === undefined || lat === undefined)
|
|
121
|
+
continue;
|
|
122
|
+
const nodeId = featureId ?? nextNodeId--;
|
|
123
|
+
osm.nodes.addNode({
|
|
124
|
+
id: nodeId,
|
|
125
|
+
lon,
|
|
126
|
+
lat,
|
|
127
|
+
tags,
|
|
128
|
+
});
|
|
129
|
+
nodeMap.set(`${lon},${lat}`, nodeId);
|
|
130
|
+
}
|
|
131
|
+
else if (geomType === "MultiPoint") {
|
|
132
|
+
const coords = normalizedFeature.geometry
|
|
133
|
+
.coordinates;
|
|
134
|
+
for (const [lon, lat] of coords) {
|
|
135
|
+
if (lon === undefined || lat === undefined)
|
|
136
|
+
continue;
|
|
137
|
+
const nodeId = nextNodeId--;
|
|
138
|
+
osm.nodes.addNode({
|
|
139
|
+
id: nodeId,
|
|
140
|
+
lon,
|
|
141
|
+
lat,
|
|
142
|
+
tags,
|
|
143
|
+
});
|
|
144
|
+
nodeMap.set(`${lon},${lat}`, nodeId);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (geomType === "LineString") {
|
|
148
|
+
const coords = normalizedFeature.geometry.coordinates;
|
|
149
|
+
if (coords.length < 2)
|
|
150
|
+
continue;
|
|
151
|
+
const nodeRefs = [];
|
|
152
|
+
for (const [lon, lat] of coords) {
|
|
153
|
+
if (lon === undefined || lat === undefined)
|
|
154
|
+
continue;
|
|
155
|
+
const nodeId = getOrCreateNode(lon, lat);
|
|
156
|
+
nodeRefs.push(nodeId);
|
|
157
|
+
}
|
|
158
|
+
if (nodeRefs.length >= 2) {
|
|
159
|
+
const wayId = featureId ?? nextWayId--;
|
|
160
|
+
osm.ways.addWay({
|
|
161
|
+
id: wayId,
|
|
162
|
+
refs: nodeRefs,
|
|
163
|
+
tags,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else if (geomType === "MultiLineString") {
|
|
168
|
+
const coords = normalizedFeature.geometry
|
|
169
|
+
.coordinates;
|
|
170
|
+
for (const line of coords) {
|
|
171
|
+
if (line.length < 2)
|
|
172
|
+
continue;
|
|
173
|
+
const nodeRefs = [];
|
|
174
|
+
for (const [lon, lat] of line) {
|
|
175
|
+
if (lon === undefined || lat === undefined)
|
|
176
|
+
continue;
|
|
177
|
+
const nodeId = getOrCreateNode(lon, lat);
|
|
178
|
+
nodeRefs.push(nodeId);
|
|
179
|
+
}
|
|
180
|
+
if (nodeRefs.length >= 2) {
|
|
181
|
+
const wayId = nextWayId--;
|
|
182
|
+
osm.ways.addWay({
|
|
183
|
+
id: wayId,
|
|
184
|
+
refs: nodeRefs,
|
|
185
|
+
tags,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else if (geomType === "Polygon") {
|
|
191
|
+
const coords = normalizedFeature.geometry.coordinates;
|
|
192
|
+
processPolygonRings(osm, coords, tags, featureId, () => nextWayId--, () => nextRelationId--, getOrCreateNode);
|
|
193
|
+
}
|
|
194
|
+
else if (geomType === "MultiPolygon") {
|
|
195
|
+
const coords = normalizedFeature.geometry.coordinates;
|
|
196
|
+
const relationMembers = [];
|
|
197
|
+
for (const polygon of coords) {
|
|
198
|
+
const { outerWayId, holeWayIds } = processPolygonRings(osm, polygon, undefined, // Tags go on relation
|
|
199
|
+
undefined, () => nextWayId--, () => nextRelationId--, getOrCreateNode);
|
|
200
|
+
if (outerWayId !== undefined) {
|
|
201
|
+
relationMembers.push({ type: "way", ref: outerWayId, role: "outer" });
|
|
202
|
+
for (const holeId of holeWayIds) {
|
|
203
|
+
relationMembers.push({ type: "way", ref: holeId, role: "inner" });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (relationMembers.length > 0) {
|
|
208
|
+
osm.relations.addRelation({
|
|
209
|
+
id: featureId ?? nextRelationId--,
|
|
210
|
+
members: relationMembers,
|
|
211
|
+
tags: { type: "multipolygon", ...tags },
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (++count % 1000 === 0) {
|
|
216
|
+
yield progressEvent(`Processed ${count} features from "${name}"...`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
yield progressEvent(`Finished converting "${name}" to Osmix...`);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Process polygon rings and add to OSM index.
|
|
223
|
+
* Returns the created way IDs for use in multipolygon relations.
|
|
224
|
+
*/
|
|
225
|
+
function processPolygonRings(osm, coordinates, tags, featureId, getNextWayId, getNextRelationId, getOrCreateNode) {
|
|
226
|
+
if (coordinates.length === 0) {
|
|
227
|
+
return { outerWayId: undefined, holeWayIds: [] };
|
|
228
|
+
}
|
|
229
|
+
const outerRing = coordinates[0];
|
|
230
|
+
if (!outerRing || outerRing.length < 3) {
|
|
231
|
+
return { outerWayId: undefined, holeWayIds: [] };
|
|
232
|
+
}
|
|
233
|
+
const createRelation = coordinates.length > 1;
|
|
234
|
+
// Create nodes for outer ring
|
|
235
|
+
const outerNodeRefs = [];
|
|
236
|
+
for (const coord of outerRing) {
|
|
237
|
+
const [lon, lat] = coord;
|
|
238
|
+
if (lon === undefined || lat === undefined)
|
|
239
|
+
continue;
|
|
240
|
+
const nodeId = getOrCreateNode(lon, lat);
|
|
241
|
+
outerNodeRefs.push(nodeId);
|
|
242
|
+
}
|
|
243
|
+
if (outerNodeRefs.length < 3) {
|
|
244
|
+
return { outerWayId: undefined, holeWayIds: [] };
|
|
245
|
+
}
|
|
246
|
+
// Ensure ring is closed
|
|
247
|
+
if (outerNodeRefs[0] !== outerNodeRefs[outerNodeRefs.length - 1]) {
|
|
248
|
+
outerNodeRefs.push(outerNodeRefs[0]);
|
|
249
|
+
}
|
|
250
|
+
// Create way for outer ring
|
|
251
|
+
const outerWayId = createRelation
|
|
252
|
+
? getNextWayId()
|
|
253
|
+
: (featureId ?? getNextWayId());
|
|
254
|
+
osm.ways.addWay({
|
|
255
|
+
id: outerWayId,
|
|
256
|
+
refs: outerNodeRefs,
|
|
257
|
+
tags: createRelation ? { area: "yes" } : { area: "yes", ...tags },
|
|
258
|
+
});
|
|
259
|
+
// Create separate ways for holes
|
|
260
|
+
const holeWayIds = [];
|
|
261
|
+
for (let i = 1; i < coordinates.length; i++) {
|
|
262
|
+
const holeRing = coordinates[i];
|
|
263
|
+
if (!holeRing || holeRing.length < 3)
|
|
264
|
+
continue;
|
|
265
|
+
const holeNodeRefs = [];
|
|
266
|
+
for (const coord of holeRing) {
|
|
267
|
+
const [lon, lat] = coord;
|
|
268
|
+
if (lon === undefined || lat === undefined)
|
|
269
|
+
continue;
|
|
270
|
+
const nodeId = getOrCreateNode(lon, lat);
|
|
271
|
+
holeNodeRefs.push(nodeId);
|
|
272
|
+
}
|
|
273
|
+
if (holeNodeRefs.length < 3)
|
|
274
|
+
continue;
|
|
275
|
+
// Ensure hole ring is closed
|
|
276
|
+
if (holeNodeRefs[0] !== holeNodeRefs[holeNodeRefs.length - 1]) {
|
|
277
|
+
holeNodeRefs.push(holeNodeRefs[0]);
|
|
278
|
+
}
|
|
279
|
+
const holeWayId = getNextWayId();
|
|
280
|
+
osm.ways.addWay({
|
|
281
|
+
id: holeWayId,
|
|
282
|
+
refs: holeNodeRefs,
|
|
283
|
+
tags: { area: "yes" },
|
|
284
|
+
});
|
|
285
|
+
holeWayIds.push(holeWayId);
|
|
286
|
+
}
|
|
287
|
+
if (createRelation) {
|
|
288
|
+
osm.relations.addRelation({
|
|
289
|
+
id: featureId ?? getNextRelationId(),
|
|
290
|
+
members: [
|
|
291
|
+
{ type: "way", ref: outerWayId, role: "outer" },
|
|
292
|
+
...holeWayIds.map((id) => ({ type: "way", ref: id, role: "inner" })),
|
|
293
|
+
],
|
|
294
|
+
tags: {
|
|
295
|
+
type: "multipolygon",
|
|
296
|
+
...tags,
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
return { outerWayId, holeWayIds };
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Convert GeoJSON properties to OSM tags.
|
|
304
|
+
*/
|
|
305
|
+
function propertiesToTags(properties) {
|
|
306
|
+
if (!properties || Object.keys(properties).length === 0) {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
const tags = {};
|
|
310
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
311
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
312
|
+
tags[key] = value;
|
|
313
|
+
}
|
|
314
|
+
else if (value != null) {
|
|
315
|
+
tags[key] = String(value);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return Object.keys(tags).length > 0 ? tags : undefined;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Extract numeric ID from feature.
|
|
322
|
+
*/
|
|
323
|
+
function extractFeatureId(featureId) {
|
|
324
|
+
if (featureId === undefined)
|
|
325
|
+
return undefined;
|
|
326
|
+
if (typeof featureId === "number")
|
|
327
|
+
return featureId;
|
|
328
|
+
if (typeof featureId === "string") {
|
|
329
|
+
const numId = Number.parseInt(featureId, 10);
|
|
330
|
+
if (!Number.isNaN(numId))
|
|
331
|
+
return numId;
|
|
332
|
+
}
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=osm-from-shapefile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osm-from-shapefile.js","sourceRoot":"","sources":["../../src/osm-from-shapefile.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,GAAG,EAAmB,MAAM,aAAa,CAAA;AAClD,OAAO,EACN,WAAW,EAEX,aAAa,GACb,MAAM,wBAAwB,CAAA;A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,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"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Shapefile import.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import type { FeatureCollection } from "geojson";
|
|
6
|
+
/**
|
|
7
|
+
* Input types accepted by `fromShapefile`.
|
|
8
|
+
*
|
|
9
|
+
* Supports multiple formats:
|
|
10
|
+
* - `ArrayBufferLike` - Binary ZIP data containing shapefile components
|
|
11
|
+
* - `ReadableStream` - Stream of ZIP data (will be consumed to ArrayBuffer)
|
|
12
|
+
* - `string` - URL to a shapefile or ZIP file
|
|
13
|
+
*/
|
|
14
|
+
export type ReadShapefileDataTypes = ArrayBufferLike | ReadableStream | string;
|
|
15
|
+
/**
|
|
16
|
+
* Result from shpjs parsing.
|
|
17
|
+
* Can be a single FeatureCollection or an array if the ZIP contains multiple shapefiles.
|
|
18
|
+
*/
|
|
19
|
+
export type ShpjsResult = (FeatureCollection & {
|
|
20
|
+
fileName?: string;
|
|
21
|
+
}) | (FeatureCollection & {
|
|
22
|
+
fileName?: string;
|
|
23
|
+
})[];
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD;;;;;;;GAOG;AACH,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG,cAAc,GAAG,MAAM,CAAA;AAE9E;;;GAGG;AACH,MAAM,MAAM,WAAW,GACpB,CAAC,iBAAiB,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAC3C,CAAC,iBAAiB,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for Shapefile data handling.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import type { FeatureCollection } from "geojson";
|
|
6
|
+
import type { ReadShapefileDataTypes } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Parse Shapefile data and return GeoJSON FeatureCollection(s).
|
|
9
|
+
*
|
|
10
|
+
* Uses shpjs to parse Shapefiles and automatically project to WGS84.
|
|
11
|
+
*
|
|
12
|
+
* @param data - Shapefile data (URL string, ArrayBuffer/ReadableStream of ZIP).
|
|
13
|
+
* @returns Array of GeoJSON FeatureCollections with optional fileName.
|
|
14
|
+
* @throws If data is null or parsing fails.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* // From ArrayBuffer
|
|
19
|
+
* const collections = await parseShapefile(zipBuffer)
|
|
20
|
+
*
|
|
21
|
+
* // From URL
|
|
22
|
+
* const collections = await parseShapefile('https://example.com/data.zip')
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseShapefile(data: ReadShapefileDataTypes): Promise<(FeatureCollection & {
|
|
26
|
+
fileName?: string;
|
|
27
|
+
})[]>;
|
|
28
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,OAAO,KAAK,EAAE,sBAAsB,EAAe,MAAM,SAAS,CAAA;AAElE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,cAAc,CACnC,IAAI,EAAE,sBAAsB,GAC1B,OAAO,CAAC,CAAC,iBAAiB,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,CAAC,CAwBxD"}
|