680 GEOSGeometry** lines;
681 GEOSGeometry** points;
682 GEOSGeometry* mline_out=0;
683 GEOSGeometry* mpoint_out=0;
684 GEOSGeometry* gout=0;
690 ngeoms = GEOSGetNumGeometries(gin);
692 nlines_alloc = ngeoms;
693 lines =
lwalloc(
sizeof(GEOSGeometry*)*nlines_alloc);
694 points =
lwalloc(
sizeof(GEOSGeometry*)*ngeoms);
696 for (i=0; i<ngeoms; ++i)
698 const GEOSGeometry* g = GEOSGetGeometryN(gin, i);
706 GEOSGeom_destroy(vg);
709 if ( GEOSGeomTypeId(vg) == GEOS_POINT )
711 points[npoints++] = vg;
713 else if ( GEOSGeomTypeId(vg) == GEOS_LINESTRING )
715 lines[nlines++] = vg;
717 else if ( GEOSGeomTypeId(vg) == GEOS_MULTILINESTRING )
719 nsubgeoms=GEOSGetNumGeometries(vg);
720 nlines_alloc += nsubgeoms;
721 lines =
lwrealloc(lines,
sizeof(GEOSGeometry*)*nlines_alloc);
722 for (j=0; j<nsubgeoms; ++j)
724 const GEOSGeometry* gc = GEOSGetGeometryN(vg, j);
727 lines[nlines++] = GEOSGeom_clone(gc);
734 lwerror(
"unexpected geom type returned " 735 "by LWGEOM_GEOS_makeValid: %s",
744 mpoint_out = GEOSGeom_createCollection(GEOS_MULTIPOINT,
749 mpoint_out = points[0];
757 mline_out = GEOSGeom_createCollection(
758 GEOS_MULTILINESTRING, lines, nlines);
762 mline_out = lines[0];
768 if ( mline_out && mpoint_out )
770 points[0] = mline_out;
771 points[1] = mpoint_out;
772 gout = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION,
775 else if ( mline_out )
779 else if ( mpoint_out )
static GEOSGeometry * LWGEOM_GEOS_makeValidLine(const GEOSGeometry *gin)
void * lwrealloc(void *mem, size_t size)
void * lwalloc(size_t size)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.