PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ lwgeom_grid_in_place()

void lwgeom_grid_in_place ( LWGEOM geom,
const gridspec grid 
)

Definition at line 2143 of file lwgeom.c.

2144 {
2145  if (!geom) return;
2146  if (lwgeom_is_empty(geom)) return;
2147  switch ( geom->type )
2148  {
2149  case POINTTYPE:
2150  {
2151  LWPOINT *pt = (LWPOINT*)(geom);
2152  ptarray_grid_in_place(pt->point, grid);
2153  return;
2154  }
2155  case CIRCSTRINGTYPE:
2156  case TRIANGLETYPE:
2157  case LINETYPE:
2158  {
2159  LWLINE *ln = (LWLINE*)(geom);
2160  ptarray_grid_in_place(ln->points, grid);
2161  /* For invalid line, return an EMPTY */
2162  if (ln->points->npoints < 2)
2163  ln->points->npoints = 0;
2164  return;
2165  }
2166  case POLYGONTYPE:
2167  {
2168  LWPOLY *ply = (LWPOLY*)(geom);
2169  if (!ply->rings) return;
2170 
2171  /* Check first the external ring */
2172  uint32_t i = 0;
2173  POINTARRAY *pa = ply->rings[0];
2174  ptarray_grid_in_place(pa, grid);
2175  if (pa->npoints < 4)
2176  {
2177  /* External ring collapsed: free everything */
2178  for (i = 0; i < ply->nrings; i++)
2179  {
2180  ptarray_free(ply->rings[i]);
2181  }
2182  ply->nrings = 0;
2183  return;
2184  }
2185 
2186  /* Check the other rings */
2187  uint32_t j = 1;
2188  for (i = 1; i < ply->nrings; i++)
2189  {
2190  POINTARRAY *pa = ply->rings[i];
2191  ptarray_grid_in_place(pa, grid);
2192 
2193  /* Skip bad rings */
2194  if (pa->npoints >= 4)
2195  {
2196  ply->rings[j++] = pa;
2197  }
2198  else
2199  {
2200  ptarray_free(pa);
2201  }
2202  }
2203  /* Adjust ring count appropriately */
2204  ply->nrings = j;
2205  return;
2206  }
2207  case MULTIPOINTTYPE:
2208  case MULTILINETYPE:
2209  case MULTIPOLYGONTYPE:
2210  case TINTYPE:
2211  case COLLECTIONTYPE:
2212  case COMPOUNDTYPE:
2213  {
2214  LWCOLLECTION *col = (LWCOLLECTION*)(geom);
2215  uint32_t i, j = 0;
2216  if (!col->geoms) return;
2217  for (i = 0; i < col->ngeoms; i++)
2218  {
2219  LWGEOM *g = col->geoms[i];
2220  lwgeom_grid_in_place(g, grid);
2221  /* Empty geoms need to be freed */
2222  /* before we move on */
2223  if (lwgeom_is_empty(g))
2224  {
2225  lwgeom_free(g);
2226  continue;
2227  }
2228  col->geoms[j++] = g;
2229  }
2230  col->ngeoms = j;
2231  return;
2232  }
2233  default:
2234  {
2235  lwerror("%s: Unsupported geometry type: %s", __func__,
2236  lwtype_name(geom->type));
2237  return;
2238  }
2239  }
2240 }
#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:2016
void lwgeom_free(LWGEOM *lwgeom)
Definition: lwgeom.c:1138
void lwgeom_grid_in_place(LWGEOM *geom, const gridspec *grid)
Definition: lwgeom.c:2143
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_geom(), mvt_grid_and_validate_geos(), and test_lwtriangle_clip().

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