Skip to content

Problem with relative, unix-like hrefs on Windows #619

@maawoo

Description

@maawoo

Hi everyone!
I'm not sure what exactly I'm doing wrong or if this is a possible bug. So any help or advice is appreciated!
I have a bunch of STAC items with relative, unix-like asset hrefs. From these items I simply want to create a self-contained
catalog. That's about it. I've reduced my code to a simple example using only one collection (of an overall larger, tile-based catalog structure) and one item:

import pystac
import os

data_dir = 'C:\\my\\data\\dir'
tile = 'tile_id'
scene = 'scene_name'

sp_extent = pystac.SpatialExtent([None, None, None, None])
tmp_extent = pystac.TemporalExtent([None, None])

test_collection = pystac.Collection(id=tile, description='test collection', 
                                    extent=pystac.Extent(sp_extent, tmp_extent))

item_path = os.path.join(data_dir, tile, scene, scene + '.json')
item = pystac.read_file(href=item_path)

test_collection.add_item(item=item)
extent = test_collection.extent.from_items(items=[item])
test_collection.extent = extent

Now, when I normalize all hrefs and save my collection, as shown here in the docs, I kind of get what I want. All hrefs, including those of item assets, are relative 👍🏻 but they use windows-style double backslashes 👎🏻. This causes problems with STAC Browser for example.

test_collection.normalize_hrefs(root_href=os.path.join(data_dir, tile)
test_collection.save(catalog_type=pystac.CatalogType.SELF_CONTAINED)

case_A

If I replace the backward slashes from the root_href to normalize against, it results in a collection with relative, unix-style hrefs 👍🏻 but, for whatever reason, also in absolute hrefs for all item assets 👎🏻

test_collection.normalize_hrefs(root_href=os.path.join(data_dir, tile).replace('\\', '/'))
test_collection.save(catalog_type=pystac.CatalogType.SELF_CONTAINED)

image10

I've also played around with the make_all_asset_hrefs_relative method, but it didn't help unfortunately.

Metadata

Metadata

Assignees

Labels

bugThings which are broken

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions