PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwgeom_grid_in_place()

void lwgeom_grid_in_place ( LWGEOM lwgeom,
const gridspec grid 
)

Definition at line 2144 of file lwgeom.c.

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

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(), and mvt_grid_and_validate_geos().

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