dms polygon operators - ObjectVision/GeoDMS GitHub Wiki
Back to Geometric functions and polygon operators
The dms_ operators are the polygon operations that GeoDMS implements itself, next to the operators of the geometry libraries GEOS, boost geometry, boost polygon and cgal. They work on polygons that are not valid: rings may cross themselves, touch themselves, overlap or touch each other, or fail to close. Every element is read under the even-odd rule, and an optional grid size merges vertices and slivers that are too close together to be meant apart. They take all six polygon value types: spoint, ipoint, wpoint, upoint, fpoint and dpoint.
the operators
Element by element, on two polygon attributes of the same value type and values unit, over the same domain unit or with one of them a parameter, each with an optional third argument, the grid size:
- dms_intersect, the intersection
- dms_union, the union
- dms_difference, the first minus the second
- dms_xor, the symmetric difference
Cleaning, dissolving and splitting:
- dms_polygon reads each element under the even-odd rule and writes it back as a valid polygon
- dms_union_polygon dissolves all polygons into one, or per group with a partition attribute
- dms_split_polygon splits each multi polygon into its single polygons, each a row of a new domain unit
- dms_split_union_polygon dissolves, then splits
- dms_split_convex_polygon splits each polygon, holes included, into strictly convex parts without holes
- dms_split_convex_polygon_keilsnoeyink does the same with the minimum number of parts for polygons without holes, and is slower
Pairs of polygons:
- dms_overlay_polygon gives all pairs of polygons with a common interior point, between two attributes or within one, with the intersection geometry of each pair
- dms_polygon_connectivity gives the same pairs as relations only; with a group per polygon, it gives one pair per pair of groups
- dms_convex_polygon_connectivity does the same for convex polygons, and decides each pair with an exact test instead of the sweep
Growing and shrinking:
- dms_buffer_multi_polygon grows or shrinks each geometry by a distance, with rounded corners; it takes the arguments of geos_buffer_multi_polygon and puts the points where GEOS puts them
- dms_minkowski_sum grows each geometry by a convex kernel: a kernel polygon, or one of the four convex named shapes at a given size; see minkowski_sum
- dms_minkowski_difference shrinks each geometry by a convex kernel; see minkowski_difference
The two Minkowski operators of this family refuse a kernel that is not convex, which includes the star-shaped named shapes 'XHV' and 'XD'. dms_polygon, dms_split_polygon, the two convex splits, the buffer and the two Minkowski operators work per element and compute the elements of a tile in parallel.
the even-odd rule
The polygon value of one element is a sequence of points, with the rings of a multi polygon strung together by zero-width corridors. The dms_ operators read that sequence as one closed walk: consecutive points are line segments, and the last point is connected back to the first. A point of the plane lies inside when a ray from that point to infinity crosses the walk an odd number of times. That has three consequences that a modeller can use:
- The orientation of the rings does not matter on input. A shell given counter-clockwise, a hole given clockwise, or a feature of which only some rings are reversed, are all read the same way. The other families need has_correct_winding and fix_winding_order for that.
- A ring that crosses itself has a defined meaning. A ring in the shape of a bow tie is two triangles, since the middle is crossed twice. The usual definition of a valid polygon, which the geometry libraries implement, leaves such a ring without an interior, which is why they refuse it or repair it first.
- A ring that is not closed gets closed, and a corridor that is walked twice cancels out, because a segment traversed in both directions does not change the count.
The result is always a valid polygon: clockwise shells and counter-clockwise holes, the order for which area is positive.
the grid as tolerance
Every vertex of the input and every computed intersection is snapped to a grid, and that grid is the tolerance. Two vertices in the same cell become one vertex, and a sliver thinner than a cell collapses and is dropped. Polygons come in and polygons go out, so a sliver that collapses to a line or a point is not part of the result.
| form | the grid | use |
|---|---|---|
| two arguments, integer coordinates | the integer grid itself | no vertex is moved, and every vertex of the result is an integer point |
| two arguments, float coordinates | a power of two: the coarser of the last-place unit of the largest coordinate and the extent divided by 2^36. The extent is that of the pair of elements for the element-by-element operators; for a dissolve it is the declared range of the values unit, or the extent of all the data when the unit declares none | far below the precision of geographic data, so the answer is the exact one |
| three arguments | the given grid size, in coordinate units | the tolerance at which near-coincident vertices merge and slivers disappear |
The grid size of the three-argument form is a parameter, one number for the whole attribute, so that two neighbours snap their shared boundary in the same way. It must be positive, a whole number for integer coordinates, and coarse enough for the operands: at most 2^36 cells in either direction over their joint extent. A grid that is too fine is refused with an error that says so.
A dissolve, dms_union_polygon or dms_split_union_polygon, derives its grid once for the whole call rather than per pair of elements: from the declared range of the values unit when it has one, and from the extent of all the elements otherwise. Every element and every intermediate result then lands on one lattice, so the result depends neither on the order of the elements nor on how the attribute is tiled. A values unit ranged over the whole of the Netherlands in metres gives a cell of about 8 micrometres.
what the result looks like
- No ring has a vertex on the straight line between its neighbours, so a shared edge that disappears in a union takes its collinear corners with it.
- Shells and holes start at their lexicographically first vertex and are written in that order, so the result depends neither on the order of the operands nor on where the input rings started:
dms_union(A, B)anddms_union(B, A)give the same sequence, anddms_xor(A, A)is empty. - An element whose result is empty is an empty sequence, not a remnant without area. An element with an undefined operand is undefined.
choosing between dms_ and the libraries
For data that is already valid, the geos_ operators remain the first choice: they are faster and offer more operations. Use the dms_ operators when the source is not clean, or when the model needs a tolerance. polygon operators lists the operators of all five families side by side and compares the libraries.
The family has no buffer of points or arcs, no simplification and no operator that keeps only the outer rings. For buffers and simplification, the geos_ operators take all six point types; to keep the outer rings, use bg_outer_multi_polygon. These operators need valid polygons, so clean the input with dms_polygon first.
The infix operators *, +, - and ^ apply bp_ and geos_ operators, not dms_ ones; see polygon operators. To get the reading of the dms_ family, call the operator by its name.
diagnostics
At the minor trace level each call reports how much snapping it did, for instance:
dms_union: 1240 sequences; 87 crossings snapped to the grid, 0 extra noding rounds, 0 undefined results
The crossings are the intersections that were moved onto the grid. The noding rounds are the extra passes needed when that snapping created a new incidence, and the last number counts the elements that came out undefined.
examples
Cleaning invalid polygons works through cleaning a source, reading a self-intersecting ring, closing slivers with a grid size and cutting a hole.
The test configurations of this family ship with GeoDMS in examples\testcases, and each one is a small, runnable example:
oper_dms_overlay.dms: the areas of the four element-by-element operations, their algebraic identities, and agreement with thebp_andgeos_resultsoper_dms_overlay_types.dms: all six point typesoper_dms_overlay_topology.dms: the layout of a multi polygon: several shells, a hole, an island in a lake, rings that touchoper_dms_overlay_neg1.dmstooper_dms_overlay_neg5.dms: the four refusals of a grid size and the check of the values unitoper_dms_single_ring.dms: an element that is one simple ring, against the full sweepoper_dms_crossings.dms: the crossing sweep on degenerate cases: several edges through one crossing, crossings on lattice points, vertical and collinear edges, a ring that crosses itselfoper_dms_union_counts.dms: the dissolve: an overlap is united, a ring wound the wrong way adds, partitions, and the grid of a ranged and of an unranged dpoint unitoper_dms_union_steep.dms: a snapped steep edge, against the pairwise resultoper_dms_dissolve_empty.dms: a dissolve of nothing, or of empty polygons, is emptyoper_dms_family.dms: the clean-up, the dissolve with and without a partition, the splits, the pairs and the two Minkowski operators, also on rings that are not validoper_dms_minkowski.dms: exact sums and erosions, a hole smaller than the kernel, a kernel per element and off the origin, and agreement with thegeos_andcgal_results;oper_dms_minkowski_neg1.dmstooper_dms_minkowski_neg3.dmsshow the refused kernelsoper_dms_buffer.dms: agreement with geos_buffer_multi_polygon, vertex counts includedoper_dms_split_convex.dms: the convex parts of both split operators: their number, the minimum of the Keil-Snoeyink variant, their union, the strict convexity of every corner, a hole that touches the shell, and a thousand elements over three tiles
see also
- polygon operators, every polygon operator by library
- Geos, boost polygon and cgal, the libraries
- Mul (polygon intersection), Add (union) and Sub (difference), the infix operators
since version
20.20.0. dms_split_convex_polygon, dms_split_convex_polygon_keilsnoeyink, dms_convex_polygon_connectivity, dms_buffer_multi_polygon and the grouped forms of dms_polygon_connectivity since 20.24.0.