PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lwgeom_grid_in_place()

void lwgeom_grid_in_place ( LWGEOM geom,
const gridspec grid 
)

Definition at line 2166 of file lwgeom.c.

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