Python bindings of cjval, the official validator for CityJSON files.
To install the latest release: pip install cjvalpy
- install latest Rust
- install maturin
maturin build --release
cd ./target/wheels/
pip install [name-wheel].whl
will install it to your local Python
- install Rust (v1.39+)
- install maturin
maturin develop
- move to another folder, and
import cjvalpy
shouldn't return any error
Made to be used with cjio:
cjio myfile.city.json validate
but can be used directly in python:
import cjvalpy
import json
import urllib.request
f = open("~/data/noise.city.json")
fj = json.loads(f.read())
js = []
js.append(json.dumps(fj))
print("Downloading the Extension JSON schema file(s):")
if "extensions" in fj:
for ext in fj["extensions"]:
theurl = fj["extensions"][ext]["url"]
try:
with urllib.request.urlopen(fj["extensions"][ext]["url"]) as f:
sf = f.read().decode('utf-8')
js.append(sf)
except:
s = "'%s' cannot be downloaded\nAbort" % fj["extensions"][ext]["url"]
raise Exception(s)
val = cjvalpy.CJValidator(js)
val.validate()
re = val.get_report()
print(val.get_report())