Poly to grid to (simplified) polygon
Configuration examples Poly to grid to (simplified) polygon
This script can be used for two use cases:
-
To simplify a polygon dataset while maintaining the topology. This means linestrings used across multiple polygons are simplified in the same manner, resulting in a polygon set with the same topology as the source dataset (the Bg_simplify_polygon and bg_simplify_multi_polygon functions do not guarantee maintaining the topology).
-
To make a set of (simplified) polygons of adjacent grid cells with the same values.
download
A standalone configuration that demonstrates both use cases on its own data:
poly_2_grid_2_simplified_poly.zip
It carries its own copy of the template, dated before the filled-lakes fix described below. For new work, use the template that ships with the GeoDMS rather than the one in this zip.
examples
In the examples container of this script, you find different options:
- simplify_gridsize: simplifies the source data with the size of the grid. In this container you find options with grid sizes of 500 and 100 meters as spoint, and 10 meters as ipoint.
- simplify_m10: simplifies the source data with as simplify factor 10 meter. In this container you find options with grid sizes of 500 and 100 meters as spoint, and 10 meters as ipoint.
- simplify_m0: simplifies the source data with as simplify factor 0 meter. This means only intermediate points in straight lines are removed, as they do not affect the shape of the feature. In this container you find options with grid sizes of 500 and 100 meters as spoint, and 10 meters as ipoint.
The resulting polygons in the rijksdriehoek coordinates can be requested with the item:
examples/simplify_size_/d_size_i_s_point/SimplifiedPolygons/Results/geometry.
functions
- Poly2grid
- points2polygon
- impedance_table
- Connected_parts
- point_xy
- collect_by_cond
- Union_data
- select
- Combine_data
the template ships with the GeoDMS
Since GeoDMS 20.16.0 this page no longer carries a copy of the template. The one to use is installed with the GeoDMS, as
<install>/library/geometry/Grid2Poly.dms
and is included the way any library script is:
#include <%exeDir%/library/geometry/Grid2Poly.dms>
Pointing at the installed file rather than repeating it here is deliberate. The copy this page used to show was an older variant, template grid2poly_ipoint, and it had drifted: its Results/geometry was a plain geos_union_polygon over all rings, without the islands-minus-lakes split, so a zone with a hole in it came out filled. That was fixed in the installed template (“fixed filled lakes caused by geos ignoring inverted rings unlike boost geometry”, 13-11-2025) and never in the copy shown here. The poly_2_grid_2_simplified_poly_20251104.zip above is dated before that fix as well.
The same older variant used to be installed alongside the current one by the CMake-built setup (.c), as library/geometry/Grid2Poly_ipoint.dms with examples/grid_to_vector.dms calling it. Both are gone as of 20.16.0; the .m and .c setups now install the same library.
calling it
grid2poly takes five case parameters:
| parameter | meaning |
|---|---|
unit<ipoint> domain_grid | the grid domain to vectorise |
unit<uint32> Zone | the zones: one (multi)polygon comes out per zone |
attribute<Zone> zone_rel (domain_grid) | which zone each cell belongs to |
unit<dpoint> coordinate_system | the coordinate system of the result |
parameter<float64> simplifyFactor | simplification tolerance; 0 removes only intermediate points on straight lines |
The result is Results/geometry, a polygon attribute of Zone. Results/overlap_check is the template’s own assertion that the resulting polygons do not overlap.
Note the fourth parameter: the installed template takes the coordinate system as an argument, where the older variant shown here had geography/point_rd and units/meter2 wired into it.
a worked example, and how to run it
<install>/examples/grid_to_polygon.dms
builds a simplified CBS buurt map: it rasterises the CBS Buurt polygons onto the 25 m rijksdriehoek grid from library/basedata_nl/grids.dms, runs grid2poly over that with a 50 m simplification factor, and results in resulting_polygons. The CBS Gebiedsindelingen geopackage is downloaded on first use, so the example needs an internet connection once.
It carries its own checks, so it can be run headless:
GeoDmsRun.exe <install>/examples/grid_to_polygon.dms /checks
which asserts that the buurt map was read, that every buurt got a polygon, that the total area stays close to the source, that the result really has fewer points than the source, and that no two polygons overlap. That command is part of the GeoDMS release tests.