12 unstable releases (5 breaking)

new 0.7.1 Apr 16, 2024
0.6.1 Feb 5, 2024
0.6.0 Sep 28, 2023
0.5.0 Nov 24, 2022
0.3.0 Oct 27, 2021

#448 in Encoding

Download history 5/week @ 2024-02-03 5/week @ 2024-02-17 37/week @ 2024-02-24 2/week @ 2024-03-02 5/week @ 2024-03-09 7/week @ 2024-03-16 5/week @ 2024-03-30 72/week @ 2024-04-06

86 downloads per month

MIT license

110KB
2K SLoC

cjval: schema-validation of CityJSON + CityJSONSeq files

crates.io GitHub license

A library to validate the syntax of CityJSON objects (CityJSON + CityJSONSeq).

It validates against the CityJSON schemas and additional functions have been implemented (because these can't be expressed with JSON Schema).

The following is error checks are performed:

  1. JSON syntax: is the file a valid JSON file?
  2. CityJSON schemas: validation against the schemas (CityJSON v1.0 + v1.1 + v2.0)
  3. Extension schemas: validate against the extra schemas if there's an Extension in the input file
  4. parents_children_consistency: if a City Object references another in its "children", this ensures that the child exists. And that the child has the parent in its "parents"
  5. wrong_vertex_index: checks if all vertex indices exist in the list of vertices
  6. semantics_array: checks if the arrays for the semantics in the geometries have the same shape as that of the geometry and if the values are consistent
  7. textures: checks if the arrays for the textures are coherent (if the vertices exist + if the texture linked to exists)
  8. materials: checks if the arrays for the materials are coherent with the geometry objects and if material linked to exists

It also verifies the following, these are not errors since the file is still considered valid and usable, but they can make the file larger and some parsers might not understand all the properties:

  1. extra_root_properties: if CityJSON has extra root properties, these should be documented in an Extension. If not this warning is returned
  2. duplicate_vertices: duplicated vertices in "vertices" are allowed, but they take up spaces and decreases the topological relationships explicitly in the file. If there are any, cjio has the operator clean to fix this automatically.
  3. unused_vertices: vertices that are not referenced in the file, they take extra space. If there are any, cjio has the operator clean to fix this automatically.

Library + 3 binaries

cjval is a library and has 3 different binaries:

  1. cjval to validate a CityJSON file (it downloads automatically Extensions)
  2. cjseqval to validate a CityJSONSeq file, that is a stream of CityJSONFeature (from stdin)
  3. cjvalext to validate a CityJSON Extension file

Installation/compilation

To install the binaries on your system easily

  1. install the Rust compiler
  2. cargo install cjval --features build-binary

To compile the project (and eventually modify it)

  1. install the Rust compiler
  2. git clone https://github.com/cityjson/cjval.git
  3. cargo build --release --features build-binary (this will ensure the binaries are compiled too)
  4. ./target/release/cjval myfile.json

Web application

The code is uses at https://validator.cityjson.org, it is compiled as a WebAssembly (WASM code here) and a simple GUI was built.

CLI Usage

cjval

The CityJSON schemas are built-in the binary, so it suffices to:

$ cjval myfile.city.json

(the latest schemas of a X.Y version will be automatically fetched)

If the file contains one or more Extensions, eg:

{
  "type": "CityJSON",
  "version": "2.0",
  "extensions":
  {
    "Potato":
    {
      "url": "https://www.cityjson.org/extensions/potato.ext.json",
      "version": "1.0"
    }
  }
...  

then cjval will download automatically the Extension schema files.

If instead you want to use your own local Extension schema(s), you can pass them as argument with the argument -e and this will overwrite the automatic download:

$ cjval myfile.city.json -e ./myextensions/generic.ext.json

cjseqval

To validate a stream of CityJSONFeature (this uses cjseq to generate a stream from a CityJSON file):

$ cjseq cat -f myfile.city.json | cjfval --verbose

and you'll get a short report per line (which is one CityJSON followed by several CityJSONFeature).

Contributors

Dependencies

~12–29MB
~444K SLoC