PostGIS  2.1.10dev-r@@SVN_REVISION@@
static GEOSGeometry* LWGEOM_GEOS_makeValidMultiLine ( const GEOSGeometry *  gin)
static

Definition at line 691 of file liblwgeom/lwgeom_geos_clean.c.

References lwalloc(), lwerror(), lwfree(), LWGEOM_GEOS_makeValidLine(), and lwrealloc().

Referenced by LWGEOM_GEOS_makeValid().

692 {
693  GEOSGeometry** lines;
694  GEOSGeometry** points;
695  GEOSGeometry* mline_out=0;
696  GEOSGeometry* mpoint_out=0;
697  GEOSGeometry* gout=0;
698  uint32_t nlines=0, nlines_alloc;
699  uint32_t npoints=0;
700  uint32_t ngeoms=0, nsubgeoms;
701  uint32_t i, j;
702 
703  ngeoms = GEOSGetNumGeometries(gin);
704 
705  nlines_alloc = ngeoms;
706  lines = lwalloc(sizeof(GEOSGeometry*)*nlines_alloc);
707  points = lwalloc(sizeof(GEOSGeometry*)*ngeoms);
708 
709  for (i=0; i<ngeoms; ++i)
710  {
711  const GEOSGeometry* g = GEOSGetGeometryN(gin, i);
712  GEOSGeometry* vg;
714  if ( GEOSisEmpty(vg) )
715  {
716  /* we don't care about this one */
717  GEOSGeom_destroy(vg);
718  }
719  if ( GEOSGeomTypeId(vg) == GEOS_POINT )
720  {
721  points[npoints++] = vg;
722  }
723  else if ( GEOSGeomTypeId(vg) == GEOS_LINESTRING )
724  {
725  lines[nlines++] = vg;
726  }
727  else if ( GEOSGeomTypeId(vg) == GEOS_MULTILINESTRING )
728  {
729  nsubgeoms=GEOSGetNumGeometries(vg);
730  nlines_alloc += nsubgeoms;
731  lines = lwrealloc(lines, sizeof(GEOSGeometry*)*nlines_alloc);
732  for (j=0; j<nsubgeoms; ++j)
733  {
734  const GEOSGeometry* gc = GEOSGetGeometryN(vg, j);
735  /* NOTE: ownership of the cloned geoms will be
736  * taken by final collection */
737  lines[nlines++] = GEOSGeom_clone(gc);
738  }
739  }
740  else
741  {
742  /* NOTE: return from GEOSGeomType will leak
743  * but we really don't expect this to happen */
744  lwerror("unexpected geom type returned "
745  "by LWGEOM_GEOS_makeValid: %s",
746  GEOSGeomType(vg));
747  }
748  }
749 
750  if ( npoints )
751  {
752  if ( npoints > 1 )
753  {
754  mpoint_out = GEOSGeom_createCollection(GEOS_MULTIPOINT,
755  points, npoints);
756  }
757  else
758  {
759  mpoint_out = points[0];
760  }
761  }
762 
763  if ( nlines )
764  {
765  if ( nlines > 1 )
766  {
767  mline_out = GEOSGeom_createCollection(
768  GEOS_MULTILINESTRING, lines, nlines);
769  }
770  else
771  {
772  mline_out = lines[0];
773  }
774  }
775 
776  lwfree(lines);
777 
778  if ( mline_out && mpoint_out )
779  {
780  points[0] = mline_out;
781  points[1] = mpoint_out;
782  gout = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION,
783  points, 2);
784  }
785  else if ( mline_out )
786  {
787  gout = mline_out;
788  }
789  else if ( mpoint_out )
790  {
791  gout = mpoint_out;
792  }
793 
794  lwfree(points);
795 
796  return gout;
797 }
void lwfree(void *mem)
Definition: lwutil.c:190
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
static GEOSGeometry * LWGEOM_GEOS_makeValidLine(const GEOSGeometry *gin)
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:183
void * lwalloc(size_t size)
Definition: lwutil.c:175

Here is the call graph for this function:

Here is the caller graph for this function: