diff --git a/processing/processing.go b/processing/processing.go index 43ae76f..e80bc71 100644 --- a/processing/processing.go +++ b/processing/processing.go @@ -295,8 +295,11 @@ func (p *GeometryProcessor) ProcessSingle(geometry geom.Geometry) map[tms20.TMID geomsAndTilesPerTileMatrix := make(map[tms20.TMID]SnapResult, len(p.tmIDs)) for _, tmsID := range p.tmIDs { newGeometries := newGeometriesPerTileMatrix[tmsID] - tiles := p.detectTiles(ix, tmsID, newGeometries) singleGeometry := geomhelp.GeometrySliceToGeom(newGeometries) + if singleGeometry == nil { + continue + } + tiles := p.detectTiles(ix, tmsID, newGeometries) geomsAndTilesPerTileMatrix[tmsID] = SnapResult{singleGeometry, tiles} } return geomsAndTilesPerTileMatrix diff --git a/processing/processing_test.go b/processing/processing_test.go index 431d242..da6679b 100644 --- a/processing/processing_test.go +++ b/processing/processing_test.go @@ -346,12 +346,22 @@ func TestProcessSingle(t *testing.T) { 2: {Geometry: geom.MultiPolygon{polyA, polyB}, Tiles: []tile.Tile{tileA, tileB}}, }, }, + { + name: "nil geometry leaves unset results", + tmIDs: []tms20.TMID{1}, + config: Config{EncodeTiles: true, UseLineTrace: false}, + snapOutput: map[tms20.TMID][]geom.Geometry{ + 1: {}, + }, + detectTilesResult: map[tms20.TMID][]tile.Tile{}, + want: map[tms20.TMID]SnapResult{}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // This counts how often "tileDetect" has been called - numDetect := len(tt.tmIDs) + numDetect := len(tt.want) processor := NewGeometryProcessor(tt.tmIDs, tt.config, createMockSnapFunc(tt.snapOutput), createMockIndexFactory(&numDetect, tt.insertErr, tt.detectTilesResult))