# PolygonsÂ¶

InÂ [1]:

```
import os
import matplotlib.pyplot as plt
import gstlearn as gl
import gstlearn.plot as gp
import gstlearn.document as gdoc
import numpy as np
import scipy as sp
from scipy import interpolate
gdoc.setNoScroll()
```

We read the contents of the Polygon definition from a CSV file.

InÂ [2]:

```
filename = gdoc.loadData("Alluvial", "Seine_Alluvial.csv")
csv = gl.CSVformat(False, 0, ";", ",", "9999")
poly = gl.Polygons.createFromCSV(filename, csv, False)
```

InÂ [3]:

```
ax = poly.plot()
ax.decoration(title="Polygon")
```

The current polygon contains a large number of vertices.

InÂ [4]:

```
poly.display(gl.AStringFormat(2))
```

Polygons -------- Number of Polygon Sets = 1 PolyElem #1 ........... Number of Vertices = 30301

We define a rotated grid which contains the whole alluvial plain.

InÂ [5]:

```
grid = gl.DbGrid()
err = grid.reset([4000,3500],[100,100],[480000,6650000])
```

InÂ [6]:

```
ax = grid.plot(alpha=0.3)
ax = poly.plot()
ax.decoration(title="Polygon in its alluvial plain")
```

Reduce the complexity of the Polygon

InÂ [7]:

```
newpoly = poly.reduceComplexity(3000)
newpoly.display(gl.AStringFormat(2))
```

Polygons -------- Number of Polygon Sets = 1 PolyElem #1 ........... Number of Vertices = 1123

InÂ [8]:

```
ax = grid.plot(alpha=0.3)
ax = newpoly.plot()
ax = poly.plot(edgecolor='red')
ax.decoration(title="(Simplified) Polygon in its alluvial plain")
```

InÂ [9]:

```
err = gl.db_polygon(grid,newpoly,
namconv = gl.NamingConvention("Coarse",True, True, True, gl.ELoc.SEL))
print(f"Number of active grid nodes = {grid.getSampleNumber(True)}")
```

Number of active grid nodes = 315868

InÂ [10]:

```
grid.setLocator("Coarse",gl.ELoc.Z)
err = grid.morpho(gl.EMorpho.DILATION, option=1, radius = [30,30])
grid.setLocator("Morpho*",gl.ELoc.SEL)
print(f"Number of active grid nodes = {grid.getSampleNumber(True)}")
```

Number of active grid nodes = 1593571

InÂ [11]:

```
ax = grid.plot(alpha=0.3)
ax = newpoly.plot()
ax = poly.plot(edgecolor='red')
ax.decoration(title="(Simplified) Polygon in its dilated selection")
```