PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ lwgeom_grid_in_place()

void lwgeom_grid_in_place ( LWGEOM geom,
const gridspec grid 
)

Definition at line 2172 of file lwgeom.c.

2173 {
2174  if (!geom) return;
2175  if (lwgeom_is_empty(geom)) return;
2176  switch ( geom->type )
2177  {
2178  case POINTTYPE:
2179  {
2180  LWPOINT *pt = (LWPOINT*)(geom);
2181  ptarray_grid_in_place(pt->point, grid);
2182  return;
2183  }
2184  case CIRCSTRINGTYPE:
2185  case TRIANGLETYPE:
2186  case LINETYPE:
2187  {
2188  LWLINE *ln = (LWLINE*)(geom);
2189  ptarray_grid_in_place(ln->points, grid);
2190  /* For invalid line, return an EMPTY */
2191  if (ln->points->npoints < 2)
2192  ln->points->npoints = 0;
2193  return;
2194  }
2195  case POLYGONTYPE:
2196  {
2197  LWPOLY *ply = (LWPOLY*)(geom);
2198  if (!ply->rings) return;
2199 
2200  /* Check first the external ring */
2201  uint32_t i = 0;
2202  POINTARRAY *pa = ply->rings[0];
2203  ptarray_grid_in_place(pa, grid);
2204  if (pa->npoints < 4)
2205  {
2206  /* External ring collapsed: free everything */
2207  for (i = 0; i < ply->nrings; i++)
2208  {
2209  ptarray_free(ply->rings[i]);
2210  }
2211  ply->nrings = 0;
2212  return;
2213  }
2214 
2215  /* Check the other rings */
2216  uint32_t j = 1;
2217  for (i = 1; i < ply->nrings; i++)
2218  {
2219  POINTARRAY *pa = ply->rings[i];
2220  ptarray_grid_in_place(pa, grid);
2221 
2222  /* Skip bad rings */
2223  if (pa->npoints >= 4)
2224  {
2225  ply->rings[j++] = pa;
2226  }
2227  else
2228  {
2229  ptarray_free(pa);
2230  }
2231  }
2232  /* Adjust ring count appropriately */
2233  ply->nrings = j;
2234  return;
2235  }
2236  case MULTIPOINTTYPE:
2237  case MULTILINETYPE:
2238  case MULTIPOLYGONTYPE:
2239  case TINTYPE:
2240  case COLLECTIONTYPE:
2241  case COMPOUNDTYPE:
2242  {
2243  LWCOLLECTION *col = (LWCOLLECTION*)(geom);
2244  uint32_t i, j = 0;
2245  if (!col->geoms) return;
2246  for (i = 0; i < col->ngeoms; i++)
2247  {
2248  LWGEOM *g = col->geoms[i];
2249  lwgeom_grid_in_place(g, grid);
2250  /* Empty geoms need to be freed */
2251  /* before we move on */
2252  if (lwgeom_is_empty(g))
2253  {
2254  lwgeom_free(g);
2255  continue;
2256  }
2257  col->geoms[j++] = g;
2258  }
2259  col->ngeoms = j;
2260  return;
2261  }
2262  default:
2263  {
2264  lwerror("%s: Unsupported geometry type: %s", __func__,
2265  lwtype_name(geom->type));
2266  return;
2267  }
2268  }
2269 }
#define COLLECTIONTYPE
Definition: liblwgeom.h:122
#define COMPOUNDTYPE
Definition: liblwgeom.h:124
#define MULTILINETYPE
Definition: liblwgeom.h:120
#define LINETYPE
Definition: liblwgeom.h:117
#define MULTIPOINTTYPE
Definition: liblwgeom.h:119
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:116
#define TINTYPE
Definition: liblwgeom.h:130
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:121
#define POLYGONTYPE
Definition: liblwgeom.h:118
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:123
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:129
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:1138
void lwgeom_grid_in_place(LWGEOM *geom, const gridspec *grid)
Definition: lwgeom.c:2172
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:594
LWGEOM ** geoms
Definition: liblwgeom.h:589
uint8_t type
Definition: liblwgeom.h:476
POINTARRAY * points
Definition: liblwgeom.h:497
POINTARRAY * point
Definition: liblwgeom.h:485
POINTARRAY ** rings
Definition: liblwgeom.h:533
uint32_t nrings
Definition: liblwgeom.h:538
uint32_t npoints
Definition: liblwgeom.h:441

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: