PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ lwgeom_grid_in_place()

void lwgeom_grid_in_place ( LWGEOM lwgeom,
const gridspec grid 
)

Definition at line 2145 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().

2146 {
2147  if (!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 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 COLLECTIONTYPE:
2211  case COMPOUNDTYPE:
2212  {
2213  LWCOLLECTION *col = (LWCOLLECTION*)(geom);
2214  uint32_t i, j = 0;
2215  if (!col->geoms) return;
2216  for (i = 0; i < col->ngeoms; i++)
2217  {
2218  LWGEOM *g = col->geoms[i];
2219  lwgeom_grid_in_place(g, grid);
2220  /* Empty geoms need to be freed */
2221  /* before we move on */
2222  if (lwgeom_is_empty(g))
2223  {
2224  lwgeom_free(g);
2225  continue;
2226  }
2227  col->geoms[j++] = g;
2228  }
2229  col->ngeoms = j;
2230  return;
2231  }
2232  default:
2233  {
2234  lwerror("%s: Unsupported geometry type: %s", __func__,
2235  lwtype_name(geom->type));
2236  return;
2237  }
2238  }
2239 }
#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:2145
uint32_t ngeoms
Definition: liblwgeom.h:509
POINTARRAY * point
Definition: liblwgeom.h:413
uint32_t nrings
Definition: liblwgeom.h:457
void ptarray_grid_in_place(POINTARRAY *pa, const gridspec *grid)
Definition: ptarray.c:2009
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:511
POINTARRAY ** rings
Definition: liblwgeom.h:459
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:1393
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91
void lwgeom_free(LWGEOM *lwgeom)
Definition: lwgeom.c:1144
#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:424
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: