Skip to content

Commit

Permalink
Implement get_texture_location()
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsdukai committed Jun 4, 2018
1 parent 1577e7e commit 969d9d2
Show file tree
Hide file tree
Showing 12 changed files with 1,350 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Pipfile
Expand Up @@ -4,6 +4,7 @@ verify_ssl = true
url = "https://pypi.org/simple"

[dev-packages]
pytest = "*"

[requires]
python_version = "3.6"
Expand All @@ -12,4 +13,4 @@ python_version = "3.6"
click = "*"
jsonschema = "*"
jsonref = "*"
"e1839a8" = {path = ".", editable = true}
"e1839a8" = {editable = true, path = "."}
57 changes: 55 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions cjio/cityjson.py
@@ -1,6 +1,8 @@

import os
import sys
import re

import json
import collections
import jsonref
Expand Down Expand Up @@ -57,6 +59,7 @@ class CityJSON:
def __init__(self, file=None, j=None, ignore_duplicate_keys=False):
if file is not None:
self.read(file, ignore_duplicate_keys)
self.path = file.name
elif j is not None:
self.j = j
else: #-- create an empty one
Expand Down Expand Up @@ -421,6 +424,42 @@ def get_subset_cotype(self, cotype):
return cm2



def get_texture_location(self):
"""Get the location of the texture files
Assumes that all textures are in the same location. Relative paths
are expanded to absolute paths.
"""
if "appearance" in self.j:
if "textures" in self.j["appearance"]:
p = self.j["appearance"]["textures"][0]["image"]
cj_dir = os.path.dirname(self.path)
url = re.match('http[s]?://|www\.', p)
if url:
return url
else:
d = os.path.dirname(p)
print(d)
if len(d) == 0:
# textures are in the same dir as the cityjson file
return cj_dir
elif not os.path.isabs(d):
if os.path.isdir(os.path.abspath(d)):
# texture dir is not necessarily in the same dir
# as the input file
return os.path.abspath(d)
elif os.path.isdir(os.path.join(cj_dir, d)):
# texture dir is a subdirectory at the input file
return os.path.join(cj_dir, d)
else:
raise FileNotFoundError("Texture directory '%s' not found" % d)


def validate_textures(self):
"""Check if the texture files exist"""


def remove_textures(self):
for i in self.j["CityObjects"]:
if "texture" in self.j["CityObjects"][i]:
Expand Down

0 comments on commit 969d9d2

Please sign in to comment.