Skip to content

links

Link helpers.

Create inferred links common to collections and items.

Source code in stac_fastapi/types/links.py
29
30
31
32
33
34
35
36
37
38
@attr.s
class BaseLinks:
    """Create inferred links common to collections and items."""

    collection_id: str = attr.ib()
    base_url: str = attr.ib()

    def root(self) -> Dict[str, Any]:
        """Return the catalog root."""
        return dict(rel=Relations.root, type=MimeTypes.json, href=self.base_url)

root

root() -> Dict[str, Any]

Return the catalog root.

Source code in stac_fastapi/types/links.py
36
37
38
def root(self) -> Dict[str, Any]:
    """Return the catalog root."""
    return dict(rel=Relations.root, type=MimeTypes.json, href=self.base_url)

Bases: BaseLinks

Create inferred links specific to collections.

Source code in stac_fastapi/types/links.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@attr.s
class CollectionLinks(BaseLinks):
    """Create inferred links specific to collections."""

    def self(self) -> Dict[str, Any]:
        """Create the `self` link."""
        return dict(
            rel=Relations.self,
            type=MimeTypes.json,
            href=urljoin(self.base_url, f"collections/{self.collection_id}"),
        )

    def parent(self) -> Dict[str, Any]:
        """Create the `parent` link."""
        return dict(rel=Relations.parent, type=MimeTypes.json, href=self.base_url)

    def items(self) -> Dict[str, Any]:
        """Create the `items` link."""
        return dict(
            rel="items",
            type=MimeTypes.geojson,
            href=urljoin(self.base_url, f"collections/{self.collection_id}/items"),
        )

    def create_links(self) -> List[Dict[str, Any]]:
        """Return all inferred links."""
        return [self.self(), self.parent(), self.items(), self.root()]
create_links() -> List[Dict[str, Any]]

Return all inferred links.

Source code in stac_fastapi/types/links.py
65
66
67
def create_links(self) -> List[Dict[str, Any]]:
    """Return all inferred links."""
    return [self.self(), self.parent(), self.items(), self.root()]

items

items() -> Dict[str, Any]

Create the items link.

Source code in stac_fastapi/types/links.py
57
58
59
60
61
62
63
def items(self) -> Dict[str, Any]:
    """Create the `items` link."""
    return dict(
        rel="items",
        type=MimeTypes.geojson,
        href=urljoin(self.base_url, f"collections/{self.collection_id}/items"),
    )

parent

parent() -> Dict[str, Any]

Create the parent link.

Source code in stac_fastapi/types/links.py
53
54
55
def parent(self) -> Dict[str, Any]:
    """Create the `parent` link."""
    return dict(rel=Relations.parent, type=MimeTypes.json, href=self.base_url)

self

self() -> Dict[str, Any]

Create the self link.

Source code in stac_fastapi/types/links.py
45
46
47
48
49
50
51
def self(self) -> Dict[str, Any]:
    """Create the `self` link."""
    return dict(
        rel=Relations.self,
        type=MimeTypes.json,
        href=urljoin(self.base_url, f"collections/{self.collection_id}"),
    )

Bases: BaseLinks

Create inferred links specific to items.

Source code in stac_fastapi/types/links.py
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
@attr.s
class ItemLinks(BaseLinks):
    """Create inferred links specific to items."""

    item_id: str = attr.ib()

    def self(self) -> Dict[str, Any]:
        """Create the `self` link."""
        return dict(
            rel=Relations.self,
            type=MimeTypes.geojson,
            href=urljoin(
                self.base_url,
                f"collections/{self.collection_id}/items/{self.item_id}",
            ),
        )

    def parent(self) -> Dict[str, Any]:
        """Create the `parent` link."""
        return dict(
            rel=Relations.parent,
            type=MimeTypes.json,
            href=urljoin(self.base_url, f"collections/{self.collection_id}"),
        )

    def collection(self) -> Dict[str, Any]:
        """Create the `collection` link."""
        return dict(
            rel=Relations.collection,
            type=MimeTypes.json,
            href=urljoin(self.base_url, f"collections/{self.collection_id}"),
        )

    def create_links(self) -> List[Dict[str, Any]]:
        """Return all inferred links."""
        links = [
            self.self(),
            self.parent(),
            self.collection(),
            self.root(),
        ]
        return links

collection

collection() -> Dict[str, Any]

Create the collection link.

Source code in stac_fastapi/types/links.py
 95
 96
 97
 98
 99
100
101
def collection(self) -> Dict[str, Any]:
    """Create the `collection` link."""
    return dict(
        rel=Relations.collection,
        type=MimeTypes.json,
        href=urljoin(self.base_url, f"collections/{self.collection_id}"),
    )
create_links() -> List[Dict[str, Any]]

Return all inferred links.

Source code in stac_fastapi/types/links.py
103
104
105
106
107
108
109
110
111
def create_links(self) -> List[Dict[str, Any]]:
    """Return all inferred links."""
    links = [
        self.self(),
        self.parent(),
        self.collection(),
        self.root(),
    ]
    return links

parent

parent() -> Dict[str, Any]

Create the parent link.

Source code in stac_fastapi/types/links.py
87
88
89
90
91
92
93
def parent(self) -> Dict[str, Any]:
    """Create the `parent` link."""
    return dict(
        rel=Relations.parent,
        type=MimeTypes.json,
        href=urljoin(self.base_url, f"collections/{self.collection_id}"),
    )

self

self() -> Dict[str, Any]

Create the self link.

Source code in stac_fastapi/types/links.py
76
77
78
79
80
81
82
83
84
85
def self(self) -> Dict[str, Any]:
    """Create the `self` link."""
    return dict(
        rel=Relations.self,
        type=MimeTypes.geojson,
        href=urljoin(
            self.base_url,
            f"collections/{self.collection_id}/items/{self.item_id}",
        ),
    )
filter_links(links: List[Dict]) -> List[Dict]

Remove inferred links.

Source code in stac_fastapi/types/links.py
16
17
18
def filter_links(links: List[Dict]) -> List[Dict]:
    """Remove inferred links."""
    return [link for link in links if link["rel"] not in INFERRED_LINK_RELS]
resolve_links(links: list, base_url: str) -> List[Dict]

Convert relative links to absolute links.

Source code in stac_fastapi/types/links.py
21
22
23
24
25
26
def resolve_links(links: list, base_url: str) -> List[Dict]:
    """Convert relative links to absolute links."""
    filtered_links = filter_links(links)
    for link in filtered_links:
        link.update({"href": urljoin(base_url, link["href"])})
    return filtered_links