PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lwgeom_remove_irrelevant_points_for_view()

void lwgeom_remove_irrelevant_points_for_view ( LWGEOM geom,
GBOX bbox,
bool  cartesian_hint 
)

remove points that are irrelevant for rendering the geometry within a view specified by rectangular bounds.

2D-(MULTI)POLYGONs and (MULTI)LINESTRINGs are evaluated, others keep untouched.

Definition at line 318 of file liblwgeom/lwgeom_remove_irrelevant_points_for_view.c.

318  {
319 
320  unsigned int i, j, iw, jw;
321 
322  if (geom->type == LINETYPE) {
323 
324  LWLINE* line = (LWLINE*)geom;
325  removePoints(line->points, bbox, false, cartesian_hint);
326  }
327 
328  if (geom->type == MULTILINETYPE) {
329 
330  LWMLINE* mline = (LWMLINE*)geom;
331  iw = 0;
332  for (i=0; i<mline->ngeoms; i++) {
333  LWLINE* line = mline->geoms[i];
334  removePoints(line->points, bbox, false, cartesian_hint);
335 
336  if (line->points->npoints) {
337  // keep (reduced) line
338  mline->geoms[iw++] = line;
339  }
340  else {
341  // discard current line
342  lwfree(line);
343  }
344  }
345  mline->ngeoms = iw;
346  }
347 
348  if (geom->type == POLYGONTYPE) {
349 
350  LWPOLY* polygon = (LWPOLY*)geom;
351  iw = 0;
352  for (i=0; i<polygon->nrings; i++) {
353  removePoints(polygon->rings[i], bbox, true, cartesian_hint);
354 
355  if (polygon->rings[i]->npoints) {
356  // keep (reduced) ring
357  polygon->rings[iw++] = polygon->rings[i];
358  }
359  else {
360  if (!i) {
361  // exterior ring outside, free and skip all rings
362  unsigned int k;
363  for (k=0; k<polygon->nrings; k++) {
364  lwfree(polygon->rings[k]);
365  }
366  break;
367  }
368  else {
369  // free and remove current interior ring
370  lwfree(polygon->rings[i]);
371  }
372  }
373  }
374  polygon->nrings = iw;
375  }
376 
377  if (geom->type == MULTIPOLYGONTYPE) {
378 
379  LWMPOLY* mpolygon = (LWMPOLY*)geom;
380  jw = 0;
381  for (j=0; j<mpolygon->ngeoms; j++) {
382 
383  LWPOLY* polygon = mpolygon->geoms[j];
384  iw = 0;
385  for (i=0; i<polygon->nrings; i++) {
386  removePoints(polygon->rings[i], bbox, true, cartesian_hint);
387 
388  if (polygon->rings[i]->npoints) {
389  // keep (reduced) ring
390  polygon->rings[iw++] = polygon->rings[i];
391  }
392  else {
393  if (!i) {
394  // exterior ring outside, free and skip all rings
395  unsigned int k;
396  for (k=0; k<polygon->nrings; k++) {
397  lwfree(polygon->rings[k]);
398  }
399  break;
400  }
401  else {
402  // free and remove current interior ring
403  lwfree(polygon->rings[i]);
404  }
405  }
406  }
407  polygon->nrings = iw;
408 
409  if (iw) {
410  mpolygon->geoms[jw++] = polygon;
411  }
412  else {
413  // free and remove polygon from multipolygon
414  lwfree(polygon);
415  }
416  }
417  mpolygon->ngeoms = jw;
418  }
419 }
void removePoints(POINTARRAY *points, GBOX *bounds, bool closed, bool cartesian_hint)
#define MULTILINETYPE
Definition: liblwgeom.h:106
#define LINETYPE
Definition: liblwgeom.h:103
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:107
void lwfree(void *mem)
Definition: lwutil.c:248
#define POLYGONTYPE
Definition: liblwgeom.h:104
uint8_t type
Definition: liblwgeom.h:462
POINTARRAY * points
Definition: liblwgeom.h:483
LWLINE ** geoms
Definition: liblwgeom.h:547
uint32_t ngeoms
Definition: liblwgeom.h:552
uint32_t ngeoms
Definition: liblwgeom.h:566
LWPOLY ** geoms
Definition: liblwgeom.h:561
POINTARRAY ** rings
Definition: liblwgeom.h:519
uint32_t nrings
Definition: liblwgeom.h:524
uint32_t npoints
Definition: liblwgeom.h:427

References LWMLINE::geoms, LWMPOLY::geoms, LINETYPE, lwfree(), MULTILINETYPE, MULTIPOLYGONTYPE, LWMLINE::ngeoms, LWMPOLY::ngeoms, POINTARRAY::npoints, LWPOLY::nrings, LWLINE::points, POLYGONTYPE, removePoints(), LWPOLY::rings, and LWGEOM::type.

Referenced by ST_RemoveIrrelevantPointsForView(), and test_lwgeom_remove_irrelevant_points_for_view().

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