PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lwgeom_grid_in_place()

void lwgeom_grid_in_place ( LWGEOM lwgeom,
gridspec grid 
)

Definition at line 2317 of file lwgeom.c.

2318 {
2319  if (!geom) return;
2320  if (lwgeom_is_empty(geom)) return;
2321 
2323 
2324  switch ( geom->type )
2325  {
2326  case POINTTYPE:
2327  {
2328  LWPOINT *pt = (LWPOINT*)(geom);
2329  ptarray_grid_in_place(pt->point, grid);
2330  return;
2331  }
2332  case CIRCSTRINGTYPE:
2333  case TRIANGLETYPE:
2334  case LINETYPE:
2335  {
2336  LWLINE *ln = (LWLINE*)(geom);
2337  ptarray_grid_in_place(ln->points, grid);
2338  /* For invalid line, return an EMPTY */
2339  if (ln->points->npoints < 2)
2340  ln->points->npoints = 0;
2341  return;
2342  }
2343  case POLYGONTYPE:
2344  {
2345  LWPOLY *ply = (LWPOLY*)(geom);
2346  if (!ply->rings) return;
2347 
2348  /* Check first the external ring */
2349  uint32_t i = 0;
2350  POINTARRAY *pa = ply->rings[0];
2351  ptarray_grid_in_place(pa, grid);
2352  if (pa->npoints < 4)
2353  {
2354  /* External ring collapsed: free everything */
2355  for (i = 0; i < ply->nrings; i++)
2356  {
2357  ptarray_free(ply->rings[i]);
2358  }
2359  ply->nrings = 0;
2360  return;
2361  }
2362 
2363  /* Check the other rings */
2364  uint32_t j = 1;
2365  for (i = 1; i < ply->nrings; i++)
2366  {
2367  POINTARRAY *pa = ply->rings[i];
2368  ptarray_grid_in_place(pa, grid);
2369 
2370  /* Skip bad rings */
2371  if (pa->npoints >= 4)
2372  {
2373  ply->rings[j++] = pa;
2374  }
2375  else
2376  {
2377  ptarray_free(pa);
2378  }
2379  }
2380  /* Adjust ring count appropriately */
2381  ply->nrings = j;
2382  return;
2383  }
2384  case MULTIPOINTTYPE:
2385  case MULTILINETYPE:
2386  case MULTIPOLYGONTYPE:
2387  case TINTYPE:
2388  case COLLECTIONTYPE:
2389  case COMPOUNDTYPE:
2390  {
2391  LWCOLLECTION *col = (LWCOLLECTION*)(geom);
2392  uint32_t i, j = 0;
2393  if (!col->geoms) return;
2394  for (i = 0; i < col->ngeoms; i++)
2395  {
2396  LWGEOM *g = col->geoms[i];
2397  lwgeom_grid_in_place(g, grid);
2398  /* Empty geoms need to be freed */
2399  /* before we move on */
2400  if (lwgeom_is_empty(g))
2401  {
2402  lwgeom_free(g);
2403  continue;
2404  }
2405  col->geoms[j++] = g;
2406  }
2407  col->ngeoms = j;
2408  return;
2409  }
2410  default:
2411  {
2412  lwerror("%s: Unsupported geometry type: %s", __func__,
2413  lwtype_name(geom->type));
2414  return;
2415  }
2416  }
2417 }
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
#define COMPOUNDTYPE
Definition: liblwgeom.h:110
#define MULTILINETYPE
Definition: liblwgeom.h:106
#define LINETYPE
Definition: liblwgeom.h:103
#define MULTIPOINTTYPE
Definition: liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
#define TINTYPE
Definition: liblwgeom.h:116
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:107
#define POLYGONTYPE
Definition: liblwgeom.h:104
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:109
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:327
#define TRIANGLETYPE
Definition: liblwgeom.h:115
void ptarray_grid_in_place(POINTARRAY *pa, gridspec *grid)
Snap to grid.
Definition: ptarray.c:2234
static void condition_gridspec_scale(gridspec *grid)
Definition: lwgeom.c:2297
void lwgeom_grid_in_place(LWGEOM *geom, gridspec *grid)
Definition: lwgeom.c:2317
void lwgeom_free(LWGEOM *lwgeom)
Definition: lwgeom.c:1246
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:199
uint32_t ngeoms
Definition: liblwgeom.h:580
LWGEOM ** geoms
Definition: liblwgeom.h:575
POINTARRAY * points
Definition: liblwgeom.h:483
POINTARRAY * point
Definition: liblwgeom.h:471
POINTARRAY ** rings
Definition: liblwgeom.h:519
uint32_t nrings
Definition: liblwgeom.h:524
uint32_t npoints
Definition: liblwgeom.h:427

References CIRCSTRINGTYPE, COLLECTIONTYPE, COMPOUNDTYPE, condition_gridspec_scale(), LWCOLLECTION::geoms, LINETYPE, lwerror(), lwgeom_free(), lwgeom_grid_in_place(), lwgeom_is_empty(), lwtype_name(), MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, LWCOLLECTION::ngeoms, POINTARRAY::npoints, LWPOLY::nrings, LWPOINT::point, LWLINE::points, POINTTYPE, POLYGONTYPE, ptarray_free(), ptarray_grid_in_place(), LWPOLY::rings, TINTYPE, TRIANGLETYPE, and LWGEOM::type.

Referenced by do_grid_test(), lwgeom_grid(), lwgeom_grid_in_place(), mvt_clip_and_validate_geos(), mvt_geom(), and test_lwtriangle_clip().

Here is the call graph for this function:
Here is the caller graph for this function: