How bertt/cityjson works
Project Type and Purpose
• This is a .NET 6.0 class‐library project (CityJSON) with two companion CLI tools (cj2pg and cj2glb).
• Purpose: parse and manipulate CityJSON files, convert to NetTopologySuite features, and offer command‐line conversion to PostGIS (cj2pg) and GLB (cj2glb).
File‐Structure Analysis
• Top‐level:
• src – the core CityJSON library (domain types, converters, geometry models, extension methods, IO routines).
• tests – unit tests exercising parsing, geometry conversions, sequence reading.
• tools – two CLI apps (cityjson2pg, cj2glb) plus their tests and fixtures.
• Patterns & Layers:
• Domain layer (CityObject, Geometry, CityJsonDocument)
• Conversion layer (Convertors/*.cs)
• Extension methods (Extensions/*.cs)
• IO layer (CityJsonSeqReader, PolygonCreator)
• External dependency: NetTopologySuite for geometry features; Json.NET for deserialization.
• CI/CD: GitHub workflows under .github/workflows (build, test, release).
Key README Insights
• Shows core API: deserialize to CityJsonDocument, convert to NTS features, read sequence files.
• Describes two CLI tools: “cj2pg” (CityJSON → PostGIS) and “cj2glb” (CityJSON → GLB).
• Lists supported geometry types, appearance (textures), and limitations.
• Core Library (“CityJSON.Core”)
– Domain Model (CityJsonDocument, CityObject, Geometry classes)
– Converters (GeometryConverter, VertexConvertor)
– Extensions (ToFeature, ToFeatures methods)
– IO Services (CityJsonSeqReader, PolygonCreator)
• External Libraries
– Json.NET (Newtonsoft.Json)
– NetTopologySuite
• CLI Tools
– cj2pg (uses “CityJSON.Core” + PostGIS Connector)
– cj2glb (uses “CityJSON.Core” + glTF Builder)
• Data Stores / Outputs
– PostGIS Database
– GLB Files
• Tests
– Unit Tests for Core Library
– Integration Tests for Tools (fixtures folder)
• JSON File → (Json.NET) → Core Library → CityJsonDocument
• CityJsonDocument → (Converters + Extensions) → NetTopologySuite Features
• cj2pg:
– Reads CityJSON → Core Library → Generates SQL → Writes to PostGIS
• cj2glb:
– Reads CityJSON → Core Library → GltfCreator → Outputs .glb file
• CI/CD Workflow → (Build & Test) → Deploy NuGet / Release Binaries
c. Architectural Patterns & Principles
• Layered architecture:
– Presentation (CLI tools)
– Application (Core Library services)
– Domain (Geometry & CityJSON models)
– Infrastructure (IO, external DB/file outputs)
• Single Responsibility: converters, extensions, IO each in their own folder.
• Dependency Injection point: CLI applications wire up the core library.
• Extensibility: extension methods and converter classes allow adding support for new geometry types or outputs.
d. Key Technologies & Frameworks
• .NET 6.0 / C#
• Newtonsoft.Json for JSON parsing
• NetTopologySuite for geometry representations
• Npgsql (implied in cj2pg) for PostGIS integration
• Custom glTF builders in cj2glb