From b611c3d8f63085fc913ce052e4248c486eb65b39 Mon Sep 17 00:00:00 2001 From: Mattia Date: Thu, 6 Jun 2024 13:07:59 +0200 Subject: [PATCH] use region for cacluate bbox in 3dtiles --- importer/handlers/tiles3d/handler.py | 30 ++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/importer/handlers/tiles3d/handler.py b/importer/handlers/tiles3d/handler.py index 6f620b8..4e9dcf1 100644 --- a/importer/handlers/tiles3d/handler.py +++ b/importer/handlers/tiles3d/handler.py @@ -2,17 +2,14 @@ import logging import os from pathlib import Path -from geonode.assets.utils import get_default_asset +import math from geonode.layers.models import Dataset from geonode.resource.enumerator import ExecutionRequestAction as exa from geonode.upload.utils import UploadLimitValidator -from importer.handlers.base import BaseHandler -from importer.models import ResourceHandlerInfo from importer.orchestrator import orchestrator from importer.celery_tasks import import_orchestrator from importer.handlers.common.vector import BaseVectorFileHandler from importer.handlers.utils import create_alternate, should_be_imported -from importer.publisher import DataPublisher from importer.utils import ImporterRequestAction as ira from geonode.base.models import ResourceBase from importer.handlers.tiles3d.exceptions import Invalid3DTilesException @@ -216,6 +213,31 @@ def create_geonode_resource( layer_name, alternate, execution_id, ResourceBase, asset ) + # fixing-up bbox for the 3dtile object + js_file = None + with open(asset.location[0]) as _file: + js_file = json.loads(_file.read()) + + if not js_file: + return resource + + # checking if the region is inside the json file + region = js_file.get("root", {}).get("boundingVolume", {}).get("region", None) + if not region: + logger.info(f"No region found, the BBOX will not be updated for 3dtiles: {resource.title}") + return resource + west, south, east, nord = region[:4] + # [xmin, ymin, xmax, ymax] + resource.set_bbox_polygon( + bbox=[ + math.degrees(west), + math.degrees(south), + math.degrees(east), + math.degrees(nord) + ], + srid='EPSG:4326' + ) + return resource def generate_resource_payload(self, layer_name, alternate, asset, _exec, workspace):