landxml 0.6.6 → 0.7.1

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # landxml
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - b200147: Updated publish workflow
8
+ - eec1ceb: Struggling with CI/CD #2
9
+ - b80d579: Struggling with CI/CD #1
10
+
11
+ ## 0.7.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 23cc669: Ai performance optimizations
16
+
3
17
  ## 0.6.6
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -1,48 +1,188 @@
1
- # LandXML Parser for Contour Geojson and 3D Models
1
+ # LandXML Parser for Contour GeoJSON and 3D Models
2
2
 
3
- Easily transform LandXML surfaces into stunning GeoJSON contours or immersive GLB models to explore within threeJS or any popular 3D software.
3
+ Easily transform LandXML surfaces into GeoJSON contours or GLB 3D models for use in ThreeJS, Cesium, QGIS, or any popular 3D/GIS software.
4
4
 
5
- ### Features
5
+ ---
6
6
 
7
- - **toGlb:** Generate GLB models from LandXML surfaces.
8
- - **toGeojsonContours:** Convert LandXML data into detailed contour GeoJSON representations.
9
- - **reprojectGeojson:** Effortlessly reproject GeoJSON data to desired projection using `proj4`
7
+ ## Features
10
8
 
11
- ### Example: Retrieve GeoJSON Contours
9
+ - **`toGlbAndContours`** Generate both a GLB model and GeoJSON contours in a single pass (fastest when you need both outputs).
10
+ - **`toGlb`** — Generate a GLB 3D model from LandXML surfaces.
11
+ - **`toGeojsonContours`** — Convert LandXML surfaces into contour line GeoJSON.
12
+ - **`reprojectGeoJson`** — Reproject GeoJSON coordinates to any projection using `proj4`.
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install landxml
20
+ ```
21
+
22
+ ---
23
+
24
+ ## Examples
25
+
26
+ ### Get contours and a GLB model together (recommended)
27
+
28
+ When you need both outputs, use `toGlbAndContours` — it parses the XML once and shares computed data between both outputs, making it significantly faster than calling `toGlb` and `toGeojsonContours` separately.
29
+
30
+ ```typescript
31
+ import { toGlbAndContours, reprojectGeoJson } from "landxml";
32
+
33
+ const landXmlString = `<?xml version="1.0"?>...<LandXML>...</LandXML>`;
34
+
35
+ const surfaces = await toGlbAndContours(
36
+ landXmlString,
37
+ 2, // contour interval (LandXML units)
38
+ true, // generate outline
39
+ "auto", // GLB centre: "auto" | "origin" | [x, y]
40
+ );
41
+
42
+ const { glb, center, geojson, wktString, download } = surfaces[0];
43
+
44
+ // Download the GLB file in the browser
45
+ download();
46
+
47
+ // Reproject contours from the LandXML CRS to WGS84
48
+ const reprojected = reprojectGeoJson(geojson, wktString, "WGS84", false);
49
+ ```
50
+
51
+ ---
52
+
53
+ ### Get GeoJSON contours only
12
54
 
13
55
  ```typescript
14
56
  import { toGeojsonContours, reprojectGeoJson } from "landxml";
15
57
 
16
- const loadGeojson = async () => {
17
- const landXmlString = "<?xml version="1.0"?>...</LandXML>";
18
- const contourInterval = 2;
19
- const geojsonSurfaces = await toGeojsonContours(landXmlString, contourInterval);
58
+ const landXmlString = `<?xml version="1.0"?>...<LandXML>...</LandXML>`;
20
59
 
21
- // Retrieve geojson with raw LandXML coordinates
22
- let { geojson, wktString } = geojsonSurfaces[0];
60
+ const surfaces = await toGeojsonContours(
61
+ landXmlString,
62
+ 2, // contour interval (metres)
63
+ true, // include surface outline as a z=0 feature
64
+ );
23
65
 
24
- // Reproject GeoJSON to a desired coordinate system (e.g., WGS84)
25
- const targetCoordinateSystem = wktString || "WGS84";
26
- const keepOriginalGeometryAsFeatureProperties = false;
27
- return reprojectGeoJson(geojson, wktString, targetCoordinateSystem, keepOriginalGeometryAsFeatureProperties);
28
- }
66
+ const { geojson, wktString } = surfaces[0];
67
+
68
+ // Reproject from the LandXML coordinate system to WGS84 for web mapping
69
+ const reprojected = reprojectGeoJson(geojson, wktString ?? "WGS84", "WGS84", false);
70
+
71
+ console.log(reprojected.features.length); // number of contour + outline features
29
72
  ```
30
73
 
31
- ### Example: Convert to GLB 3D model
74
+ ---
75
+
76
+ ### Convert to a GLB 3D model
32
77
 
33
78
  ```typescript
34
79
  import { toGlb } from "landxml";
35
80
 
36
- const LandXml2GlbModel = async () => {
37
- const landXmlString = "<?xml version="1.0"?>...</LandXML>";
81
+ const landXmlString = `<?xml version="1.0"?>...<LandXML>...</LandXML>`;
38
82
 
39
- // Define how the model's origin should be positioned (options: "origin" | "auto" | [x: number, y: number])
40
- const center = "auto";
41
- const glbSurfaces = await toGlb(landXmlString, center);
83
+ const surfaces = await toGlb(
84
+ landXmlString,
85
+ "auto", // centre strategy: "auto" | "origin" | [x, y]
86
+ );
42
87
 
43
- let { download, glb } = glbSurfaces[0];
44
- download()
88
+ const { glb, center, download } = surfaces[0];
45
89
 
46
- // Alternatively, process the raw binary data from the 'glb' variable (Uint8Array)
47
- }
90
+ // Trigger a browser download of the .glb file
91
+ download();
92
+
93
+ // Or use the raw binary (Uint8Array) directly — e.g. load into Three.js
94
+ const loader = new GLTFLoader();
95
+ loader.parse(glb.buffer, "", (gltf) => {
96
+ scene.add(gltf.scene);
97
+ });
48
98
  ```
99
+
100
+ ---
101
+
102
+ ### Work with a specific surface in a multi-surface LandXML
103
+
104
+ LandXML files can contain multiple surfaces. Use `surfaceId` to select one by name or by index.
105
+
106
+ ```typescript
107
+ import { toGeojsonContours } from "landxml";
108
+
109
+ const landXmlString = `<?xml version="1.0"?>...<LandXML>...</LandXML>`;
110
+
111
+ // By name
112
+ const byName = await toGeojsonContours(landXmlString, 2, true, "ExistingGround");
113
+
114
+ // By index (0-based)
115
+ const byIndex = await toGeojsonContours(landXmlString, 2, true, 1);
116
+ ```
117
+
118
+ ---
119
+
120
+ ### Reproject GeoJSON
121
+
122
+ `reprojectGeoJson` wraps `proj4` and works with both WKT strings (exported by Civil 3D when a drawing is geo-referenced) and standard proj4 definition strings.
123
+
124
+ ```typescript
125
+ import { reprojectGeoJson } from "landxml";
126
+
127
+ // wktString is available on every surface returned by toGeojsonContours / toGlbAndContours
128
+ const reprojected = reprojectGeoJson(
129
+ geojson,
130
+ wktString, // source CRS — WKT or proj4 string
131
+ "WGS84", // target CRS (default)
132
+ true, // keep original geometry as feature property "_rawGeometry"
133
+ );
134
+ ```
135
+
136
+ ---
137
+
138
+ ## API Reference
139
+
140
+ ### `toGlbAndContours(landXmlString, contourInterval?, generateOutline?, center?, surfaceId?)`
141
+
142
+ | Parameter | Type | Default | Description |
143
+ | ----------------- | ------------------------------ | -------- | -------------------------------------------------- |
144
+ | `landXmlString` | `string` | — | Raw LandXML XML string |
145
+ | `contourInterval` | `number` | `2` | Vertical interval between contour lines |
146
+ | `generateOutline` | `boolean` | `true` | Append surface boundary as a `z=0` GeoJSON feature |
147
+ | `center` | `"auto" \| "origin" \| [x, y]` | `"auto"` | GLB model origin strategy |
148
+ | `surfaceId` | `string \| number` | `-1` | Surface name or index; `-1` returns all surfaces |
149
+
150
+ Returns `Promise<GlbAndContoursResult[]>` where each element contains `name`, `description`, `sourceFile`, `timeStamp`, `wktString`, `glb`, `center`, `download`, and `geojson`.
151
+
152
+ ---
153
+
154
+ ### `toGeojsonContours(landXmlString, contourInterval?, generateOutline?, surfaceId?)`
155
+
156
+ | Parameter | Type | Default | Description |
157
+ | ----------------- | ------------------ | ------- | -------------------------------------------------- |
158
+ | `landXmlString` | `string` | — | Raw LandXML XML string |
159
+ | `contourInterval` | `number` | `2` | Vertical interval between contour lines |
160
+ | `generateOutline` | `boolean` | `true` | Append surface boundary as a `z=0` GeoJSON feature |
161
+ | `surfaceId` | `string \| number` | `-1` | Surface name or index; `-1` returns all surfaces |
162
+
163
+ Returns `Promise<{ name, description, sourceFile, timeStamp, wktString?, geojson }[]>`.
164
+
165
+ ---
166
+
167
+ ### `toGlb(landXmlString, center?, surfaceId?)`
168
+
169
+ | Parameter | Type | Default | Description |
170
+ | --------------- | ------------------------------ | -------- | ----------------------------------------------------------------------------------------------------------- |
171
+ | `landXmlString` | `string` | — | Raw LandXML XML string |
172
+ | `center` | `"auto" \| "origin" \| [x, y]` | `"auto"` | GLB model origin strategy. 3D models are sensitive to large coordinates — `"auto"` offsets to the XY median |
173
+ | `surfaceId` | `string \| number` | `-1` | Surface name or index; `-1` returns all surfaces |
174
+
175
+ Returns `Promise<{ name, description, sourceFile, timeStamp, glb, center, download }[]>`.
176
+
177
+ ---
178
+
179
+ ### `reprojectGeoJson(geojson, sourceProjection, targetProjection?, keepOriginalGeometry?)`
180
+
181
+ | Parameter | Type | Default | Description |
182
+ | ---------------------- | ------------------- | --------- | ------------------------------------------------------------------ |
183
+ | `geojson` | `FeatureCollection` | — | GeoJSON to reproject |
184
+ | `sourceProjection` | `string` | — | Proj4 or WKT string of the source CRS |
185
+ | `targetProjection` | `string` | `"WGS84"` | Proj4 or WKT string of the target CRS |
186
+ | `keepOriginalGeometry` | `boolean` | `true` | Store original coordinates under `feature.properties._rawGeometry` |
187
+
188
+ Returns the mutated `FeatureCollection` with updated coordinates.
package/dist/index.d.mts CHANGED
@@ -59,4 +59,69 @@ declare const toGeojsonContours: (landXmlString: string, contourInterval?: numbe
59
59
  */
60
60
  declare const reprojectGeoJson: (geojson: FeatureCollection, sourceProjection: string, targetProjection?: string, keepOriginalGeometryAsFeatureProperty?: boolean) => FeatureCollection<geojson.Geometry, geojson.GeoJsonProperties>;
61
61
 
62
- export { reprojectGeoJson, toGeojsonContours, toGlb };
62
+ type GlbAndContoursResult = {
63
+ name: string;
64
+ description: string;
65
+ sourceFile: string;
66
+ timeStamp: string;
67
+ wktString?: string;
68
+ /** Binary GLB data */
69
+ glb: Uint8Array;
70
+ /** XY center used to offset the GLB model from origin */
71
+ center: [x: number, y: number];
72
+ /** Convenience download trigger (browser only) */
73
+ download: () => void;
74
+ /** Contour lines + optional outline as a GeoJSON FeatureCollection */
75
+ geojson: FeatureCollection<LineString, {
76
+ z: number;
77
+ }>;
78
+ };
79
+ /**
80
+ * Converts a LandXML string into **both** a GLB 3-D model and GeoJSON contour
81
+ * lines in a single pass — the XML is parsed once and the triangle/elevation
82
+ * data computed once and shared between both outputs.
83
+ *
84
+ * Use this instead of calling `toGlb` + `toGeojsonContours` separately when
85
+ * you need both outputs, as it eliminates all redundant work.
86
+ *
87
+ * @param landXmlString Raw LandXML string
88
+ * @param contourInterval Vertical interval between contour lines (default 2)
89
+ * @param generateOutline When true, the outline of each surface is appended to
90
+ * the GeoJSON as a z=0 feature (default true)
91
+ * @param center GLB origin strategy: "auto" (median XY), "origin" ([0,0]),
92
+ * or an explicit [x, y] pair (default "auto")
93
+ * @param surfaceId Surface name or 0-based index to process a single
94
+ * surface; -1 processes all surfaces (default -1)
95
+ */
96
+ declare const toGlbAndContours: (landXmlString: string, contourInterval?: number, generateOutline?: boolean, center?: "auto" | "origin" | [
97
+ x: number,
98
+ y: number
99
+ ], surfaceId?: string | number) => Promise<GlbAndContoursResult[]>;
100
+
101
+ type ParsedSurface = {
102
+ sourceFile: string;
103
+ timeStamp: string;
104
+ name: string;
105
+ description: string;
106
+ wktString?: string;
107
+ surfaceDefinition: {
108
+ points: [x: number, y: number, z: number][];
109
+ faces: [vertIndexA: number, vertIndexB: number, vertIndexC: number][];
110
+ faceNeighbors: [faceIndex: number, faceIndex: number, faceIndex: number][];
111
+ };
112
+ };
113
+
114
+ /**
115
+ * Derives the triangle list and elevation range from a ParsedSurface.
116
+ * Call this once and pass the result to both getContours() and getGlb() when
117
+ * you need both outputs for the same surface — avoids double-traversal of the
118
+ * (potentially large) faces/points arrays.
119
+ */
120
+ type PrecomputedSurfaceData = {
121
+ triangles: [x: number, y: number, z: number][][];
122
+ minElevation: number;
123
+ maxElevation: number;
124
+ };
125
+ declare const precomputeSurfaceData: (data: ParsedSurface) => PrecomputedSurfaceData;
126
+
127
+ export { type GlbAndContoursResult, type PrecomputedSurfaceData, precomputeSurfaceData, reprojectGeoJson, toGeojsonContours, toGlb, toGlbAndContours };
package/dist/index.d.ts CHANGED
@@ -59,4 +59,69 @@ declare const toGeojsonContours: (landXmlString: string, contourInterval?: numbe
59
59
  */
60
60
  declare const reprojectGeoJson: (geojson: FeatureCollection, sourceProjection: string, targetProjection?: string, keepOriginalGeometryAsFeatureProperty?: boolean) => FeatureCollection<geojson.Geometry, geojson.GeoJsonProperties>;
61
61
 
62
- export { reprojectGeoJson, toGeojsonContours, toGlb };
62
+ type GlbAndContoursResult = {
63
+ name: string;
64
+ description: string;
65
+ sourceFile: string;
66
+ timeStamp: string;
67
+ wktString?: string;
68
+ /** Binary GLB data */
69
+ glb: Uint8Array;
70
+ /** XY center used to offset the GLB model from origin */
71
+ center: [x: number, y: number];
72
+ /** Convenience download trigger (browser only) */
73
+ download: () => void;
74
+ /** Contour lines + optional outline as a GeoJSON FeatureCollection */
75
+ geojson: FeatureCollection<LineString, {
76
+ z: number;
77
+ }>;
78
+ };
79
+ /**
80
+ * Converts a LandXML string into **both** a GLB 3-D model and GeoJSON contour
81
+ * lines in a single pass — the XML is parsed once and the triangle/elevation
82
+ * data computed once and shared between both outputs.
83
+ *
84
+ * Use this instead of calling `toGlb` + `toGeojsonContours` separately when
85
+ * you need both outputs, as it eliminates all redundant work.
86
+ *
87
+ * @param landXmlString Raw LandXML string
88
+ * @param contourInterval Vertical interval between contour lines (default 2)
89
+ * @param generateOutline When true, the outline of each surface is appended to
90
+ * the GeoJSON as a z=0 feature (default true)
91
+ * @param center GLB origin strategy: "auto" (median XY), "origin" ([0,0]),
92
+ * or an explicit [x, y] pair (default "auto")
93
+ * @param surfaceId Surface name or 0-based index to process a single
94
+ * surface; -1 processes all surfaces (default -1)
95
+ */
96
+ declare const toGlbAndContours: (landXmlString: string, contourInterval?: number, generateOutline?: boolean, center?: "auto" | "origin" | [
97
+ x: number,
98
+ y: number
99
+ ], surfaceId?: string | number) => Promise<GlbAndContoursResult[]>;
100
+
101
+ type ParsedSurface = {
102
+ sourceFile: string;
103
+ timeStamp: string;
104
+ name: string;
105
+ description: string;
106
+ wktString?: string;
107
+ surfaceDefinition: {
108
+ points: [x: number, y: number, z: number][];
109
+ faces: [vertIndexA: number, vertIndexB: number, vertIndexC: number][];
110
+ faceNeighbors: [faceIndex: number, faceIndex: number, faceIndex: number][];
111
+ };
112
+ };
113
+
114
+ /**
115
+ * Derives the triangle list and elevation range from a ParsedSurface.
116
+ * Call this once and pass the result to both getContours() and getGlb() when
117
+ * you need both outputs for the same surface — avoids double-traversal of the
118
+ * (potentially large) faces/points arrays.
119
+ */
120
+ type PrecomputedSurfaceData = {
121
+ triangles: [x: number, y: number, z: number][][];
122
+ minElevation: number;
123
+ maxElevation: number;
124
+ };
125
+ declare const precomputeSurfaceData: (data: ParsedSurface) => PrecomputedSurfaceData;
126
+
127
+ export { type GlbAndContoursResult, type PrecomputedSurfaceData, precomputeSurfaceData, reprojectGeoJson, toGeojsonContours, toGlb, toGlbAndContours };