PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ lwgeom_grid_in_place()

void lwgeom_grid_in_place ( LWGEOM lwgeom,
const gridspec grid 
)

Definition at line 2189 of file lwgeom.c.

2190 {
2191  if (!geom) return;
2192  if (lwgeom_is_empty(geom)) return;
2193  switch ( geom->type )
2194  {
2195  case POINTTYPE:
2196  {
2197  LWPOINT *pt = (LWPOINT*)(geom);
2198  ptarray_grid_in_place(pt->point, grid);
2199  return;
2200  }
2201  case CIRCSTRINGTYPE:
2202  case TRIANGLETYPE:
2203  case LINETYPE:
2204  {
2205  LWLINE *ln = (LWLINE*)(geom);
2206  ptarray_grid_in_place(ln->points, grid);
2207  /* For invalid line, return an EMPTY */
2208  if (ln->points->npoints < 2)
2209  ln->points->npoints = 0;
2210  return;
2211  }
2212  case POLYGONTYPE:
2213  {
2214  LWPOLY *ply = (LWPOLY*)(geom);
2215  if (!ply->rings) return;
2216 
2217  /* Check first the external ring */
2218  uint32_t i = 0;
2219  POINTARRAY *pa = ply->rings[0];
2220  ptarray_grid_in_place(pa, grid);
2221  if (pa->npoints < 4)
2222  {
2223  /* External ring collapsed: free everything */
2224  for (i = 0; i < ply->nrings; i++)
2225  {
2226  ptarray_free(ply->rings[i]);
2227  }
2228  ply->nrings = 0;
2229  return;
2230  }
2231 
2232  /* Check the other rings */
2233  uint32_t j = 1;
2234  for (i = 1; i < ply->nrings; i++)
2235  {
2236  POINTARRAY *pa = ply->rings[i];
2237  ptarray_grid_in_place(pa, grid);
2238 
2239  /* Skip bad rings */
2240  if (pa->npoints >= 4)
2241  {
2242  ply->rings[j++] = pa;
2243  }
2244  else
2245  {
2246  ptarray_free(pa);
2247  }
2248  }
2249  /* Adjust ring count appropriately */
2250  ply->nrings = j;
2251  return;
2252  }
2253  case MULTIPOINTTYPE:
2254  case MULTILINETYPE:
2255  case MULTIPOLYGONTYPE:
2256  case TINTYPE:
2257  case COLLECTIONTYPE:
2258  case COMPOUNDTYPE:
2259  {
2260  LWCOLLECTION *col = (LWCOLLECTION*)(geom);
2261  uint32_t i, j = 0;
2262  if (!col->geoms) return;
2263  for (i = 0; i < col->ngeoms; i++)
2264  {
2265  LWGEOM *g = col->geoms[i];
2266  lwgeom_grid_in_place(g, grid);
2267  /* Empty geoms need to be freed */
2268  /* before we move on */
2269  if (lwgeom_is_empty(g))
2270  {
2271  lwgeom_free(g);
2272  continue;
2273  }
2274  col->geoms[j++] = g;
2275  }
2276  col->ngeoms = j;
2277  return;
2278  }
2279  default:
2280  {
2281  lwerror("%s: Unsupported geometry type: %s", __func__,
2282  lwtype_name(geom->type));
2283  return;
2284  }
2285  }
2286 }
#define COLLECTIONTYPE
Definition: liblwgeom.h:123
#define COMPOUNDTYPE
Definition: liblwgeom.h:125
#define MULTILINETYPE
Definition: liblwgeom.h:121
#define LINETYPE
Definition: liblwgeom.h:118
#define MULTIPOINTTYPE
Definition: liblwgeom.h:120
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:117
#define TINTYPE
Definition: liblwgeom.h:131
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:122
#define POLYGONTYPE
Definition: liblwgeom.h:119
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:124
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:130
void ptarray_grid_in_place(POINTARRAY *pa, const gridspec *grid)
Snap to grid.
Definition: ptarray.c:2078
void lwgeom_free(LWGEOM *lwgeom)
Definition: lwgeom.c:1155
void lwgeom_grid_in_place(LWGEOM *geom, const gridspec *grid)
Definition: lwgeom.c:2189
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
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:203
uint32_t ngeoms
Definition: liblwgeom.h:595
LWGEOM ** geoms
Definition: liblwgeom.h:590
POINTARRAY * points
Definition: liblwgeom.h:498
POINTARRAY * point
Definition: liblwgeom.h:486
POINTARRAY ** rings
Definition: liblwgeom.h:534
uint32_t nrings
Definition: liblwgeom.h:539
uint32_t npoints
Definition: liblwgeom.h:442

References CIRCSTRINGTYPE, COLLECTIONTYPE, COMPOUNDTYPE, 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: