From fe5c61468ab22ae7ae6160bcdf248c5f37c7283a Mon Sep 17 00:00:00 2001 From: Bert Temme Date: Thu, 17 Oct 2024 15:22:04 +0200 Subject: [PATCH] add a check for attributes that have all nulll values in a tile --- src/wkb2gltf.core/GlbCreator.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wkb2gltf.core/GlbCreator.cs b/src/wkb2gltf.core/GlbCreator.cs index 39363f5..1389893 100644 --- a/src/wkb2gltf.core/GlbCreator.cs +++ b/src/wkb2gltf.core/GlbCreator.cs @@ -87,6 +87,14 @@ public static byte[] GetGlb(List> triangles, string copyright = " primitive.AddMeshFeatureIds(featureIdAttribute); } + // remove the attributes that have only null values + foreach (var attribute in attributes) { + var firstType = attribute.Value.Where(x => x != DBNull.Value).FirstOrDefault(); + if (firstType == null) { + attributes.Remove(attribute.Key); + } + } + foreach (var attribute in attributes) { // the 3d tiles metadata spec does not allow for null values (but only 'nodata' values), so we need to determine the // nodata value for each type. @@ -101,12 +109,7 @@ public static byte[] GetGlb(List> triangles, string copyright = " var longNodata = long.MinValue; var ulongNodata = ulong.MaxValue; // let's take the ulong max value as nodata var doubleNodata = double.MinValue; - - // in the attribute dictionary, find the type o the first value that is not dbnull var firstType = attribute.Value.Where(x => x != DBNull.Value).FirstOrDefault(); - if(firstType == null) { - throw(new Exception($"All values of attribute '{attribute.Key}' are Null, can't determine type")); - } var type = firstType.GetType(); var objects = attribute.Value; var property = schemaClass.UseProperty(attribute.Key);