|
21 | 21 | import os |
22 | 22 | from pathlib import Path |
23 | 23 | import math |
| 24 | +import zipfile |
| 25 | +from geonode.assets.models import LocalAsset |
24 | 26 | from geonode.layers.models import Dataset |
25 | 27 | from geonode.resource.enumerator import ExecutionRequestAction as exa |
26 | 28 | from geonode.upload.utils import UploadLimitValidator |
@@ -84,7 +86,7 @@ def can_handle(_data) -> bool: |
84 | 86 | if not base: |
85 | 87 | return False |
86 | 88 | ext = base.split(".")[-1] if isinstance(base, str) else base.name.split(".")[-1] |
87 | | - if ext in ["json"] and Tiles3DFileHandler.is_3dtiles_json(base): |
| 89 | + if ext in ["json"] and Tiles3DFileHandler.is_3dtiles_json(base, **_data): |
88 | 90 | return True |
89 | 91 | except Exception: |
90 | 92 | return False |
@@ -123,9 +125,15 @@ def is_valid(files, user, **kwargs): |
123 | 125 | return True |
124 | 126 |
|
125 | 127 | @staticmethod |
126 | | - def is_3dtiles_json(_file): |
127 | | - with open(_file, "r") as _readed_file: |
128 | | - _file = json.loads(_readed_file.read()) |
| 128 | + def is_3dtiles_json(_file, **kwargs): |
| 129 | + if "zip_file" in kwargs: |
| 130 | + # if we have a zipfile we need to read the file content before proceed |
| 131 | + with zipfile.ZipFile(kwargs["zip_file"], "r") as z: |
| 132 | + with z.open(_file.name) as inner_file: |
| 133 | + _file = json.loads(inner_file.read().decode("utf-8")) |
| 134 | + else: |
| 135 | + with open(_file, "r") as _readed_file: |
| 136 | + _file = json.loads(_readed_file.read()) |
129 | 137 | # required key described in the specification of 3dtiles |
130 | 138 | # https://docs.ogc.org/cs/22-025r4/22-025r4.html#toc92 |
131 | 139 | is_valid = all(key in _file.keys() for key in ("asset", "geometricError", "root")) |
@@ -225,25 +233,28 @@ def create_geonode_resource( |
225 | 233 | asset=None, |
226 | 234 | ): |
227 | 235 | # we want just the tileset.json as location of the asset |
228 | | - asset.location = [path for path in asset.location if path.endswith(".json")] |
229 | | - asset.save() |
| 236 | + # asset.location = [path for path in asset.location if path.endswith(".json")] |
| 237 | + # asset.save() |
| 238 | + exec_obj = orchestrator.get_execution_object(execution_id) |
230 | 239 |
|
231 | 240 | resource = super().create_geonode_resource(layer_name, alternate, execution_id, ResourceBase, asset) |
| 241 | + asset = self.create_asset_and_link(resource, files=exec_obj.input_params["files"], action=exec_obj.action) |
232 | 242 |
|
233 | | - # fixing-up bbox for the 3dtile object |
234 | | - js_file = None |
235 | | - with open(asset.location[0]) as _file: |
236 | | - js_file = json.loads(_file.read()) |
| 243 | + if isinstance(asset, LocalAsset): |
| 244 | + # fixing-up bbox for the 3dtile object |
| 245 | + js_file = None |
| 246 | + with open(asset.location[0]) as _file: |
| 247 | + js_file = json.loads(_file.read()) |
237 | 248 |
|
238 | | - if not js_file: |
239 | | - return resource |
| 249 | + if not js_file: |
| 250 | + return resource |
240 | 251 |
|
241 | | - if self._has_region(js_file): |
242 | | - resource = self.set_bbox_from_region(js_file, resource=resource) |
243 | | - elif self._has_sphere(js_file): |
244 | | - resource = self.set_bbox_from_boundingVolume_sphere(js_file, resource=resource) |
245 | | - else: |
246 | | - resource = self.set_bbox_from_boundingVolume(js_file, resource=resource) |
| 252 | + if self._has_region(js_file): |
| 253 | + resource = self.set_bbox_from_region(js_file, resource=resource) |
| 254 | + elif self._has_sphere(js_file): |
| 255 | + resource = self.set_bbox_from_boundingVolume_sphere(js_file, resource=resource) |
| 256 | + else: |
| 257 | + resource = self.set_bbox_from_boundingVolume(js_file, resource=resource) |
247 | 258 |
|
248 | 259 | return resource |
249 | 260 |
|
|
0 commit comments