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

Formatting with black and flake8 #270

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions importer/handlers/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from glob import iglob
from importlib import import_module
import logging
import sys
from importer import project_dir
from django.apps import AppConfig
from django.conf import settings
from django.utils.module_loading import import_string
Expand Down
1 change: 0 additions & 1 deletion importer/handlers/gpkg/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import shutil
from django.test import TestCase, override_settings
from importer.handlers.gpkg.exceptions import InvalidGeopackageException
Expand Down
4 changes: 2 additions & 2 deletions importer/handlers/remote/tests/test_3dtiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_import_resource_should_work(self, patch_upload):
ExecutionRequest.objects.filter(exec_id=exec_id).delete()

def test_create_geonode_resource_raise_error_if_url_is_not_reachabel(self):
with self.assertRaises(Invalid3DTilesException) as error:
with self.assertRaises(Invalid3DTilesException):
exec_id = orchestrator.create_execution_request(
user=self.owner,
func_name="funct1",
Expand All @@ -129,7 +129,7 @@ def test_create_geonode_resource_raise_error_if_url_is_not_reachabel(self):
},
)

resource = self.handler.create_geonode_resource(
self.handler.create_geonode_resource(
"layername",
"layeralternate",
execution_id=exec_id,
Expand Down
4 changes: 2 additions & 2 deletions importer/handlers/tiles3d/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def set_bbox_from_boundingVolume(self, js_file, resource):
)

return resource

def set_bbox_from_boundingVolume_sphere(self, js_file, resource):
transform_raw = js_file.get("root", {}).get("transform", [])
sphere_raw = js_file.get("root", {}).get("boundingVolume", {}).get("sphere", None)
Expand All @@ -317,6 +317,6 @@ def set_bbox_from_boundingVolume_sphere(self, js_file, resource):

def _has_region(self, js_file):
return js_file.get("root", {}).get("boundingVolume", {}).get("region", None)

def _has_sphere(self, js_file):
return js_file.get("root", {}).get("boundingVolume", {}).get("sphere", None)
4 changes: 1 addition & 3 deletions importer/handlers/tiles3d/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ def test_set_bbox_from_bounding_volume_sphere_without_transform(self):
self.assertEqual(resource.bbox_y1, 86.8110610157489)

os.remove("/tmp/tileset.json")



def test_set_bbox_from_bounding_volume_sphere_with_center_zero_without_transform(self):
# https://github.com/geosolutions-it/MapStore2/blob/master/web/client/api/__tests__/ThreeDTiles-test.js#L53C4-L79C8
# This test should not extract bbox from boundingVolume sphere with center 0, 0, 0
Expand Down Expand Up @@ -476,7 +475,6 @@ def test_set_bbox_from_bounding_volume_sphere_with_center_zero_without_transform
self.assertTrue(resource.bbox == self.default_bbox)

os.remove("/tmp/tileset.json")


def _generate_execid_asset(self):
exec_id = orchestrator.create_execution_request(
Expand Down
23 changes: 13 additions & 10 deletions importer/handlers/tiles3d/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def fromCartesian(cartesian):

return {"longitude": longitude, "latitude": latitude, "height": height}


def getScale(matrix):
'''
Cesium.Matrix4.getScale()
Expand All @@ -135,17 +136,18 @@ def getScale(matrix):
'''

# check the type of the matrix
if isinstance(matrix, np.ndarray)!=True:
if not isinstance(matrix, np.ndarray):
print('Please define a NumPy array object')

x = np.linalg.norm([matrix[0][0], matrix[0][1], matrix[0][2]])
y = np.linalg.norm([matrix[1][0], matrix[1][1], matrix[1][2]])
z = np.linalg.norm([matrix[2][0], matrix[2][1], matrix[2][2]])

result = np.array([x, y, z])

return result


def box_to_wgs84(box_raw, transform_raw):
box = box_raw
transform_raw = transform_raw or [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
Expand Down Expand Up @@ -190,33 +192,34 @@ def box_to_wgs84(box_raw, transform_raw):
"maxy": lat + radiusDegrees,
}


def sphere_to_wgs84(sphere_raw, transform_raw):

transform_raw = transform_raw or [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]

transform = np.array([
transform_raw[0:4],
transform_raw[4:8],
transform_raw[8:12],
transform_raw[12:16],
])

centerPoint = np.array([sphere_raw[0], sphere_raw[1], sphere_raw[2], 1])

radius = sphere_raw[3]

# Sphere center after the transformation
center = centerPoint.dot(transform) # Cesium.Matrix4.multiplyByPoint
center = centerPoint.dot(transform) # Cesium.Matrix4.multiplyByPoint

scale = getScale(transform)
uniformScale = np.max(scale)
radiusDegrees = (radius * uniformScale) / 111194.87428468118 # degrees of one meter
radiusDegrees = (radius * uniformScale) / 111194.87428468118 # degrees of one meter

cartographic = fromCartesian(center)

if not cartographic:
return None

lng = math.degrees(cartographic['longitude'])
lat = math.degrees(cartographic['latitude'])

Expand Down
2 changes: 1 addition & 1 deletion importer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
'importer.handlers.sld.handler.SLDFileHandler',
'importer.handlers.tiles3d.handler.Tiles3DFileHandler',
'importer.handlers.remote.tiles3d.RemoteTiles3DResourceHandler',
]
]
3 changes: 0 additions & 3 deletions importer/tests/end2end/test_end2end.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import ast
import os
import time
from uuid import uuid4

import mock
from django.conf import settings
from django.contrib.auth import get_user_model
Expand All @@ -19,7 +17,6 @@
from geonode.base.populate_test_data import create_single_dataset
from django.db.models import Q
from geonode.base.models import ResourceBase
from geonode.resource.manager import resource_manager

geourl = settings.GEODATABASE_URL

Expand Down
5 changes: 1 addition & 4 deletions importer/tests/unit/test_dastore.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os
from django.test import TestCase
from mock import patch
from importer import project_dir
from importer.orchestrator import orchestrator
from importer.datastore import DataStoreManager
from importer.publisher import DataPublisher
from unittest.mock import MagicMock
from django.contrib.auth import get_user_model


class TestDataStoreManager(TestCase):
"""
"""
Expand Down
Loading