'Testing empty geometries and collections.'

def test_emptyCollections(self):

    gc1 = GeometryCollection([])
    gc2 = fromstr(u'GEOMETRYCOLLECTION    EMPTY')
    pnt = fromstr(u'POINT    EMPTY')
    ls = fromstr(u'LINESTRING    EMPTY')
    poly = fromstr(u'POLYGON    EMPTY')
    mls = fromstr(u'MULTILINESTRING    EMPTY')
    mpoly1 = fromstr(u'MULTIPOLYGON    EMPTY')
    mpoly2 = MultiPolygon(())
    for g in [gc1, gc2, pnt, ls, poly, mls, mpoly1, mpoly2]:
        self.assertEqual(True, g.empty)
        if isinstance(g, Polygon):
            self.assertEqual(1, len(g))
            self.assertEqual(1, g.num_geom)
            self.assertEqual(0, len(g[0]))
        elif isinstance(g, (Point, LineString)):
            self.assertEqual(1, g.num_geom)
            self.assertEqual(0, len(g))
        else:
            self.assertEqual(0, g.num_geom)
            self.assertEqual(0, len(g))
        if isinstance(g, Point):
            self.assertRaises(GEOSIndexError, g.get_x)
        elif isinstance(g, Polygon):
            lr = g.shell
            self.assertEqual(u'LINEARRING    EMPTY', lr.wkt)
            self.assertEqual(0, len(lr))
            self.assertEqual(True, lr.empty)
            self.assertRaises(GEOSIndexError, lr.__getitem__, 0)
        else:
            self.assertRaises(GEOSIndexError, g.__getitem__, 0)
