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, an older one in which a zone with a hole in it comes out filled. 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
The template 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>
This page deliberately points at the installed file instead of repeating it: a copy here would not get the corrections that the installed template gets. The Results/geometry of the installed template makes the islands-minus-lakes split, so a zone with a hole in it keeps its hole. The .m and .c setups 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 template takes the coordinate system of the result as an argument.
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, with curl, into the folder RegionalUnits/cbs of the SourceDataDir, so the example needs an internet connection once. Current versions of Windows 10 and 11 and the common Linux distributions include curl. When the download breaks off, curl removes the partial file, so the next run downloads the geopackage again. A partial file that stays behind anyway, because the run was stopped during the download or because curl is older than version 7.83.0, makes every later run fail to open the geopackage; delete it and run the example again.
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.