LWCOLLECTION *out = lwcollection_construct_empty(igeom->type, igeom->srid, FLAGS_GET_Z(igeom->flags), FLAGS_GET_M(igeom->flags));
if( lwcollection_is_empty(igeom) )
- return out;
+ return out; /* should we return NULL instead ? */
for( i = 0; i < igeom->ngeoms; i++ )
{
LWGEOM *ngeom = lwgeom_simplify(igeom->geoms[i], dist);
- out = lwcollection_add_lwgeom(out, ngeom);
+ if ( ngeom ) out = lwcollection_add_lwgeom(out, ngeom);
}
return out;
return LW_FAILURE;
return lwgeom_startpoint(col->geoms[0], pt);
-}
\ No newline at end of file
+}
if( lwline_is_empty(iline) )
return lwline_clone(iline);
- oline = lwline_construct(iline->srid, NULL, ptarray_simplify(iline->points, dist, 2));
+ static const int minvertices = 0; /* TODO: allow setting this */
+ oline = lwline_construct(iline->srid, NULL, ptarray_simplify(iline->points, dist, minvertices));
oline->type = iline->type;
return oline;
}
LWDEBUGF(2, "simplify_polygon3d: simplifying polygon with %d rings", ipoly->nrings);
if( lwpoly_is_empty(ipoly) )
- return opoly;
+ return opoly; /* should we return NULL instead ? */
for (i = 0; i < ipoly->nrings; i++)
{
- POINTARRAY *opts = ptarray_simplify(ipoly->rings[i], dist, 3);
+ static const int minvertices = 0; /* TODO: allow setting this */
+ POINTARRAY *opts = ptarray_simplify(ipoly->rings[i], dist, minvertices);
+
+ LWDEBUGF(3, "ring%d simplified from %d to %d points", i, ipoly->rings[i]->npoints, opts->npoints);
/* Less points than are needed to form a closed ring, we can't use this */
- if ( i && opts->npoints < 4 )
+ if ( opts->npoints < 4 )
{
LWDEBUGF(3, "ring%d skipped (% pts)", i, opts->npoints);
ptarray_free(opts);
- continue;
+ if ( i ) continue;
+ else break; /* Don't scan holes if shell is collapsed */
}
- LWDEBUGF(3, "ring%d simplified from %d to %d points", i, ipoly->rings[i]->npoints, opts->npoints);
-
/* Add ring to simplified polygon */
if( lwpoly_add_ring(opoly, opts) == LW_FAILURE )
return NULL;
-
- /* Don't scan holes if shell is collapsed */
- if ( !i && opts->npoints < 4 )
- {
- LWDEBUG(3, "nothing more to do for collapsed shell");
- break;
- }
}
LWDEBUGF(3, "simplified polygon with %d rings", ipoly->nrings);
opoly->type = ipoly->type;
+
+ if( lwpoly_is_empty(opoly) )
+ return NULL;
+
return opoly;
}
SELECT '8', ST_astext(ST_Simplify('POLYGON((0 0 3 2, 0 10 6 1, 0 51 1 6, 50 20 6 7, 30 20 9 9, 7 32 10 5, 0 0 3 2), (1 1 4 3, 1 3 2 3, 18 18 5 30, 1 1 4 3))', 1));
SELECT '9', ST_astext(ST_Simplify('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 5 6, 6 6, 8 5, 5 5))', 20));
+SELECT '10', ST_astext(ST_Simplify('LINESTRING(0 0, 0 10)', 20));
+SELECT '11', ST_astext(ST_Simplify('MULTIPOLYGON(((100 100, 100 130, 130 130, 130 100, 100 100)), ((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 5 6, 6 6, 8 5, 5 5)) )', 20));
+SELECT '12', ST_astext(ST_Simplify('MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 5 6, 6 6, 8 5, 5 5)),((100 100, 100 130, 130 130, 130 100, 100 100)))', 20));
6|MULTILINESTRING ZM ((0 0 3 2,0 51 1 6,50 20 6 7,7 32 10 5),(0 0 4 3,20 20 5 30))
7|POLYGON ZM ((0 0 3 2,0 51 1 6,50 20 6 7,7 32 10 5,0 0 3 2))
8|POLYGON ZM ((0 0 3 2,0 51 1 6,50 20 6 7,30 20 9 9,7 32 10 5,0 0 3 2),(1 1 4 3,1 3 2 3,18 18 5 30,1 1 4 3))
-9|POLYGON((0 0,10 10,0 0))
+9|
+10|LINESTRING(0 0,0 10)
+11|MULTIPOLYGON(((100 100,100 130,130 130,130 100,100 100)))
+12|MULTIPOLYGON(((100 100,100 130,130 130,130 100,100 100)))