You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* manage test data with git
* added test data
* define extension schema
* fix fb schema
* impl encoding of extension
* decode
* add e2e for extension
* style: format code with Rustfmt
This commit fixes the style issues introduced in 805d9c8 according to the output
from Rustfmt.
Details: #20
* docs: document about extension
* Update src/rust/fcb_core/src/writer/serializer.rs
Co-authored-by: Copilot <[email protected]>
---------
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Copilot <[email protected]>
Copy file name to clipboardExpand all lines: .cursor/rules/memory/specification.md
+112
Original file line number
Diff line number
Diff line change
@@ -510,3 +510,115 @@ graph TD
510
510
```
511
511
512
512
this structure allows for efficient querying and retrieval of city objects based on both spatial and attribute criteria.
513
+
514
+
## extension support
515
+
516
+
flatcitybuf implements full support for the cityjson extension mechanism, allowing customization of the data model while maintaining compatibility with standard tools.
517
+
518
+
### extension mechanism background
519
+
520
+
cityjson extensions enable users to:
521
+
522
+
1.**add new attributes** to existing cityobjects
523
+
2.**create new cityobject types** beyond the standard types
524
+
3.**add new properties** at the root level of a cityjson file
525
+
4.**define new semantic surface types**
526
+
527
+
extensions are identified using a "+" prefix (e.g., "+noise") and are defined in json schema files hosted at urls referenced in the cityjson file.
528
+
529
+
### extension schema implementation
530
+
531
+
flatcitybuf supports extensions through specialized schema components in three main areas:
532
+
533
+
#### 1. extension definition in `extension.fbs`
534
+
535
+
```flatbuffers
536
+
table Extension {
537
+
name: string; // Extension name (e.g., "+Noise")
538
+
description: string; // Description of the extension
539
+
url: string; // URL to the extension schema
540
+
version: string; // Extension version
541
+
version_cityjson: string; // Compatible CityJSON version
542
+
extra_attributes: string; // Stringified JSON schema for attributes
543
+
extra_city_objects: string; // Stringified JSON schema for city objects
544
+
extra_root_properties: string; // Stringified JSON schema for root properties
545
+
extra_semantic_surfaces: string; // Stringified JSON schema for semantic surfaces
546
+
}
547
+
```
548
+
549
+
#### 2. extended cityobjects in `feature.fbs`
550
+
551
+
```flatbuffers
552
+
enum CityObjectType:ubyte {
553
+
// ... standard types ...
554
+
ExtensionObject
555
+
}
556
+
557
+
table CityObject {
558
+
type: CityObjectType;
559
+
extension_type: string; // e.g. "+NoiseCityFurnitureSegment"
560
+
// ... other fields ...
561
+
}
562
+
```
563
+
564
+
#### 3. extended semantic surfaces in `geometry.fbs`
565
+
566
+
```flatbuffers
567
+
enum SemanticSurfaceType:ubyte {
568
+
// ... standard types ...
569
+
ExtraSemanticSurface
570
+
}
571
+
572
+
table SemanticObject {
573
+
type: SemanticSurfaceType;
574
+
extension_type: string; // e.g. "+ThermalSurface"
575
+
// ... other fields ...
576
+
}
577
+
```
578
+
579
+
#### 4. extension references in header
580
+
581
+
extensions are referenced in the header, allowing applications to understand which extensions are used in the file:
582
+
583
+
```flatbuffers
584
+
table Header {
585
+
// ... other fields ...
586
+
extensions: [Extension]; // List of extensions used
587
+
// ... other fields ...
588
+
}
589
+
```
590
+
591
+
### encoding and decoding strategy
592
+
593
+
the encoding and decoding of extensions follows these principles:
594
+
595
+
1.**self-contained extensions**: extension schemas are embedded directly in the file as stringified json, making the file self-contained and usable without external references.
596
+
597
+
2.**enum with extension marker**: special enum values (`extensionobject`, `extrasemanticssurface`) combined with a string field (`extension_type`) handle extended types. this approach maintains enum efficiency while supporting unlimited extension types.
598
+
599
+
3.**unified attribute storage**: extension attributes are treated the same as core attributes, both encoded in the attributes byte array. this simplifies implementation and maintains query performance.
600
+
601
+
4.**root properties**: extension properties at the root level are stored in the header's attributes field.
602
+
603
+
when encoding:
604
+
605
+
- if a cityobject type starts with "+", it's encoded as `extensionobject` with the full type name stored in the `extension_type` field
606
+
- if a semantic surface type starts with "+", it's encoded as `extrasemanticssurface` with the full type name stored in the `extension_type` field
607
+
- extension-specific attributes are encoded as regular attributes in the binary attribute array
608
+
609
+
when decoding:
610
+
611
+
- if a cityobject has type `extensionobject` and a non-null `extension_type`, the extension type name is used
612
+
- if a semantic surface has type `extrasemanticssurface` and a non-null `extension_type`, the extension type name is used
613
+
- all attributes are decoded, regardless of whether they belong to the core schema or extensions
614
+
615
+
### benefits of this approach
616
+
617
+
this implementation balances several key factors:
618
+
619
+
-**performance**: maintains fast access to core data structures
620
+
-**flexibility**: supports any cityjson extension
621
+
-**self-containment**: makes files usable without external references
622
+
-**simplicity**: uses consistent patterns for extension handling
623
+
624
+
the schema is agnostic about the validity of extension data, focusing instead on accurately representing the structure of extended cityjson files in an efficient binary format.
// Extension objects. In the JSON data, it's written like "+ThermalSurface". However as we can't expect the extended semantic surface type, just mark it as "ExtraSemanticSurface".
27
+
ExtraSemanticSurface
25
28
}
26
29
27
30
enum GeometryType:ubyte {
@@ -85,6 +88,7 @@ table SemanticObject {
85
88
attributes:[ubyte];
86
89
children:[uint];
87
90
parent:uint = null; // default is null, important to be able to check if this field is set
91
+
extension_type: string; // extension type of the semantic object. e.g. "+ThermalSurface"
0 commit comments