# Extract coordinates inside a polygon shape drawn with dcc.Graph dragmode

**URL:** <https://community.plotly.com/t/extract-coordinates-inside-a-polygon-shape-drawn-with-dcc-graph-dragmode/75039>\
**Category:** Dash Python\
**Created:** [May 5, 2023, 5:16pm UTC](https://community.plotly.com/t/extract-coordinates-inside-a-polygon-shape-drawn-with-dcc-graph-dragmode/75039 "2023-05-05T17:16:35Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [May 5, 2023, 6:18pm UTC](https://community.plotly.com/t/extract-coordinates-inside-a-polygon-shape-drawn-with-dcc-graph-dragmode/75039/2 "2023-05-05T18:18:26Z")

</div>

Hey @matt.sd.watson welcome to the forums.

I extracted the coordinates like this in the past:

```python
import re

def extract(closedpath: str) -> list[float]:
    path = re.split('[a-zA-Z]', closedpath)
    path = [point for point in path if point]

    # initiate variables
    x = []
    y = []

    for point in path:
        point_x, point_y = map(float, point.split(','))
        x.append(point_x)
        y.append(point_y)
    return x,y

```

usage:

```python
string = "M291.94094488188983,299.9798228346457L314.61811023622056,277.30265748031496L351.468503937008,277.30265748031496L367.53149606299223,283.91683070866145L387.3740157480316,290.5310039370079L404.3818897637796,307.5388779527559Z"

x, y = extract(string)

```

As for the second part of your question, this might be helpful:

> **[Image Annotations | Dash for Python Documentation | Plotly](https://dash.plotly.com/annotations)**
>
> Image Annotations for image processing applications.

Search for the text passage:

```auto
we use the function skimage.draw.polygon to obtain the coordinates of pixels covered by the path
then we use the function scipy.ndimage.binary_fill_holes in order to set to True the pixels enclosed by the path.

```

EDIT: reading the linked example it sounds pretty similar to what you want to do…

---

_[View the full topic](https://community.plotly.com/t/extract-coordinates-inside-a-polygon-shape-drawn-with-dcc-graph-dragmode/75039)._
