Skip to content

Commit

Permalink
Add bbox to info() operator
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoledoux committed Jun 25, 2019
1 parent 7873c20 commit df59c05
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions cjio/cityjson.py
Expand Up @@ -427,17 +427,15 @@ def validate(self, skip_schema=False, folder_schemas=None):
return (isValid, woWarnings, es, ws)


def update_bbox(self):
"""
Update the bbox (["metadata"]["bbox"]) of the CityJSON.
If there is none then it is added.
"""
def get_bbox(self):
if "metadata" not in self.j:
self.j["metadata"] = {}
if self.is_empty() == True:
bbox = [0, 0, 0, 0, 0, 0]
self.j["metadata"]["geographicalExtent"] = bbox
return bbox
return self.calculate_bbox()
if "geographicalExtent" not in self.j["metadata"]:
return self.calculate_bbox()
return self.j["metadata"]["geographicalExtent"]


def calculate_bbox(self):
bbox = [9e9, 9e9, 9e9, -9e9, -9e9, -9e9]
for v in self.j["vertices"]:
for i in range(3):
Expand All @@ -451,6 +449,21 @@ def update_bbox(self):
bbox[i] = (bbox[i] * self.j["transform"]["scale"][i]) + self.j["transform"]["translate"][i]
for i in range(3):
bbox[i+3] = (bbox[i+3] * self.j["transform"]["scale"][i]) + self.j["transform"]["translate"][i]
return bbox


def update_bbox(self):
"""
Update the bbox (["metadata"]["bbox"]) of the CityJSON.
If there is none then it is added.
"""
if "metadata" not in self.j:
self.j["metadata"] = {}
if self.is_empty() == True:
bbox = [0, 0, 0, 0, 0, 0]
self.j["metadata"]["geographicalExtent"] = bbox
return bbox
bbox = self.calculate_bbox()
self.j["metadata"]["geographicalExtent"] = bbox
return bbox

Expand Down Expand Up @@ -854,6 +867,7 @@ def get_info(self):
info = collections.OrderedDict()
info["cityjson_version"] = self.get_version()
info["epsg"] = self.get_epsg()
info["bbox"] = self.get_bbox()
if "extensions" in self.j:
d = set()
for i in self.j["extensions"]:
Expand Down Expand Up @@ -1327,4 +1341,5 @@ def translate(self, values, minimum_xyz):
v[1] = v[1] + bbox[1]
v[2] = v[2] + bbox[2]
self.set_epsg(None)
self.update_bbox()
return bbox

0 comments on commit df59c05

Please sign in to comment.