PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lwgeom_grid_in_place()

void lwgeom_grid_in_place ( LWGEOM geom,
gridspec grid 
)

Definition at line 2289 of file lwgeom.c.

2290 {
2291  if (!geom) return;
2292  if (lwgeom_is_empty(geom)) return;
2293 
2295 
2296  switch ( geom->type )
2297  {
2298  case POINTTYPE:
2299  {
2300  LWPOINT *pt = (LWPOINT*)(geom);
2301  ptarray_grid_in_place(pt->point, grid);
2302  return;
2303  }
2304  case CIRCSTRINGTYPE:
2305  case TRIANGLETYPE:
2306  case LINETYPE:
2307  {
2308  LWLINE *ln = (LWLINE*)(geom);
2309  ptarray_grid_in_place(ln->points, grid);
2310  /* For invalid line, return an EMPTY */
2311  if (ln->points->npoints < 2)
2312  ln->points->npoints = 0;
2313  return;
2314  }
2315  case POLYGONTYPE:
2316  {
2317  LWPOLY *ply = (LWPOLY*)(geom);
2318  if (!ply->rings) return;
2319 
2320  /* Check first the external ring */
2321  uint32_t i = 0;
2322  POINTARRAY *pa = ply->rings[0];
2323  ptarray_grid_in_place(pa, grid);
2324  if (pa->npoints < 4)
2325  {
2326  /* External ring collapsed: free everything */
2327  for (i = 0; i < ply->nrings; i++)
2328  {
2329  ptarray_free(ply->rings[i]);
2330  }
2331  ply->nrings = 0;
2332  return;
2333  }
2334 
2335  /* Check the other rings */
2336  uint32_t j = 1;
2337  for (i = 1; i < ply->nrings; i++)
2338  {
2339  POINTARRAY *pa = ply->rings[i];
2340  ptarray_grid_in_place(pa, grid);
2341 
2342  /* Skip bad rings */
2343  if (pa->npoints >= 4)
2344  {
2345  ply->rings[j++] = pa;
2346  }
2347  else
2348  {
2349  ptarray_free(pa);
2350  }
2351  }
2352  /* Adjust ring count appropriately */
2353  ply->nrings = j;
2354  return;
2355  }
2356  case MULTIPOINTTYPE:
2357  case MULTILINETYPE:
2358  case MULTIPOLYGONTYPE:
2359  case TINTYPE:
2360  case COLLECTIONTYPE:
2361  case COMPOUNDTYPE:
2362  {
2363  LWCOLLECTION *col = (LWCOLLECTION*)(geom);
2364  uint32_t i, j = 0;
2365  if (!col->geoms) return;
2366  for (i = 0; i < col->ngeoms; i++)
2367  {
2368  LWGEOM *g = col->geoms[i];
2369  lwgeom_grid_in_place(g, grid);
2370  /* Empty geoms need to be freed */
2371  /* before we move on */
2372  if (lwgeom_is_empty(g))
2373  {
2374  lwgeom_free(g);
2375  continue;
2376  }
2377  col->geoms[j++] = g;
2378  }
2379  col->ngeoms = j;
2380  return;
2381  }
2382  default:
2383  {
2384  lwerror("%s: Unsupported geometry type: %s", __func__,
2385  lwtype_name(geom->type));
2386  return;
2387  }
2388  }
2389 }
#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:2099
static void condition_gridspec_scale(gridspec *grid)
Definition: lwgeom.c:2269
void lwgeom_grid_in_place(LWGEOM *geom, gridspec *grid)
Definition: lwgeom.c:2289
void lwgeom_free(LWGEOM *lwgeom)
Definition: lwgeom.c:1218
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
uint8_t type
Definition: liblwgeom.h:462
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: