Hi,
I was wondering if anyone has successfully created an empty polygon such that this can be input to a polygon annotator.
Here is some code:
import holoviews as hv
hv.extension('bokeh')
For points I can create an empty points holoviews element.
pts_empty = hv.Points(([], []), kdims=['x', 'y'])
pts_empty
It does not fail to display even though it does not contain any data:
Then I add some code to try to create an empty polygon element:
plg_empty = hv.Polygons(data)
plg_empty
Trying to ‘display’ this throws an index error while trying to ensure a ring with no data.
File C:\xx\Miniconda3\envs\test_env\lib\site-packages\holoviews\core\data\multipath.py:568, in ensure_ring(geom, values)
566 starts = [0] + list(breaks+1)
567 ends = list(breaks-1) + [len(geom)-1]
→ 568 zipped = zip(geom[starts], geom[ends], ends, values[starts])
569 unpacked = tuple(zip(*[(v, i+1) for s, e, i, v in zipped
570 if (s!=e).any()]))
571 if not unpacked:IndexError: index 0 is out of bounds for axis 0 with size 0
:Polygons [x,y]
It runs ‘ensure_ring’ on an empty geometry, but I wonder if that check should only happen if there are any data in the element and would wish for it to allow to create an empty polygon element.
That would be neat for a polygon annotator starting with no data, but a structure to put it in when starting to add a polygon with vertices.
Would like to run this:
polygon_annotator = hv.annotate.instance()
polygon_annotator(plg_empty)
But this now throws a similar error as when trying to show the empty polygons and again fail on the check ‘ensure_ring’
Finally I would like to fetch the annotations afterwards with
polygon_annotator = hv.annotate.instance()
plg_annotator.annotated.dframe()
There are workarounds creating some dummy polygon, but I would prefer a ‘clean’ start if possible. Do anyone have some experience to share on this or info on how one might create empty polygons?
Second best would be to create a dummy polygon that can be programmatically deletedafter the annotation session is started (which is possible manually, by selecting the annotation polygon and delete, with backspace key in windows). It can be tested on the example below, but I do not know how to delete from the annotator programmatically.
plg_dummy = hv.Polygons([{'x': [1,2,3], 'y':[3,1,2]}])
polygon_annotator(plg_dummy)
Maybe the topic of creating empty polygon should rather be an issue to github(?)