PostGIS  2.5.0dev-r@@SVN_REVISION@@
void lwgeom_grid_in_place ( LWGEOM geom,
const gridspec grid 
)

Definition at line 2138 of file lwgeom.c.

References CIRCSTRINGTYPE, COLLECTIONTYPE, COMPOUNDTYPE, LWCOLLECTION::geoms, LINETYPE, lwerror(), lwgeom_free(), 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, and LWGEOM::type.

Referenced by do_grid_test(), lwgeom_grid(), and mvt_geom().

2139 {
2140  if (!geom) return;
2141  switch ( geom->type )
2142  {
2143  case POINTTYPE:
2144  {
2145  LWPOINT *pt = (LWPOINT*)(geom);
2146  ptarray_grid_in_place(pt->point, grid);
2147  return;
2148  }
2149  case CIRCSTRINGTYPE:
2150  case LINETYPE:
2151  {
2152  LWLINE *ln = (LWLINE*)(geom);
2153  ptarray_grid_in_place(ln->points, grid);
2154  /* For invalid line, return an EMPTY */
2155  if (ln->points->npoints < 2)
2156  ln->points->npoints = 0;
2157  return;
2158  }
2159  case POLYGONTYPE:
2160  {
2161  LWPOLY *ply = (LWPOLY*)(geom);
2162  if (!ply->rings) return;
2163 
2164  /* Check first the external ring */
2165  uint32_t i = 0;
2166  POINTARRAY *pa = ply->rings[0];
2167  ptarray_grid_in_place(pa, grid);
2168  if (pa->npoints < 4)
2169  {
2170  /* External ring collapsed: free everything */
2171  for (i = 0; i < ply->nrings; i++)
2172  {
2173  ptarray_free(ply->rings[i]);
2174  }
2175  ply->nrings = 0;
2176  return;
2177  }
2178 
2179  /* Check the other rings */
2180  uint32_t j = 1;
2181  for (i = 1; i < ply->nrings; i++)
2182  {
2183  POINTARRAY *pa = ply->rings[i];
2184  ptarray_grid_in_place(pa, grid);
2185 
2186  /* Skip bad rings */
2187  if (pa->npoints >= 4)
2188  {
2189  ply->rings[j++] = pa;
2190  }
2191  else
2192  {
2193  ptarray_free(pa);
2194  }
2195  }
2196  /* Adjust ring count appropriately */
2197  ply->nrings = j;
2198  return;
2199  }
2200  case MULTIPOINTTYPE:
2201  case MULTILINETYPE:
2202  case MULTIPOLYGONTYPE:
2203  case COLLECTIONTYPE:
2204  case COMPOUNDTYPE:
2205  {
2206  LWCOLLECTION *col = (LWCOLLECTION*)(geom);
2207  uint32_t i, j = 0;
2208  if (!col->geoms) return;
2209  for (i = 0; i < col->ngeoms; i++)
2210  {
2211  LWGEOM *g = col->geoms[i];
2212  lwgeom_grid_in_place(g, grid);
2213  /* Empty geoms need to be freed */
2214  /* before we move on */
2215  if (lwgeom_is_empty(g))
2216  {
2217  lwgeom_free(g);
2218  continue;
2219  }
2220  col->geoms[j++] = g;
2221  }
2222  col->ngeoms = j;
2223  return;
2224  }
2225  default:
2226  {
2227  lwerror("%s: Unsupported geometry type: %s", __func__,
2228  lwtype_name(geom->type));
2229  return;
2230  }
2231  }
2232 }
#define LINETYPE
Definition: liblwgeom.h:85
#define POLYGONTYPE
Definition: liblwgeom.h:86
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:328
#define COMPOUNDTYPE
Definition: liblwgeom.h:92
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
void lwgeom_grid_in_place(LWGEOM *geom, const gridspec *grid)
Definition: lwgeom.c:2138
uint32_t ngeoms
Definition: liblwgeom.h:506
POINTARRAY * point
Definition: liblwgeom.h:410
uint32_t nrings
Definition: liblwgeom.h:454
void ptarray_grid_in_place(POINTARRAY *pa, const gridspec *grid)
Definition: ptarray.c:1873
unsigned int uint32_t
Definition: uthash.h:78
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
LWGEOM ** geoms
Definition: liblwgeom.h:508
POINTARRAY ** rings
Definition: liblwgeom.h:456
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1386
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
uint8_t type
Definition: liblwgeom.h:395
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91
void lwgeom_free(LWGEOM *lwgeom)
Definition: lwgeom.c:1137
#define MULTILINETYPE
Definition: liblwgeom.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
POINTARRAY * points
Definition: liblwgeom.h:421
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function:

Here is the caller graph for this function: