def preprocess(self, is_test_run): cityFp = open(self._filename) mainCity = cityjson.CityJSON(file=cityFp, ignore_duplicate_keys=False) print('Loaded: ' + self._filename) print('City has ' + str(len(mainCity.j['CityObjects'].keys())) + ' objects.') tempLoopCounter = 0 for id in mainCity.j['CityObjects'].keys(): sCity = mainCity.get_subset_ids([id], exclude=False) print('Got id: ' + id) # print('scity ' + json.dumps(sCity.j)) raw_data = sCity.j obj_value = sCity.export2obj() new_data_obj = self.add_data_blob( id, bytes(json.dumps(raw_data), 'utf-8'), bytes(obj_value.getvalue(), 'utf-8')) print('Added new geometry for id: ' + str(id)) new_meta_data = new_data_obj.meta_data() new_meta_data["id"] = id new_meta_data["BBox"] = str(sCity.get_bbox()) # print(new_meta_data) if is_test_run: if tempLoopCounter >= 5: break else: tempLoopCounter += 1
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_calculate_bbox_with_transform(self): """Test the calculate_bbox function""" data = { "vertices": [[0, 0, 0], [1, 1, 1]], "transform": { "scale": [0.001, 0.001, 0.001], "translate": [100, 100, 100] } } cm = cityjson.CityJSON(j=data) bbox = cm.calculate_bbox() assert bbox == [100, 100, 100, 100.001, 100.001, 100.001]
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 cityobj(p): with open(p, 'r') as f: c = cityjson.CityJSON(file=f) return c
def cube_compressed(data_dir): p = os.path.join(data_dir, 'cube.c.json') with open(p, 'r') as f: yield cityjson.CityJSON(file=f)
def dummy_noappearance(data_dir): p = os.path.join(data_dir, 'dummy', 'dummy_noappearance.json') with open(p, 'r') as f: yield cityjson.CityJSON(file=f)
def zurich_subset(data_dir): p = os.path.join(data_dir, 'zurich', 'zurich_subset_lod2.json') with open(p, 'r') as f: yield cityjson.CityJSON(file=f)
def rotterdam_subset(data_dir): p = os.path.join(data_dir, 'rotterdam', 'rotterdam_subset.json') with open(p, 'r') as f: yield cityjson.CityJSON(file=f)
def delft_1b(data_dir): p = os.path.join(data_dir, 'delft_1b.json') with open(p, 'r') as f: yield cityjson.CityJSON(file=f)
def rectangle(data_dir): p = os.path.join(data_dir, 'dummy', 'rectangle.json') with open(p, 'r') as f: yield cityjson.CityJSON(file=f)
def minimal(data_dir): p = os.path.join(data_dir, 'minimal.json') with open(p, 'r') as f: yield cityjson.CityJSON(file=f)
def rotterdam(data_dir): p = os.path.join(data_dir, 'rotterdam', '3-20-DELFSHAVEN_uncompressed.json') with open(p, 'r') as f: yield cityjson.CityJSON(file=f)
import configparser from pathlib import Path from cjio import cityjson from cjio.models import CityObject, Geometry config = configparser.ConfigParser() config.read('config.ini') host = config['DEFAULT']['host'] schema = config['DEFAULT']['schema'] table = config['DEFAULT']['table'] dbname = config['DEFAULT']['dbname'] user = config['DEFAULT']['user'] bbox = [111664.8, 559448.0, 113415.9, 560217.5] cm = cityjson.CityJSON() def simpletocjio(geom): surface = geom.replace('LINESTRING Z (', '', 1).replace(')', '').split(',') s = [] for point in surface: c = point.split(' ') c = map(lambda v: float(v), c) s.append(tuple(c)) return s def runquery(query): global cm