Create empty holoviews.Polygons element for editing using annotate instance

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

For points I can create an empty points holoviews element.

pts_empty = hv.Points(([], []), kdims=['x', 'y'])

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)

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\, 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()

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()

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]}])

Maybe the topic of creating empty polygon should rather be an issue to github(?)

I notice I forgot to define what ‘data’ is above for empty polygons. Here is the code to try to define an empty polygons element and trigger the error when trying to display it (for use in jupyter notebook cell).

import holoviews as hv

# Then code to try to create an empty polygon element and display that
data = [{'x': [], 'y': []}]
plg_empty = hv.Polygons(data)

Hi @geoviz,

I don’t fully follow what your saying but that’s just because I don’t understand. What I wanted to say though I’ve run your code snippets, I don’t get the error your displaying will print results shortly

1 Like

Thanks @carl,
that you did not get an error lead me into trying the latest version holoviews 1.15.4 which I should obviously have done before filing this. It seems the topic stopped to be an issue in either 1.15.3 or 1.15.4. Thus the solution is to upgrade my working environment it seems :slight_smile:
Thanks you the response, appreciated . I will now go an close an github issue I opened on holoviews repo for this as it seems to be already solved. Starting an annotation instance with an empty polygon element also works nicely in holoviews 1.15.4. This is great I think!

1 Like