Skip to content

Commit

Permalink
add a check for attributes that have all nulll values in a tile
Browse files Browse the repository at this point in the history
  • Loading branch information
bertt committed Oct 17, 2024
1 parent bcfb839 commit fe5c614
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/wkb2gltf.core/GlbCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ public static byte[] GetGlb(List<List<Triangle>> 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.
Expand All @@ -101,12 +109,7 @@ public static byte[] GetGlb(List<List<Triangle>> 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);
Expand Down

0 comments on commit fe5c614

Please sign in to comment.