Skip to content

Commit

Permalink
Support 3D tiles datasets without transform property (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandenburgh authored Jun 3, 2022
1 parent 398dd49 commit 6d111cb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
23 changes: 15 additions & 8 deletions django-rgd-3d/rgd_3d/tasks/etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ def bounds_to_polygon(xmin, xmax, ymin, ymax):
]
)

transform = np.array(tileset_json['root']['transform']).reshape((4, 4), order='C')
# 'transform' is an optional property
# ref: https://github.com/CesiumGS/3d-tiles/tree/main/specification#transforms
transform = (
np.array(tileset_json['root']['transform']).reshape((4, 4), order='C')
if 'transform' in tileset_json['root']
else None
)

# The coordinates should be in EPSG:4978 by convention in 3D Tiles
# See https://github.com/CesiumGS/3d-tiles/tree/main/specification#coordinate-reference-system-crs
Expand All @@ -129,13 +135,14 @@ def bounds_to_polygon(xmin, xmax, ymin, ymax):
ymax = max(center[1], x[1], y[1])
coords = bounds_to_polygon(xmin, xmax, ymin, ymax)
coords = np.c_[coords, np.zeros(len(coords)), np.ones(len(coords))]
# Apply the transform
corners = (coords @ transform)[:, :-1] # in XYZ world
src = pyproj.CRS('EPSG:4978') # 4979 -> srid
dest = pyproj.CRS('EPSG:4326')
transformer = pyproj.Transformer.from_proj(src, dest, always_xy=True)
x, y, _ = transformer.transform(corners.T[0], corners.T[1], corners.T[2])
coords = np.c_[x, y]
# Apply the transform if one is given
if transform is not None:
corners = (coords @ transform)[:, :-1] # in XYZ world
src = pyproj.CRS('EPSG:4978') # 4979 -> srid
dest = pyproj.CRS('EPSG:4326')
transformer = pyproj.Transformer.from_proj(src, dest, always_xy=True)
x, y, _ = transformer.transform(corners.T[0], corners.T[1], corners.T[2])
coords = np.c_[x, y]
elif 'sphere' in volume:
raise NotImplementedError
else:
Expand Down
4 changes: 3 additions & 1 deletion django-rgd-3d/tests/test_3d_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
centroids = {
'jacksonville-untextured.zip': {'x': -81.6634, 'y': 30.3234},
'jacksonville-textured.zip': {'x': -81.6634, 'y': 30.3234},
'jacksonville-point-cloud-3d-tiles.zip': {'x': -81.6634, 'y': 30.3234},
'dragon.zip': {'x': -75.6079, 'y': 40.0439},
}

Expand All @@ -17,11 +18,12 @@
[
'jacksonville-untextured.zip',
'jacksonville-textured.zip',
'jacksonville-point-cloud-3d-tiles.zip',
'dragon.zip',
],
)
@pytest.mark.django_db(transaction=True)
def test_mesh_3d_etl(sample_file):
def test_tiles_3d_etl(sample_file):
paths = datastore.fetch(sample_file, processor=Unzip())

entry = create_tiles3d_from_paths(paths)
Expand Down
1 change: 1 addition & 0 deletions django-rgd/rgd/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'envi_rgbsmall_bip.img': 'sha512:eff9dcc3f5fdae898132ccb908ee0c13725f2b8178871b2c158ffe6f3306ba1408da59fde9228df6ed7ef9b1b720805a3fb5df4545eb80c640d221a7ee697a31',
'jacksonville-untextured.zip': 'sha512:00bb4aeeff6a5f9fd3f0777c0207d6daf6f71bbdf800a5d02d0c5964093b3443bb5b45d571abc2a216b15d343db19bcfa9cb026433c041970e3434385a28c168',
'jacksonville-textured.zip': 'sha512:0ddac53f5bac4fd67d6cf58b86dd1646ffe65a89b5c3f17442e1c4ef0f08f5f34d914e6999a64a4371361233c339f9746f46637073a5e76ffd535e621a615bf9',
'jacksonville-point-cloud-3d-tiles.zip': 'sha512:1994dddfdad026fafb3cdb91391b1404289aad1d99422babbae79874ba276bc58f4eae28fcb2d7bc2af36ff1d7ba7fc42f98b1ec4382be1041f2e1d96dafdbf1',
'dragon.zip': 'sha512:e8b88f5de6cb2d7a3d3cc649190b0230394094e91fabec54acb6dd97869d6fe311fca5806e082c76f085ee00e62630bd02b393668ac3c4e44d007e7374ae635c',
'IHTest_202009_Path3_Step5_BBXSWIR_12deg_DistStA.hdr': 'sha512:d8e11e23d81f397a895d8e302258805082fec9358d44baa63c971c56aecfc725fa0458ff86f2aa64c23c3461dd60d287c28af687393af853d2c1d2b4513163fa',
'IHTest_202009_Path3_Step5_BBXSWIR_12deg_DistStA.raw': 'sha512:8cb5a57c37c87e8a45d51a6d5e5b072a488b79ade82dcfc227473dd60a66cd5fb980a84b59e7541ed5cbfac52605d84ed0b8f055b8da7223d420d69faafe6abd',
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""
# major, minor, patch
version_info = 0, 3, 8
version_info = 0, 3, 9

# Nice string for the version
__version__ = '.'.join(map(str, version_info))

0 comments on commit 6d111cb

Please sign in to comment.