@@ -557,15 +557,19 @@ def generate_subcatalogs(self, template, defaults=None, parent_ids=None, **kwarg
557
557
558
558
layout_template = LayoutTemplate (template , defaults = defaults )
559
559
560
- items = list (self .get_items ())
561
- for item in items :
560
+ keep_item_links = []
561
+ item_links = [lk for lk in self .links if lk .rel == 'item' ]
562
+ for link in item_links :
563
+ link .resolve_stac_object (root = self .get_root ())
564
+ item = link .target
562
565
item_parts = layout_template .get_template_values (item )
563
566
id_iter = reversed (parent_ids )
564
567
if all (['{}' .format (id ) == next (id_iter , None )
565
568
for id in reversed (item_parts .values ())]):
566
569
# Skip items for which the sub-catalog structure already
567
570
# matches the template. The list of parent IDs can include more
568
571
# elements on the root side, so compare the reversed sequences.
572
+ keep_item_links .append (link )
569
573
continue
570
574
curr_parent = self
571
575
for k , v in item_parts .items ():
@@ -578,13 +582,17 @@ def generate_subcatalogs(self, template, defaults=None, parent_ids=None, **kwarg
578
582
curr_parent .add_child (subcat )
579
583
result .append (subcat )
580
584
curr_parent = subcat
581
- self . remove_item ( item . id )
585
+
582
586
# resolve collection link so when added back points to correct location
583
587
link = item .get_single_link ('collection' )
584
588
if link is not None :
585
589
link .resolve_stac_object ()
590
+
586
591
curr_parent .add_item (item )
587
592
593
+ # keep only non-item links and item links that have not been moved elsewhere
594
+ self .links = [lk for lk in self .links if lk .rel != 'item' ] + keep_item_links
595
+
588
596
return result
589
597
590
598
def save (self , catalog_type = None ):
0 commit comments