Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #12789] Improve 3dtiles filename handling #281

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions importer/handlers/tiles3d/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def can_handle(_data) -> bool:
if not base:
return False
ext = base.split(".")[-1] if isinstance(base, str) else base.name.split(".")[-1]
input_filename = os.path.basename(base if isinstance(base, str) else base.name)
if ext in ["json"] and "tileset.json" in input_filename:
if ext in ["json"] and Tiles3DFileHandler.is_3dtiles_json(base):
return True
return False

Expand Down Expand Up @@ -90,25 +89,29 @@ def is_valid(files, user):
)

try:
with open(_file, "r") as _readed_file:
_file = json.loads(_readed_file.read())
# required key described in the specification of 3dtiles
# https://docs.ogc.org/cs/22-025r4/22-025r4.html#toc92
is_valid = all(
key in _file.keys() for key in ("asset", "geometricError", "root")
)

if not is_valid:
raise Invalid3DTilesException(
"The provided 3DTiles is not valid, some of the mandatory keys are missing. Mandatory keys are: 'asset', 'geometricError', 'root'"
)
_file = Tiles3DFileHandler.is_3dtiles_json(_file)

Tiles3DFileHandler.validate_3dtile_payload(payload=_file)

except Exception as e:
raise Invalid3DTilesException(e)

return True

@staticmethod
def is_3dtiles_json(_file):
with open(_file, "r") as _readed_file:
_file = json.loads(_readed_file.read())
# required key described in the specification of 3dtiles
# https://docs.ogc.org/cs/22-025r4/22-025r4.html#toc92
is_valid = all(key in _file.keys() for key in ("asset", "geometricError", "root"))

if not is_valid:
raise Invalid3DTilesException(
"The provided 3DTiles is not valid, some of the mandatory keys are missing. Mandatory keys are: 'asset', 'geometricError', 'root'"
)

return _file

@staticmethod
def validate_3dtile_payload(payload):
Expand Down Expand Up @@ -212,7 +215,7 @@ def create_geonode_resource(
asset=None,
):
# we want just the tileset.json as location of the asset
asset.location = [path for path in asset.location if "tileset.json" in path]
asset.location = [path for path in asset.location if path.endswith(".json")]
asset.save()

resource = super().create_geonode_resource(
Expand Down
Loading