PostGIS  2.3.7dev-r@@SVN_REVISION@@
LWGEOM* lwgeom_voronoi_diagram ( const LWGEOM g,
const GBOX env,
double  tolerance,
int  output_edges 
)

Take vertices of a geometry and build the Voronoi diagram.

Parameters
gthe input geometry
envan optional envelope for clipping the results
tolerancean optional snapping tolerance for improved robustness
output_edgesif non-zero the result will be a MULTILINESTRING, otherwise it'll be a COLLECTION of polygons.

Requires GEOS-3.5.0 or higher

Definition at line 2069 of file liblwgeom/lwgeom_geos.c.

References COLLECTIONTYPE, GBOX2GEOS(), GEOS2LWGEOM(), LW_FALSE, lwcollection_as_lwgeom(), lwcollection_construct_empty(), lwerror(), lwgeom_count_vertices(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_get_geos_coordseq_2d(), lwgeom_get_srid(), lwgeom_set_srid(), and lwnotice().

Referenced by assert_empty_diagram(), ST_Voronoi(), test_lwgeom_voronoi_diagram(), and test_lwgeom_voronoi_diagram_custom_envelope().

2069  {
2070 #if POSTGIS_GEOS_VERSION < 35
2071  lwerror("lwgeom_voronoi_diagram: GEOS 3.5 or higher required");
2072  return NULL;
2073 #else
2074  uint32_t num_points = lwgeom_count_vertices(g);
2075  LWGEOM *lwgeom_result;
2076  char is_3d = LW_FALSE;
2077  int srid = lwgeom_get_srid(g);
2078  GEOSCoordSequence* coords;
2079  GEOSGeometry* geos_geom;
2080  GEOSGeometry* geos_env = NULL;
2081  GEOSGeometry* geos_result;
2082 
2083  if (num_points < 2)
2084  {
2086  return lwcollection_as_lwgeom(empty);
2087  }
2088 
2089  initGEOS(lwnotice, lwgeom_geos_error);
2090 
2091  /* Instead of using the standard LWGEOM2GEOS transformer, we read the vertices of the
2092  * LWGEOM directly and put them into a single GEOS CoordinateSeq that can be used to
2093  * define a LineString. This allows us to process geometry types that may not be
2094  * supported by GEOS, and reduces the memory requirements in cases of many geometries
2095  * with few points (such as LWMPOINT).
2096  */
2097  coords = lwgeom_get_geos_coordseq_2d(g, num_points);
2098  if (!coords)
2099  return NULL;
2100 
2101  geos_geom = GEOSGeom_createLineString(coords);
2102  if (!geos_geom)
2103  {
2104  GEOSCoordSeq_destroy(coords);
2105  return NULL;
2106  }
2107 
2108  if (env)
2109  geos_env = GBOX2GEOS(env);
2110 
2111  geos_result = GEOSVoronoiDiagram(geos_geom, geos_env, tolerance, output_edges);
2112 
2113  GEOSGeom_destroy(geos_geom);
2114  if (env)
2115  GEOSGeom_destroy(geos_env);
2116 
2117  if (!geos_result)
2118  {
2119  lwerror("GEOSVoronoiDiagram: %s", lwgeom_geos_errmsg);
2120  return NULL;
2121  }
2122 
2123  lwgeom_result = GEOS2LWGEOM(geos_result, is_3d);
2124  GEOSGeom_destroy(geos_result);
2125 
2126  lwgeom_set_srid(lwgeom_result, srid);
2127 
2128  return lwgeom_result;
2129 #endif /* POSTGIS_GEOS_VERSION < 35 */
2130 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:89
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
GEOSGeometry * GBOX2GEOS(const GBOX *box)
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:835
static GEOSCoordSequence * lwgeom_get_geos_coordseq_2d(const LWGEOM *g, uint32_t num_points)
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:76
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
void lwgeom_set_srid(LWGEOM *geom, int srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1153
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:232

Here is the call graph for this function:

Here is the caller graph for this function: