# find coordinates of holes inside a polygon

**URL:** https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243
**Category:** ParaView Support
**Tags:** python
**Created:** [February 6, 2019, 3:53pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243 "2019-02-06T15:53:35Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![fabio.romani](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fabio.romani](https://discourse.paraview.org/u/fabio.romani)
#### Post date: [February 6, 2019, 3:53pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/1 "2019-02-06T15:53:36Z")

</div>

Hi,

I have a polygon shape filled up with holes. I need to locate and collect the holes for further processing. Is there an easy way using python shell/script/filters to find those holes?

Thanks

Fabio

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [February 6, 2019, 3:56pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/2 "2019-02-06T15:56:30Z")

</div>

You can use the **Feature Edge** filter and check only the _Boundary Edges_ option to find the borders of holes.

---

<div class="post-metadata">

### Author: ![fabio.romani](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fabio.romani](https://discourse.paraview.org/u/fabio.romani)
#### Post date: [February 6, 2019, 4:10pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/3 "2019-02-06T16:10:49Z")

</div>

Thanks Cory, I’ll look into that right away.

Haven’t bought the manual yet…are those feature well documented in it? If so I’ll order it right away

Thanks!

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [February 6, 2019, 4:17pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/4 "2019-02-06T16:17:10Z")

</div>

The community edition of the [ParaView Guide](https://www.paraview.org/paraview-guide/) is available at no cost. The **Feature Edges** filter is mentioned in passing. If you want to browse descriptions of various filters, look at the “Reader, Filter, and Writer” item in the Help menu.

---

<div class="post-metadata">

### Author: ![fabio.romani](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fabio.romani](https://discourse.paraview.org/u/fabio.romani)
#### Post date: [February 6, 2019, 4:33pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/5 "2019-02-06T16:33:43Z")

</div>

Hi Cory,

That’s perfect! Thanks a lot, I think I’m getting the hang of it!

Thanks for your help

Fabio

---

<div class="post-metadata">

### Author: ![wascott](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/8e8cbc/32.png) [@wascott](https://discourse.paraview.org/u/wascott)
#### Post date: [February 6, 2019, 6:16pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/6 "2019-02-06T18:16:14Z")

</div>

Fabio,  
You can also get to the ParaView Guide through the Help menu. For those of us who forget where all of Paraview’s documentation is, this is my “go to” shortcut.  
Alan

---

<div class="post-metadata">

### Author: ![fabio.romani](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fabio.romani](https://discourse.paraview.org/u/fabio.romani)
#### Post date: [February 6, 2019, 10:25pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/7 "2019-02-06T22:25:17Z")

</div>

Hi Cory,

I guess I have one more question…here below is my little script. Basically what I need to do is locate the holes in a polygon, calculate the distance between them and based on that, modify the array data of the points between them.

Now, the filter portion (thanks to you) works as expected (I can modify the data array and visualize it at will)

I can also see that the FetureEdges “works”…meaning of: once the script runs, I can see the edges of the holes getting highlighted in ParaView. What I still can’t find is a way to loop through either the holes shapes (if possible) or the  
holes points. How can I access those information? I apologize for the dumb question

# Importing the vtk file

reader = OpenDataFile("/home/fabior/Current\_density-tm-mag-xyz\_slice.vtk")

Show(reader)

SetDisplayProperties(Representation = “Surface”)

SetDisplayProperties(ColorArrayName = “scalars”)

SetDisplayProperties(LookupTable = MakeBlueToRedLT(-100, 1e10))

Render()

# finding holes inside the polygon

featureEdges = FeatureEdges(reader)

# selecting only the holes boundaries

featureEdges.BoundaryEdges = 1

featureEdges.FeatureEdges = 0

featureEdges.NonManifoldEdges = 0

featureEdges.UpdatePipeline()

# finding distances between holes corners

# adding programmable filter to remove false CD channels

programmableFilter = ProgrammableFilter(reader)

progrFilterFile = open("/home/fabior/myPrograms/paraview/programmable\_filter.py")

programmableFilter.Script = progrFilterFile.read()

programmableFilter.UpdatePipeline()

w = CreateWriter("./modified\_data.vtk")

w.UpdatePipeline()

---

<div class="post-metadata">

### Author: ![fabio.romani](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fabio.romani](https://discourse.paraview.org/u/fabio.romani)
#### Post date: [February 6, 2019, 11:02pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/8 "2019-02-06T23:02:27Z")

</div>

…I guess I first have to pass my featureEdges variable to a new ProgrammableFilter, don’t I?  
😊

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [February 7, 2019, 2:29am UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/9 "2019-02-07T02:29:08Z")

</div>

> [@fabio.romani](#):
>
> ProgrammableFilter

`ProgrammableFilter(Input=featureEdges)` should do the trick. Then, whatever you have in `programmable_filter.py` will be run with the input set to the output of the **Feature Edges** filter.

To get the points in the `programmable_filter.py`, add to your script file

```python
inputs[0].PointData

```

which gives you a NumPy like array with the point locations.

You’ll probably want to isolate the boundaries around different holes, which you can do by running the **Connectivity** filter after the **Feature Edges** filter. This assigns a unique RegionID to each point, which you can use to differentiate among the hols.

BTW, when posting code here, you can add mark the start and end of a code section with ```. That will improve the code formatting. You can also specify the language (e.g., python) after the opening backticks to explicitly define what language highlighting should be used.

---

<div class="post-metadata">

### Author: ![fabio.romani](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fabio.romani](https://discourse.paraview.org/u/fabio.romani)
#### Post date: [February 13, 2019, 9:25pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/10 "2019-02-13T21:25:31Z")

</div>

Hi Cory,

After your inputs…I’m trying to come up with something more sophisticated. What I’d like to get is pass a area selection to the FeatureEdges filter, so that it can work on less data which are the only ones I want to focus on anyway.

I’m trying to use Clip to select the area of interest and then pass that to my “selection” variable (see below in bold red) and pass that one to the featureEdges variable before handing it over to my programmable filter.

The code errors out though…looks like ExtractSelection doesn’t like the clip…

I’m using paraview 3.14…so…it’s a bit old…

Am I doing anything wrong? (hope I’ve format the code properly with the `)

Thanks

Fabio

```python

from paraview.simple import *

import paraview.vtk as vtk

# Importing the vtk file

reader = OpenDataFile("/home/fabior/tm-mag-xyz_slice.vtk")

Show(reader)

SetDisplayProperties(Representation = "Surface")

SetDisplayProperties(ColorArrayName = "scalars")

SetDisplayProperties(LookupTable = MakeBlueToRedLT(-100, 1e10))

Render()

# collecting shape's bounds

(xmin, xmax, ymin, ymax, zmin, zmax) = reader.GetDataInformation().GetBounds()

# selecting points inside the comb

clipArea = Clip(reader)

clipArea.ClipType = 'Box'

clipArea.ClipType.Bounds = [xmin, xmax, ymin + 150.0, ymax - 150.0, zmin, zmax]

clipArea.UpdatePipeline()

# finding holes inside the polygon

***selection = ExtractSelection(Input=reader, Selection=clipArea)***

***selection.UpdatePipeline()***

featureEdges = FeatureEdges(selection)

# selecting only the holes boundaries

featureEdges.BoundaryEdges = 1

featureEdges.FeatureEdges = 0

featureEdges.NonManifoldEdges = 0

featureEdges.UpdatePipeline()

connectivityFilter = Connectivity(featureEdges)

connectivityFilter.UpdatePipeline()

# adding programmable filter to remove false CD channels

programmableFilter = ProgrammableFilter()

programmableFilter.Input = [reader, connectivityFilter]

progrFilterFile = open("/home/fabior/myPrograms/paraview/programmable_filter_holes.py")

programmableFilter.Script = progrFilterFile.read()

programmableFilter.UpdatePipeline()

w = CreateWriter("./modified_data.vtk")

w.UpdatePipeline()

```

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [February 18, 2019, 4:47pm UTC](https://discourse.paraview.org/t/find-coordinates-of-holes-inside-a-polygon/1243/11 "2019-02-18T16:47:34Z")

</div>

`Clip` should do the extraction you are looking for. `ExtractSelection` operations on a ParaView “selection”, which is a point or cell selection you make in the ParaView interface.
