createValidArea method

Geometry createValidArea(
  1. Geometry rawAreaGeom
)

Creates a valid area geometry from one that possibly has bad topology (i.e. self-intersections). Since buffer can handle invalid topology, but always returns valid geometry, constructing a 0-width buffer "corrects" the topology. Note this only works for area geometries, since buffer always returns areas. This also may return empty geometries, if the input has no actual area.

@param rawAreaGeom an area geometry possibly containing self-intersections @return a valid area geometry

Implementation

Geometry createValidArea(Geometry rawAreaGeom) {
  // if geometry is invalid then make it valid
  if (isEnsureValidTopology && !rawAreaGeom.isValid())
    return rawAreaGeom.buffer(0.0);
  return rawAreaGeom;
}