-
Notifications
You must be signed in to change notification settings - Fork 121
encoding/mvt fails on nil features #135
Copy link
Copy link
Closed
Description
When a layer has an empty feature, often due to clipping, it causes MarshalGzipped (and probably Marshal too) to fail with a null pointer panic. The panic is on accessing f.Geometry in the marshaller. On further investigation, this happens when the geometry or feature is nil.
My workflow looks a bit like this:
// get tileData from source
layers, err := mvt.UnmarshalGzipped(tileData)
if err != nil {
return nil, err
}
layers.ProjectToWGS84(tileInfo)
layers.Clip(requestedTile.Bound())
layers.ProjectToTile(requestedTile)
data, err := mvt.MarshalGzipped(layers)mvt.MarshalGzipped(layers) fails with a panic.
If I add a Prune function, something along the lines of:
func (l *Layer) Prune() {
feats := []*geojson.Feature{}
for _, f := range l.Features {
if f != nil && f.Geometry != nil {
feats = append(feats, f)
}
}
l.Features = feats
}then the tiles marshal and render correctly.
Can I suggest or open a PR to provide a Prune function for both mvt.Layer and mvt.Layers?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels