Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_calculate_bbox(self):
"""Test the calculate_bbox function"""
data = {"vertices": [
[0, 0, 0],
[1, 1, 1]
]}
cm = cityjson.CityJSON(j=data)
bbox = cm.calculate_bbox()
assert bbox == [0, 0, 0, 1, 1, 1]
def test_add_lineage_item(self):
"""Test the add_lineage_item function"""
test_desc = "We did something"
cm = cityjson.CityJSON()
cm.add_lineage_item(test_desc)
assert cm.j["metadata"]["lineage"][0]["processStep"]["description"] == test_desc
cm.add_lineage_item("Something else", features=["id1", "id2"], source=[{"description": "BAG"}], processor={"contactName": "3D geoinfo"})
item = cm.j["metadata"]["lineage"][1]
assert item["processStep"]["description"] == "Something else"
assert len(item["featureIDs"]) == 2
assert len(item["source"]) == 1
assert item["processStep"]["processor"]["contactName"] == "3D geoinfo"
def test_save_to_path(self, data_dir):
p = os.path.join(data_dir, 'rotterdam', 'rotterdam_subset.json')
cm = cityjson.load(p)
new_cos = {}
for co_id, co in cm.cityobjects.items():
co.attributes['cjio_test'] = 'made by Balázs'
new_cos[co_id] = co
cm.cityobjects = new_cos
p_out = os.path.join(data_dir, 'rotterdam_subset_cjio_test.json')
cityjson.save(cm, p_out)
def process_pipeline(processors, input, ignore_duplicate_keys):
extensions = ['.json', '.off', '.poly'] #-- input allowed
try:
f = click.open_file(input, mode='r')
extension = os.path.splitext(input)[1].lower()
if extension not in extensions:
raise IOError("File type not supported (only .json, .off, and .poly).")
#-- OFF file
if (extension == '.off'):
print_cmd_status("Converting %s to CityJSON" % (input))
cm = cityjson.off2cj(f)
#-- POLY file
elif (extension == '.poly'):
print_cmd_status("Converting %s to CityJSON" % (input))
cm = cityjson.poly2cj(f)
#-- CityJSON file
else:
print_cmd_status("Parsing %s" % (input))
cm = cityjson.reader(file=f, ignore_duplicate_keys=ignore_duplicate_keys)
if (cm.get_version() not in cityjson.CITYJSON_VERSIONS_SUPPORTED):
allv = ""
for v in cityjson.CITYJSON_VERSIONS_SUPPORTED:
allv = allv + v + "/"
str = "CityJSON version %s not supported (only versions: %s), not every operators will work.\nPerhaps it's time to upgrade cjio? 'pip install cjio -U'" % (cm.get_version(), allv)
raise click.ClickException(str)
elif (cm.get_version() != cityjson.CITYJSON_VERSIONS_SUPPORTED[-1]):
str = "v%s is not the latest version, and not everything will work.\n" % cm.get_version()
def processor(cm):
#-- mapbox_earcut available?
if (cityjson.MODULE_EARCUT_AVAILABLE == False):
str = "OBJ export skipped: Python module 'mapbox_earcut' missing (to triangulate faces)"
click.echo(click.style(str, fg='red'))
str = "Install it: https://github.com/skogler/mapbox_earcut_python"
click.echo(str)
return cm
#-- output allowed
extensions = ['.obj']
#--
print_cmd_status("Converting CityJSON to OBJ (%s)" % (filename))
f = os.path.basename(filename)
d = os.path.abspath(os.path.dirname(filename))
if not os.path.isdir(d):
os.makedirs(d)
p = os.path.join(d, f)
try:
extension = os.path.splitext(p)[1].lower()
def process_pipeline(processors, input, ignore_duplicate_keys):
extensions = ['.json', '.off', '.poly'] #-- input allowed
try:
f = click.open_file(input, mode='r')
extension = os.path.splitext(input)[1].lower()
if extension not in extensions:
raise IOError("File type not supported (only .json, .off, and .poly).")
#-- OFF file
if (extension == '.off'):
print_cmd_status("Converting %s to CityJSON" % (input))
cm = cityjson.off2cj(f)
#-- POLY file
elif (extension == '.poly'):
print_cmd_status("Converting %s to CityJSON" % (input))
cm = cityjson.poly2cj(f)
#-- CityJSON file
else:
print_cmd_status("Parsing %s" % (input))
cm = cityjson.reader(file=f, ignore_duplicate_keys=ignore_duplicate_keys)
if (cm.get_version() not in cityjson.CITYJSON_VERSIONS_SUPPORTED):
allv = ""
for v in cityjson.CITYJSON_VERSIONS_SUPPORTED:
allv = allv + v + "/"
str = "CityJSON version %s not supported (only versions: %s), not every operators will work.\nPerhaps it's time to upgrade cjio? 'pip install cjio -U'" % (cm.get_version(), allv)
raise click.ClickException(str)
elif (cm.get_version() != cityjson.CITYJSON_VERSIONS_SUPPORTED[-1]):
str = "v%s is not the latest version, and not everything will work.\n" % cm.get_version()
str += "Upgrade the file with 'upgrade_version' command: 'cjio input.json upgrade_version save out.json'"
click.echo(click.style(str, fg='red'))
except ValueError as e:
def processor(cm):
vlatest = cityjson.CITYJSON_VERSIONS_SUPPORTED[-1]
print_cmd_status('Upgrade CityJSON file to v%s' % vlatest)
re, reasons = cm.upgrade_version(vlatest)
if (re == False):
click.echo(click.style("WARNING: %s" % (reasons), fg='red'))
return cm
return processor