PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwgeom_grid_in_place()

void lwgeom_grid_in_place ( LWGEOM geom,
const gridspec grid 
)

Definition at line 2152 of file lwgeom.c.

2153 {
2154  if (!geom) return;
2155  if (lwgeom_is_empty(geom)) return;
2156  switch ( geom->type )
2157  {
2158  case POINTTYPE:
2159  {
2160  LWPOINT *pt = (LWPOINT*)(geom);
2161  ptarray_grid_in_place(pt->point, grid);
2162  return;
2163  }
2164  case CIRCSTRINGTYPE:
2165  case TRIANGLETYPE:
2166  case LINETYPE:
2167  {
2168  LWLINE *ln = (LWLINE*)(geom);
2169  ptarray_grid_in_place(ln->points, grid);
2170  /* For invalid line, return an EMPTY */
2171  if (ln->points->npoints < 2)
2172  ln->points->npoints = 0;
2173  return;
2174  }
2175  case POLYGONTYPE:
2176  {
2177  LWPOLY *ply = (LWPOLY*)(geom);
2178  if (!ply->rings) return;
2179 
2180  /* Check first the external ring */
2181  uint32_t i = 0;
2182  POINTARRAY *pa = ply->rings[0];
2183  ptarray_grid_in_place(pa, grid);
2184  if (pa->npoints < 4)
2185  {
2186  /* External ring collapsed: free everything */
2187  for (i = 0; i < ply->nrings; i++)
2188  {
2189  ptarray_free(ply->rings[i]);
2190  }
2191  ply->nrings = 0;
2192  return;
2193  }
2194 
2195  /* Check the other rings */
2196  uint32_t j = 1;
2197  for (i = 1; i < ply->nrings; i++)
2198  {
2199  POINTARRAY *pa = ply->rings[i];
2200  ptarray_grid_in_place(pa, grid);
2201 
2202  /* Skip bad rings */
2203  if (pa->npoints >= 4)
2204  {
2205  ply->rings[j++] = pa;
2206  }
2207  else
2208  {
2209  ptarray_free(pa);
2210  }
2211  }
2212  /* Adjust ring count appropriately */
2213  ply->nrings = j;
2214  return;
2215  }
2216  case MULTIPOINTTYPE:
2217  case MULTILINETYPE:
2218  case MULTIPOLYGONTYPE:
2219  case TINTYPE:
2220  case COLLECTIONTYPE:
2221  case COMPOUNDTYPE:
2222  {
2223  LWCOLLECTION *col = (LWCOLLECTION*)(geom);
2224  uint32_t i, j = 0;
2225  if (!col->geoms) return;
2226  for (i = 0; i < col->ngeoms; i++)
2227  {
2228  LWGEOM *g = col->geoms[i];
2229  lwgeom_grid_in_place(g, grid);
2230  /* Empty geoms need to be freed */
2231  /* before we move on */
2232  if (lwgeom_is_empty(g))
2233  {
2234  lwgeom_free(g);
2235  continue;
2236  }
2237  col->geoms[j++] = g;
2238  }
2239  col->ngeoms = j;
2240  return;
2241  }
2242  default:
2243  {
2244  lwerror("%s: Unsupported geometry type: %s", __func__,
2245  lwtype_name(geom->type));
2246  return;
2247  }
2248  }
2249 }
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define MULTILINETYPE
Definition: liblwgeom.h:89
#define LINETYPE
Definition: liblwgeom.h:86
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define TINTYPE
Definition: liblwgeom.h:99
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:328
#define TRIANGLETYPE
Definition: liblwgeom.h:98
void ptarray_grid_in_place(POINTARRAY *pa, const gridspec *grid)
Definition: ptarray.c:2016
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
void lwgeom_free(LWGEOM *lwgeom)
Definition: lwgeom.c:1144
void lwgeom_grid_in_place(LWGEOM *geom, const gridspec *grid)
Definition: lwgeom.c:2152
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
uint32_t ngeoms
Definition: liblwgeom.h:510
LWGEOM ** geoms
Definition: liblwgeom.h:512
uint8_t type
Definition: liblwgeom.h:399
POINTARRAY * points
Definition: liblwgeom.h:425
POINTARRAY * point
Definition: liblwgeom.h:414
POINTARRAY ** rings
Definition: liblwgeom.h:460
uint32_t nrings
Definition: liblwgeom.h:458
uint32_t npoints
Definition: liblwgeom.h:374
unsigned int uint32_t
Definition: uthash.h:78

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: