Skip to content
Snippets Groups Projects

Add element polygon shortcut as a property

Merged Yoann Schneider requested to merge element-polygon-shortcut into master
All threads resolved!
2 files
+ 29
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 14
1
@@ -5,7 +5,7 @@ Wrappers around API results to provide more convenient attribute access and IIIF
import tempfile
from contextlib import contextmanager
from typing import Generator, Optional
from typing import Generator, List, Optional
from PIL import Image
from requests import HTTPError
@@ -93,6 +93,19 @@ class Element(MagicDict):
url += "/"
return "{}full/{}/0/default.jpg".format(url, size)
@property
def polygon(self) -> List[float]:
"""
Access an Element's polygon.
This is a shortcut to an Element's polygon, normally accessed via
its zone field via `zone.polygon`. This is mostly done
to facilitate access to this important field by matching
the [CachedElement][arkindex_worker.cache.CachedElement].polygon field.
"""
if not self.get("zone"):
raise ValueError("Element {} has no zone".format(self.id))
return self.zone.polygon
@property
def requires_tiles(self) -> bool:
"""
Loading