@@ -537,15 +537,19 @@ def generate_subcatalogs(self, template, defaults=None, parent_ids=None, **kwarg
537
537
538
538
layout_template = LayoutTemplate (template , defaults = defaults )
539
539
540
- items = list (self .get_items ())
541
- for item in items :
540
+ keep_item_links = []
541
+ item_links = [lk for lk in self .links if lk .rel == 'item' ]
542
+ for link in item_links :
543
+ link .resolve_stac_object (root = self .get_root ())
544
+ item = link .target
542
545
item_parts = layout_template .get_template_values (item )
543
546
id_iter = reversed (parent_ids )
544
547
if all (['{}' .format (id ) == next (id_iter , None )
545
548
for id in reversed (item_parts .values ())]):
546
549
# Skip items for which the sub-catalog structure already
547
550
# matches the template. The list of parent IDs can include more
548
551
# elements on the root side, so compare the reversed sequences.
552
+ keep_item_links .append (link )
549
553
continue
550
554
curr_parent = self
551
555
for k , v in item_parts .items ():
@@ -558,9 +562,12 @@ def generate_subcatalogs(self, template, defaults=None, parent_ids=None, **kwarg
558
562
curr_parent .add_child (subcat )
559
563
result .append (subcat )
560
564
curr_parent = subcat
561
- self . remove_item ( item . id )
565
+
562
566
curr_parent .add_item (item )
563
567
568
+ # keep only non-item links and item links that have not been moved elsewhere
569
+ self .links = [lk for lk in self .links if lk .rel != 'item' ] + keep_item_links
570
+
564
571
return result
565
572
566
573
def save (self , catalog_type = None ):
0 commit comments