# Grid 2 polygon example

Configuration examples Grid 2 polygon

## Introduction

Calculating with grid data is usually much faster as with vector data.

If it is still useful to transform grid data into polygons, see the following example:

```parameter<meter> gridsize := 100[meter];

unit<spoint> griddomain
,   StorageType   = "gdal.grid"
,   DialogData      = "Geografie/rdc"
{
attribute<float32> GridData;
}

unit<uint32> polydomain := subset(IsDefined(griddomain/GridData))
{
attribute<rdc> point_rdc           := Nr_OrgEntity[rdc];
attribute<rdc> geometry (poly) := points2sequence(pointset/point, pointset/sequence, pointset/ordinal);

unit<uint32> pointset := union_unit(.,.,.,.,.)
{
attribute<rdc>     point          := union_data(., point_rdc, point_rdc + point(gridsize, 0[meter], rdc), point_rdc + point(gridsize, -gridsize, rdc), point_rdc + point(0[meter], -gridsize, rdc), point_rdc);
attribute<..>         sequence := union_data(., id(..), id(..), id(..), id(..), id(..))[uint32];
attribute<uint32> ordinal      := union_data(., const(0,..), const(1,..), const(2,..), const(3,..), const(4,..));
}
}
```

## Explanation

This example results in a set of square polygons for each grid cell with non missing data in the GridData attribute. The Subset with the isDefined functions results in a uint32 domain unit with entries for each defined cell. In this subset also other criteria can be used to make selections of the relevant set of grid cells.

The configured pointset domain unit has 5 times the number of entries of the subset domain. This pointset domain is used to define for each polygon the topleft, bottomleft, bottomright, topright and again topleft coordinate. With the points2sequence function these points are converted to polygons.

The square polygons can be dissolved into large polygons (interior polygon segments are removed), by using the union_polygon or partitioned_union_polygon functions.