diff --git a/inmaputil/inmap.go b/inmaputil/inmap.go index a25ced9c6..0d72fc8c1 100644 --- a/inmaputil/inmap.go +++ b/inmaputil/inmap.go @@ -340,6 +340,26 @@ func setEmissionsAEP(inventoryConfig *aeputil.InventoryConfig, spatialConfig *ae recs, _, err = inventoryConfig.ReadEmissions() // Remember to check error below. } + if mask != nil { // Remove records that do not overlap with mask. + mb := mask.Bounds() + for s, srecs := range recs { + i := 0 // output index + for _, r := range srecs { + if r.Location().Bounds().Overlaps(mb) { + // copy and increment index + srecs[i] = r + i++ + } + } + // Prevent memory leak by erasing truncated values + for j := i; j < len(srecs); j++ { + srecs[j] = nil + } + srecs = srecs[:i] + recs[s] = srecs + } + } + return func(d *inmap.InMAP) error { if err != nil { // Check error from ReadEmissions return err