geo2glb 0.1.0__tar.gz

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,34 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .mypy_cache/
10
+
11
+ # Virtual environments
12
+ .venv/
13
+ venv/
14
+ env/
15
+
16
+ # Node (local three.js for headless viewer tests)
17
+ node_modules/
18
+
19
+ # Build outputs
20
+ *.glb
21
+ .build_log
22
+ *.build_log
23
+
24
+ # Editor and OS
25
+ .vscode/
26
+ .idea/
27
+ .DS_Store
28
+
29
+ # Local Claude Code settings
30
+ .claude/settings.local.json
31
+
32
+
33
+ test*.gpkg
34
+ test*.glb
@@ -0,0 +1,137 @@
1
+ # CLAUDE.md
2
+
3
+ Context for working on geo2glb. Read this before changing code. The README is the user-facing doc; this file holds the decisions, conventions and gotchas behind it.
4
+
5
+ ## What this is
6
+
7
+ A tool for site and urban design projects (sites up to about 2 km across):
8
+
9
+ | Part | What it does |
10
+ |---|---|
11
+ | `geo2glb/` | Python CLI. Reads GeoJSON / GeoPackage (EPSG:4326), builds 3D geometry, writes one `.glb` plus a `.build_log` |
12
+ | `viewer/index.html` | Single-file three.js viewer. Drop a `.glb` on it, or serve the folder and use `?file=site.glb`. Without `?file=` it tries `default.glb` next to the page and stays silent if that's missing |
13
+ | `examples/make_sample.py` | Generates the synthetic `examples/sample/sample.gpkg` (layers `points`, `polygons`, `lines`) |
14
+ | `geo2glb/qgis_styles.py` | Writes default QGIS styles into a GeoPackage's `layer_styles` table. `examples/qgis_styles.py` is a CLI wrapper around it |
15
+ | `geo2glb/template.py` | `geo2glb --template x.gpkg`: empty `points` / `polygons` / `lines` layers with the attribute schema as typed fields, plus the QGIS styles. Keep `SCHEMA` in sync when adding attributes |
16
+ | `geo2glb/convert.py` | `--to-geojson x.gpkg [-o dir]` writes `<layer>.geojson` + `<layer>.qml` (QGIS auto-applies a same-name `.qml`); `--to-gpkg files_or_dirs -o x.gpkg` reverses it, using each `.qml` as the layer's default style and `conform()` to restore the template schema |
17
+
18
+ The owner is an infrastructure and urban planning consultant. Write user-facing text (README, log messages, UI) in British English, with no em dashes. Use tables rather than bullet lists in docs where a list is needed.
19
+
20
+ ## Decisions already made (don't revisit without asking)
21
+
22
+ | Topic | Decision |
23
+ |---|---|
24
+ | Output format | `.glb` (glTF binary), not OBJ. Per-feature attributes travel in mesh extras |
25
+ | Inputs | GeoJSON (`.geojson`, `.json`) and GeoPackage (`.gpkg`) only. Shapefile is rejected on purpose because it truncates field names to 10 characters |
26
+ | Input CRS | EPSG:4326. Missing CRS is assumed 4326 (logged); other CRSs are reprojected |
27
+ | Invalid geometry | Repaired with `make_valid`, logged |
28
+ | Classification | Geometry type picks the family, the `type` column picks the feature. LineString defaults to road; `type: railway` is the only other line type. Polygon defaults to building; a polygon with `type: road` falls back to building with a warning. Point defaults to tree |
29
+ | Missing attributes | Always fall back to a default, never fail |
30
+ | Road widths | Permen PUPR No. 5 Tahun 2023, Lampiran II (secondary/urban network, VD <= 60 km/h, new road with kerb and sidewalk). Table in `config.py` |
31
+ | Junctions | Generated in the CLI from the road linestrings as 2D polygons (shapely), before any meshing. Manual override: a polygon with `type: junction` replaces any generated junction whose node lies inside it |
32
+ | Railways | Own attributes (`rail_tracks`, `rail_gauge`, `rail_track_spacing`; `width_meter` = bed width), `road_*` ignored. Not part of the road network (no road junctions). Same-layer crossings with roads become level crossings cut into the road surfaces. Defaults: Cape gauge 1.067 m; track spacing 4.0 m and sleeper pitch 0.6 m are typical values after PM 60/2012, not yet checked against the regulation text |
33
+ | Default building colour | `#b4bcc7` cool grey, so buildings read clearly against the warm ground `#e9e6df`. An off-white was tried and was indistinguishable from the ground |
34
+ | Viewer mouse | Left or right drag rotates and tilts, middle drag pans along the ground (QGIS-like), wheel zooms. Shift/Cmd + left drag pans (OrbitControls built-in). Only a left click selects |
35
+ | World | Flat. No terrain in v1 |
36
+ | Build report | Written to `.build_log` next to the output |
37
+ | Viewer | Plain three.js 0.187.0 via import map from jsDelivr (needs internet). The user chose to keep the CDN rather than bundle three.js. Not MapLibre |
38
+ | Default model | Viewer fetches `default.glb` (relative, same folder) when there's no `?file=`; missing means do nothing, no error. The response must start with the `glTF` magic, so a server that answers 404s with an HTML page is ignored. The user turned down embedding the glb in an HTML file from the CLI |
39
+ | Language | Python, geopandas as the core reader |
40
+
41
+ ## Architecture
42
+
43
+ Pipeline in `cli.build()`:
44
+
45
+ 1. `reader.read_inputs`: expand inputs (a folder contributes every `.geojson` / `.json` / `.gpkg` directly inside it, `.qml` ignored; a GeoPackage contributes every spatial layer; non-spatial tables such as `layer_styles` are skipped), repair geometry, project to the auto-estimated UTM zone, centre on the bbox centre, explode multi-part geometry, drop Z, classify into `Feature(fid, geom_kind, type, geometry, attrs)`.
46
+ 2. `roads.build_roads`: per `layer` value: snap endpoints (0.5 m), node the network (`union_all(grid_size=1e-3)`), find junction nodes (degree >= 3, or two different roads meeting end to end), build junction polygons, clip road surfaces (widest road wins any leftover overlap), then medians, lane markings and sidewalks. Returns mesh specs, each tagged with its `layer`.
47
+ 3. `railways.build_railways`: per `layer`: ballast bed per feature, sleepers (one merged mesh, built with the vectorised `meshing.quad_prisms`), rails. Where the bed meets same-layer road, junction or sidewalk specs, it cuts itself out of those specs in place (`geom.difference`) and adds a `level_crossing` deck at road height with the rails flush in it. Must run after `build_roads` and before meshing.
48
+ 4. `cli.build` meshes the specs (a spec may carry a ready `mesh` instead of `geom`), then polygons (buildings extruded, flat types as thin slabs), then points (trees, box markers), then the ground plane.
49
+ 5. `meshing.SceneBuilder` applies the Z-up to Y-up rotation, sets PBR materials and extras, and exports with trimesh.
50
+
51
+ Rule: all clipping and boolean work happens on 2D shapely geometry. Only extrude at the end. Never do mesh booleans.
52
+
53
+ ### Junction polygon (`roads.junction_polygon`)
54
+
55
+ Union of the incident road buffers (with a round cap on roads that end at the node, to close wedge gaps), clipped to a disk of radius = furthest pairwise overlap + 1.5 x kerb radius, then closed (buffer +r, -r) to round the kerb corners, then clipped to the disk again. Sidewalks are built as (road buffer + touching junctions).buffer(sidewalk width), clipped to a slab along the road so they don't wrap dead ends, minus all road and junction surfaces.
56
+
57
+ ### Road width resolution (`roads.road_profile`)
58
+
59
+ `width_meter` (kerb to kerb) > `road_class` > `road_total_lane` x 3.50 m + 2 x 0.50 m shoulder > default `2/2-TT`. Lanes: `road_total_lane` > class > estimated from carriageway (at least 2 if the carriageway is >= 4.5 m). The width chain is mirrored in the QGIS style expression in `geo2glb/qgis_styles.py`, and so is the railway bed width from `railways.rail_profile`; keep them in sync. Style expressions read fields with `attribute(@feature, 'x')` (via `fld()`), never `"x"`, because a plain field reference errors when the layer lacks the field and the whole width comes back NULL.
60
+
61
+ ### Coordinates and heights
62
+
63
+ | Item | Value |
64
+ |---|---|
65
+ | glTF axes | x = east, y = up, -z = north, metres, origin at data bbox centre |
66
+ | Scene extras | `origin_lonlat`, `origin_projected`, `crs_projected`, `extent_m`, `counts`, `generator` |
67
+ | Z stack (top surfaces) | ground 0, flat types 0.02, road, junction and level crossing 0.04, rails in a level crossing 0.055, markings 0.05 (flat faces only), sidewalk 0.15, median island 0.20, ballast 0.30, sleepers 0.35, rails 0.50 |
68
+ | Layer | `layer` x 6 m for grade separation (flyovers float, no ramps) |
69
+
70
+ ## Gotchas (learned the hard way)
71
+
72
+ | Gotcha | Consequence |
73
+ |---|---|
74
+ | trimesh drops extras keys that start with `_` | Never use underscore-prefixed keys in mesh metadata |
75
+ | GLTFLoader sets `userData.name` to the node name | Overwrites a `name` attribute. That's why extras are nested: `{type, attributes: {...original}, geo2glb: {feature, ...computed}}` |
76
+ | GLTFLoader sanitises node names (`.`, `:`, `/` become `_`) | The viewer groups meshes by `userData.geo2glb.feature`, never by node name. Trees are two meshes (trunk, crown) sharing one feature id |
77
+ | glTF `baseColorFactor` is linear | Hex colours from data are sRGB; convert with `srgb_to_linear` (already done in `SceneBuilder._material`) |
78
+ | three.js 0.187 removed `PCFSoftShadowMap` | Use `PCFShadowMap` |
79
+ | QGIS expressions don't support simple `CASE x WHEN` | Use `CASE WHEN x = ... THEN ... END` |
80
+ | QGIS form dropdowns live in the style QML | `<fieldConfiguration>` with `editWidget` entries, and the root needs `styleCategories="Symbology\|Fields\|Forms"` or QGIS ignores them. A ValueMap entry is `{label: stored value}`; NULL is the GUID `{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}` |
81
+ | QGIS python bindings crash on temporaries | Keep references: `cats = r.categories(); cat = cats[0]; sym = cat.symbol()` |
82
+ | GeoJSON has no schema | Null values are written as `null`, so fields survive, but a field null on every feature reads back as text, and an empty layer loses all fields and its geometry type (GDAL reports `Unknown`). `convert.conform` restores template types; an empty layer's geometry type comes from the `.qml`'s `<layerGeometryType>` (0 point, 1 line, 2 polygon), else the file name |
83
+ | pandas `int64` can't hold nulls | Adding a null integer column with rows needs `Int64` (nullable); pyogrio writes it as INTEGER. Plain `int64` is fine only for empty frames (the template) |
84
+ | Headless QGIS 4 aborts on exit (`mutex lock failed`) | Harmless if it comes after the output; save results before the script ends |
85
+ | Overlapping flat polygons z-fight | Flat types share the same top height; keep sample data non-overlapping |
86
+
87
+ ## Attribute schema (summary)
88
+
89
+ `type`, `colour` (`color` accepted), `height`, `levels` (x 3 m), `base_height`, `road_class`, `width_meter`, `road_total_lane`, `median_width`, `oneway`, `sidewalk_width` (or `sidewalk=yes` for 1.85 m, the PUPR minimum), `kerb_radius` (default 6 m), `layer`, `size` (point markers), `rail_tracks`, `rail_gauge` (m, or mm if > 10), `rail_track_spacing`. Defaults and colours live in `geo2glb/config.py` and can be overridden with `-c style.yaml`.
90
+
91
+ ## Commands
92
+
93
+ ```bash
94
+ pip install -e . # installs the geo2glb command
95
+ python examples/make_sample.py examples/sample # regenerate sample.gpkg (+ QGIS styles)
96
+ geo2glb examples/sample/sample.gpkg -o viewer/site.glb # build; report in viewer/.build_log
97
+ cd viewer && python -m http.server 8765 # then open /?file=site.glb
98
+ python examples/qgis_styles.py some.gpkg # add geo2glb default styles to a GeoPackage
99
+ geo2glb --template new_site.gpkg # empty GeoPackage with the schema and styles
100
+ geo2glb --to-geojson site.gpkg # site_geojson/<layer>.geojson + .qml
101
+ geo2glb --to-gpkg site_geojson -o site.gpkg # and back
102
+ ```
103
+
104
+ ### Versions and releases
105
+
106
+ The version comes from git tags via `setuptools-scm` (`dynamic = ["version"]` in `pyproject.toml`); never write a version number in the code. `geo2glb/__init__.py` reads it with `importlib.metadata`, so an editable install shows the version from when it was last installed (re-run `pip install -e .` to refresh).
107
+
108
+ | State | Version |
109
+ |---|---|
110
+ | Clean checkout at tag `v0.2.0` | `0.2.0` |
111
+ | Commits after the tag | `0.2.1.devN+g<hash>` |
112
+ | Uncommitted changes | adds `.dYYYYMMDD`; never upload such a build |
113
+
114
+ Release: commit everything, `git tag v0.2.0`, `git push origin main --tags`, then `rm -rf dist && python -m build && twine check dist/*` and upload. With setuptools-scm the sdist contains every git-tracked file (examples, viewer, sample GeoPackage); the wheel contains only the `geo2glb` package.
115
+
116
+ There is no test suite yet. Verification so far has been:
117
+
118
+ | Check | How |
119
+ |---|---|
120
+ | CLI | Run on the sample and on an edge-case GeoJSON (manual junction, `layer: 1` flyover, unknown `road_class`, MultiLineString, MultiPoint, Z coordinates, invalid bow-tie polygon), then read `.build_log`. Railway edge cases: through a road junction, `rail_gauge: 1435` (mm), `layer: 1` viaduct over a road, `width_meter` narrower than the tracks, `road_class` on a railway |
121
+ | Viewer | Headless Chrome via Playwright (`--use-gl=angle --use-angle=swiftshader --enable-unsafe-swiftshader`), routing the jsDelivr URLs to a local `node_modules/three`, screenshots of overview, junction and level crossing close-ups, programmatic clicks to check the info panel, middle-button drag to check panning. On the Mac, Playwright isn't installed globally: `npm install playwright three@0.187.0` in a scratch folder, then `npx playwright install chromium` |
122
+ | QGIS styles | `python3-qgis` (QGIS 3.34) headless with `QT_QPA_PLATFORM=offscreen`: load each layer, check the default style loads, evaluate the width expression per feature, render to PNG |
123
+ | QGIS form widgets | Owner's Mac has QGIS 4.0.3: run scripts with `QT_QPA_PLATFORM=offscreen /Applications/QGIS-final-4_0_3.app/Contents/MacOS/python` (the wrapper, not `python3.12`). Load each layer, read `editorWidgetSetup`, instantiate widgets via `QgsGui.editorWidgetRegistry().create(type, layer, idx, config, None, parent)` |
124
+
125
+ When adding tests, start with pytest cases for `road_profile`, the junction count on the sample (8 generated junctions), the Shapefile rejection, and the extras layout of the exported glb.
126
+
127
+ ## Open ideas (not agreed yet, ask before building)
128
+
129
+ | Idea | Note |
130
+ |---|---|
131
+ | Sidewalk band in the QGIS line style | Second line layer under the road, width = road width + 2 x `sidewalk_width`, drawn only when a sidewalk is set. Discussed, user hasn't confirmed |
132
+ | Viewer on a basemap | MapLibre + three.js custom layer, using the origin already in the scene extras |
133
+ | Bundled three.js for offline use | User chose to keep the CDN for now |
134
+ | Roads | Stop lines, zebra crossings, footpaths as a separate line type, ramps and piers for flyovers |
135
+ | Railways | Turnouts, platforms, catenary masts, crossing gates, piers for viaducts, GeoPackage field domains as a non-QGIS alternative to the dropdowns |
136
+ | Buildings | Pitched roofs (`roof_type`) |
137
+ | Terrain | DEM draping |
geo2glb-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sutan Mufti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
geo2glb-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,240 @@
1
+ Metadata-Version: 2.4
2
+ Name: geo2glb
3
+ Version: 0.1.0
4
+ Summary: Compile GeoJSON / GeoPackage features into a 3D .glb for three.js
5
+ Author: Sutan Mufti
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/sutanmufti/geo2glb
8
+ Project-URL: Repository, https://github.com/sutanmufti/geo2glb
9
+ Project-URL: Issues, https://github.com/sutanmufti/geo2glb/issues
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: geopandas>=1.0
14
+ Requires-Dist: pyogrio>=0.7
15
+ Requires-Dist: shapely>=2.0
16
+ Requires-Dist: pyproj>=3.6
17
+ Requires-Dist: trimesh>=4.0
18
+ Requires-Dist: mapbox-earcut>=1.0
19
+ Requires-Dist: pyyaml>=6.0
20
+ Dynamic: license-file
21
+
22
+ # geo2glb
23
+
24
+ Compile GeoJSON and GeoPackage features into a 3D `.glb` scene, and view it in a single-file three.js viewer. Built for sites and urban design projects (up to a few km across).
25
+
26
+ ```
27
+ geo2glb/ Python CLI (geopandas, shapely, trimesh)
28
+ viewer/index.html three.js viewer, no build step
29
+ examples/ synthetic sample GeoPackage, its generator, and the QGIS style writer
30
+ ```
31
+
32
+ ## Install and run
33
+
34
+ ```bash
35
+ pip install -e . # or: pip install geopandas pyogrio shapely pyproj trimesh mapbox-earcut pyyaml
36
+ geo2glb roads.geojson buildings.geojson landscape.gpkg -o out/site.glb
37
+ ```
38
+
39
+ * Inputs are GeoJSON (`.geojson`, `.json`) or GeoPackage (`.gpkg`) only. Shapefile is not accepted because it truncates field names to 10 characters.
40
+ * Any number of inputs. A GeoPackage contributes every layer; use `file.gpkg:layer` for one. A folder contributes every GeoJSON and GeoPackage directly inside it, so the output of `--to-geojson` builds as is: `geo2glb my_site_geojson -o site.glb`.
41
+ * Input CRS is EPSG:4326. A layer with no CRS is assumed to be 4326 (logged); other CRSs are reprojected.
42
+ * The build report is written to `.build_log` next to the output (`--log` to change).
43
+ * `-c style.yaml` overrides defaults and adds road classes (see `geo2glb/config.py` for every key).
44
+ * `--no-ground` skips the ground plane.
45
+
46
+ To start a new site, write an empty template and draw into it in QGIS:
47
+
48
+ ```bash
49
+ geo2glb --template my_site.gpkg # --force to replace an existing file
50
+ ```
51
+
52
+ | Layer | Geometry | Fields |
53
+ |---|---|---|
54
+ | `points` | Point | `name`, `type`, `colour`, `height`, `size` |
55
+ | `polygons` | Polygon | `name`, `type`, `colour`, `height`, `levels`, `base_height`, `layer` |
56
+ | `lines` | LineString | `name`, `type`, `colour`, `road_class`, `width_meter`, `road_total_lane`, `median_width`, `oneway`, `sidewalk_width`, `kerb_radius`, `layer`, `rail_tracks`, `rail_gauge`, `rail_track_spacing` |
57
+
58
+ Every field is optional and the layers are EPSG:4326 with the QGIS default styles already set. Empty layers are fine; build with `geo2glb my_site.gpkg -o site.glb` once you have drawn something.
59
+
60
+ Try it on the sample:
61
+
62
+ ```bash
63
+ python examples/make_sample.py examples/sample
64
+ geo2glb examples/sample/sample.gpkg -o viewer/site.glb
65
+ ```
66
+
67
+ `sample.gpkg` has three layers, `points`, `polygons` and `lines`. Non-spatial tables such as QGIS's `layer_styles` are skipped.
68
+
69
+ ## QGIS styles
70
+
71
+ The sample GeoPackage carries default QGIS styles in its `layer_styles` table, so the layers open already styled. Each layer gets a categorised renderer on the geo2glb type, using the same fallbacks and colours as the CLI:
72
+
73
+ | Layer geometry | Categorised on | Notes |
74
+ |---|---|---|
75
+ | Lines | `coalesce(type, 'road')` | Roads are drawn at their real width in metres, resolved the same way as the CLI (`width_meter`, then `road_class`, then lanes x 3.5 m + 1 m, then 8 m). Railways are drawn at their ballast bed width with a black and white rail line |
76
+ | Polygons | `coalesce(type, 'building')` | Building, junction, each flat type, a red hatch for `type: road` polygons, and a category for any other type |
77
+ | Points | `coalesce(type, 'tree')` | Trees as green circles, anything else as a red square |
78
+
79
+ The same styles set up the attribute form, so the main fields are dropdowns when you draw or edit a feature:
80
+
81
+ | Layer | Field | Form widget |
82
+ |---|---|---|
83
+ | Lines | `type` | Dropdown: not set (road), road, railway |
84
+ | Lines | `road_class` | Dropdown of the PUPR classes with their kerb to kerb width, or not set |
85
+ | Lines | `oneway` | Dropdown: not set (two-way), yes, no |
86
+ | Polygons | `type` | Dropdown: not set (building), building, junction and the flat types |
87
+ | Points | `type` | Free text that suggests values already used in the layer (`tree` is the default, anything else is a marker) |
88
+
89
+ A polygon type outside the list (such as `retail`, extruded like a building) can't be picked in the form; set it in the attribute table with the field calculator. Existing values outside the list are kept.
90
+
91
+ To style your own GeoPackage the same way (one style per spatial layer, chosen by geometry type):
92
+
93
+ ```bash
94
+ python examples/qgis_styles.py my_site.gpkg
95
+ ```
96
+
97
+ It adds a `geo2glb` style and makes it the default; existing styles are kept but no longer default. Remove and re-add the layer in QGIS to pick it up.
98
+
99
+ ## GeoPackage to GeoJSON and back
100
+
101
+ ```bash
102
+ geo2glb --to-geojson my_site.gpkg # -> my_site_geojson/<layer>.geojson + <layer>.qml
103
+ geo2glb --to-gpkg my_site_geojson -o my_site.gpkg # files or folders; --force to replace
104
+ ```
105
+
106
+ QGIS applies a `.qml` with the same name as a GeoJSON automatically, so each file opens with the geo2glb style and the attribute dropdowns.
107
+
108
+ | Direction | What happens |
109
+ |---|---|
110
+ | To GeoJSON | One `.geojson` per layer, with the layer's default style from the GeoPackage as its `.qml` (or the generated geo2glb style if it has none) |
111
+ | To GeoPackage | One layer per `.geojson`, named after the file. Its `.qml` becomes the layer's default style, so style changes made in QGIS travel back. A file without a `.qml` gets the generated style. A file that mixes points, lines and polygons is split into `<name>_points`, `<name>_lines` and `<name>_polygons` |
112
+ | Fields | GeoJSON has no schema, so on the way back the template fields are added where missing and their types restored (text, decimal, whole number). A value that isn't a number, such as `levels: tall`, is kept as text and reported, never dropped |
113
+
114
+ An empty layer can't keep its fields in GeoJSON, so draw into the GeoPackage, or add at least one feature, before converting. The round trip back to GeoPackage still restores an empty layer's fields and geometry type (from its `.qml`).
115
+
116
+ ## Viewer
117
+
118
+ Open `viewer/index.html` and drop a `.glb` on it, or serve the folder and pass the file in the URL:
119
+
120
+ ```bash
121
+ cd viewer && python -m http.server 8000
122
+ # http://localhost:8000/?file=site.glb
123
+ ```
124
+
125
+ | How the page is opened | What loads |
126
+ |---|---|
127
+ | `?file=some.glb` | That file |
128
+ | No `?file=`, and a `default.glb` sits next to `index.html` | `default.glb` |
129
+ | No `?file=` and no `default.glb` | Nothing; drop or choose a file |
130
+
131
+ To publish a site with a model that opens straight away, build it as `default.glb` in the viewer folder (`geo2glb site.gpkg -o viewer/default.glb`) and serve the folder. The default only loads over http; opened from disk, the page shows the drop prompt.
132
+
133
+ Mouse: left or right drag rotates and tilts, middle (wheel button) drag moves the map, the wheel zooms. Without a middle button, Shift + left drag moves the map. Click a feature to see its attributes and the values geo2glb computed. The side panel has layer toggles by `type`, perspective and top views, a sun azimuth/elevation control with shadows, and a PNG screenshot. three.js 0.187 loads from jsDelivr, so the page needs internet access.
134
+
135
+ ## How features are classified
136
+
137
+ The geometry type decides the family; the `type` column decides the feature.
138
+
139
+ | Geometry | `type` missing | `type` value | Result |
140
+ |---|---|---|---|
141
+ | LineString | road | `road` | Road |
142
+ | LineString | | `railway` | Railway (see below) |
143
+ | LineString | | anything else | Road (warning) |
144
+ | Polygon | building | `building` or any other value | Extruded by `height` |
145
+ | Polygon | | `road` | Building (warning: a road polygon makes no sense) |
146
+ | Polygon | | `park`, `green`, `grass`, `water`, `plaza`, `pavement`, `parking`, `landuse` | Flat slab |
147
+ | Polygon | | `junction` | Manual junction (see below) |
148
+ | Point | tree | `tree` | Tree |
149
+ | Point | | anything else | Box marker (`size`, `height`) |
150
+
151
+ Multi-part geometries are split into parts, Z values are dropped, and invalid geometry is repaired with `make_valid` (logged).
152
+
153
+ ## Attribute schema
154
+
155
+ | Attribute | Applies to | Meaning | Fallback |
156
+ |---|---|---|---|
157
+ | `type` | all | Feature type, see above | by geometry |
158
+ | `colour` | all | Hex, e.g. `#c8c8c8` (`color` also accepted) | default per type |
159
+ | `height` | polygons, points | Top height in metres | `levels` x 3 m, else 4 m (tree 10 m) |
160
+ | `levels` | polygons | Storeys | |
161
+ | `base_height` | polygons | Bottom of extrusion (podium gaps, overhangs) | 0 |
162
+ | `road_class` | roads | PUPR tipe jalan: `8/2-T`, `6/2-T`, `4/2-T`, `4/2-TT`, `2/2-TT`, `1/1-TT` | |
163
+ | `width_meter` | roads | Kerb to kerb width, overrides everything | from class or lanes |
164
+ | `road_total_lane` | roads | Total lanes | from class or width |
165
+ | `median_width` | roads | Overrides the class median | from class |
166
+ | `oneway` | roads | `yes` / `true` / `1`: no centre line | no |
167
+ | `sidewalk_width` | roads | Sidewalk each side, 15 cm kerb | none (`sidewalk=yes` gives 1.85 m) |
168
+ | `kerb_radius` | roads | Junction corner radius | 6 m |
169
+ | `rail_tracks` | railways | Number of parallel tracks | 1 |
170
+ | `rail_gauge` | railways | Track gauge in metres; values above 10 are read as millimetres | 1.067 m |
171
+ | `rail_track_spacing` | railways | Centre to centre distance between tracks | 4.0 m |
172
+ | `width_meter` | railways | Ballast bed width, overrides the computed one | from tracks and gauge |
173
+ | `layer` | roads, railways, junctions | Grade separation; `layer` x 6 m elevation | 0 |
174
+
175
+ ## Road widths (Permen PUPR No. 5 Tahun 2023)
176
+
177
+ Widths come from Lampiran II (secondary, urban network), design speed up to 60 km/h, new road with kerb and sidewalk.
178
+
179
+ | `road_class` | Carriageway | Lanes | Median | Outer shoulder | Kerb to kerb |
180
+ |---|---|---|---|---|---|
181
+ | 8/2-T | 2 x 14.00 | 8 | 1.50 | 0.50 | 30.50 |
182
+ | 6/2-T | 2 x 10.50 | 6 | 1.50 | 0.50 | 23.50 |
183
+ | 4/2-T | 2 x 7.00 | 4 | 1.50 | 0.50 | 16.50 |
184
+ | 4/2-TT | 14.00 | 4 | | 0.50 | 15.00 |
185
+ | 2/2-TT | 7.00 | 2 | | 0.50 | 8.00 |
186
+ | 1/1-TT | 1.75 | 1 | | 0.25 | 2.25 |
187
+
188
+ The median is Tipe 1 (0.50 inner shoulder, 0.50 raised island, 0.50 inner shoulder); the island is modelled 20 cm high and stops 2 m short of junctions. Width resolution order: `width_meter` > `road_class` > `road_total_lane` x 3.50 m (the lane width implied by the table) + shoulders > default `2/2-TT`. Sidewalks narrower than the 1.85 m minimum (Pasal 29) are used as given and logged.
189
+
190
+ ## Junctions
191
+
192
+ Junctions are generated from the road linestrings; you never draw them.
193
+
194
+ 1. Endpoints within 0.5 m of another road are snapped to it, then the network is noded.
195
+ 2. A junction is any node where 3 or more segments meet, or where two different roads meet end to end.
196
+ 3. The junction area is the union of the incident road buffers, clipped to a circle that covers all their overlaps plus 1.5 x kerb radius, then closed (buffer out and in) to round the kerb corners.
197
+ 4. Each road surface is its buffer minus all junctions, so nothing overlaps and every road keeps its attributes. Lane markings are generated on the clipped surface, so they stop at the junction mouth. Sidewalks follow the rounded corners.
198
+
199
+ To control a specific junction, add a polygon with `type: junction`. Any generated junction whose node falls inside it is replaced by your polygon.
200
+
201
+ ## Railways
202
+
203
+ A LineString with `type: railway` is built as a ballast bed (30 cm), concrete sleepers every 0.6 m, and two rails per track. The `road_*` attributes, `median_width`, `oneway` and `sidewalk_width` are ignored on a railway (logged).
204
+
205
+ | Item | Value |
206
+ |---|---|
207
+ | Gauge | 1.067 m (Cape gauge, the KAI network) unless `rail_gauge` is set, e.g. 1435 for standard gauge |
208
+ | Sleeper length | gauge + 2 x 0.47 m (2.0 m for Cape gauge) |
209
+ | Bed width | (`rail_tracks` - 1) x `rail_track_spacing` + sleeper length + 2 x 0.50 m ballast shoulder, or `width_meter` |
210
+ | Level crossings | Where a railway crosses a road on the same `layer`, the bed is cut out of the road, junction, sidewalk, marking and median surfaces, and a deck is laid flush with the road with the rails embedded |
211
+ | Grade separation | A railway on a different `layer` from the road passes over or under it, with no crossing |
212
+
213
+ Railways are not part of the road network, so they don't create road junctions. Track spacing and sleeper pitch are typical values after PM 60/2012; check them against the project's standard, and override them in `-c style.yaml` under `railway`.
214
+
215
+ ## Output structure
216
+
217
+ One glTF node per feature, named by its source (`roads.geojson#3`). Each mesh's extras, available in three.js as `object.userData`:
218
+
219
+ ```json
220
+ {
221
+ "type": "road",
222
+ "attributes": { "name": "Boulevard", "road_class": "4/2-T", "sidewalk_width": 3.0 },
223
+ "geo2glb": { "feature": "roads.geojson#0", "width_meter": 16.5, "lanes": 4, "width_source": "road_class 4/2-T (PUPR 5/2023)" }
224
+ }
225
+ ```
226
+
227
+ Attributes are nested because GLTFLoader overwrites `userData.name` with the node name. Scene extras hold the origin (lon/lat and projected), the UTM CRS used and the extent. Axes: x = east, y = up, -z = north, metres, centred on the data.
228
+
229
+ Markings, medians and sidewalks are merged into one mesh per layer to keep the node count down.
230
+
231
+ ## Known limitations (v1)
232
+
233
+ | Limitation | Note |
234
+ |---|---|
235
+ | Flat world | No terrain |
236
+ | Flat roofs only | |
237
+ | Elevated roads and railways (`layer` > 0) float | No ramps or piers |
238
+ | Generated junctions are generic | No splitter islands, slip lanes, stop lines or zebra crossings; draw a manual junction polygon where the design matters |
239
+ | Railways are plain track | No turnouts, platforms, catenary or level crossing gates; where two railways cross, their beds simply overlap |
240
+ | No footpaths | Footpaths are not a separate line type yet |