Converts a list of ``regions.Shape`` objects to crtf region strings.

        Parameters
        ----------
        coordsys : str
            This overrides the coordinate system frame for all regions.

        fmt : str
            A python string format defining the output precision.
            Default is .6f, which is accurate to 0.0036 arcseconds.

        radunit : str
            This denotes the unit of the radius.

        Returns
        -------
        region_string : str
            crtf region string

        Examples
        --------
        TODO

def to_crtf(self,  coordsys='fk5', fmt='.6f', radunit='deg'):
        """
        Converts a list of ``regions.Shape`` objects to crtf region strings.

        Parameters
        ----------
        coordsys : str
            This overrides the coordinate system frame for all regions.

        fmt : str
            A python string format defining the output precision.
            Default is .6f, which is accurate to 0.0036 arcseconds.

        radunit : str
            This denotes the unit of the radius.

        Returns
        -------
        region_string : str
            crtf region string

        Examples
        --------
        TODO
        """

        crtf_strings = {
            'circle': '{0}circle[[{1:FMT}deg, {2:FMT}deg], {3:FMT}RAD]',
            'circleannulus': '{0}annulus[[{1:FMT}deg, {2:FMT}deg], [{3:FMT}RAD, {4:FMT}RAD]]',
            'ellipse': '{0}ellipse[[{1:FMT}deg, {2:FMT}deg], [{3:FMT}RAD, {4:FMT}RAD], {5:FMT}deg]',
            'rectangle': '{0}rotbox[[{1:FMT}deg, {2:FMT}deg], [{3:FMT}RAD, {4:FMT}RAD], {5:FMT}deg]',
            'polygon': '{0}poly[{1}]',
            'point': '{0}point[[{1:FMT}deg, {2:FMT}deg]]',
            'symbol': '{0}symbol[[{1:FMT}deg, {2:FMT}deg], {symbol}]',
            'text': '{0}text[[{1:FMT}deg, {2:FMT}deg], \'{text}\']',
            'line': '{0}line[[{1:FMT}deg, {2:FMT}deg], [{3:FMT}deg, {4:FMT}deg]]'
                        }

        output = '#CRTF\n'

        if radunit == 'arcsec':
            # what's this for?
            if coordsys in coordsys_mapping['CRTF'].values():
                radunitstr = '"'
            else:
                raise ValueError(
                    'Radius unit arcsec not valid for coordsys {}'.format(
                        coordsys))
        else:
            radunitstr = radunit

        for key, val in crtf_strings.items():
            crtf_strings[key] = val.replace("FMT", fmt).replace("RAD",
                                                                radunitstr)

        # CASA does not support global coordinate specification, even though the
        # documentation for the specification explicitly states that it does.
        # output += 'global coord={}\n'.format(coordsys)

        for shape in self:

            shape.check_crtf()
            shape.meta = to_crtf_meta(shape.meta)

            # if unspecified, include is True.
            # Despite the specification, CASA does *not* support a preceding
            # "+".  If you want a region included, leave the opening character
            # blank.
            include = "-" if shape.include in (False, '-') else ""
            include += "ann " if shape.meta.get('type', 'reg') == 'ann' else ""

            if shape.meta.get('label', "") != "":
                shape.meta['label'] = "'{}'".format(shape.meta['label'])
            meta_str = ", ".join("{0}={1}".format(key, val) for key, val in
                                shape.meta.items() if
                                key not in ('include', 'comment', 'symbol',
                                            'coord', 'text', 'range', 'corr',
                                            'type'))

            # the first item should be the coordinates, since CASA cannot
            # recognize a region without an inline coordinate specification
            # It can be, but does not need to be, comma-separated at the start
            meta_str = "coord={0}, ".format(coordsys.upper()) + meta_str

            if 'comment' in shape.meta:
                meta_str += ", " + shape.meta['comment']
            if 'range' in shape.meta:
                shape.meta['range'] = [str(str(x).replace(" ", "")) for x in
                                       shape.meta['range']]
                meta_str += ", range={}".format(shape.meta['range']).replace("'", "")
            if 'corr' in shape.meta:
                meta_str += ", corr={}".format(shape.meta['corr']).replace("'", "")

            coord = []
            if coordsys not in ['image', 'physical']:
                for val in shape.coord:
                    if isinstance(val, Angle):
                        coord.append(float(val.value))
                    else:
                        if radunit == '' or None:
                            coord.append(float(val.value))
                        else:
                            coord.append(float(val.to(radunit).value))
            else:
                for val in shape.coord:
                    if isinstance(val, u.Quantity):
                        coord.append(float(val.value))
                    else:
                        coord.append(float(val))

            if shape.region_type in ['ellipse', 'rectangle'] and len(shape.coord) % 2 == 1:
                coord[-1] = float(shape.coord[-1].to('deg').value)

            if shape.region_type == 'polygon':
                val = '[{0:' + fmt + '}deg, {1:' + fmt + '}deg]'
                temp = [val.format(x, y) for x, y in zip(coord[::2], coord[1::2])]
                coord = ", ".join(temp)
                line = crtf_strings['polygon'].format(include, coord)
            elif shape.region_type == 'point':
                if 'symbol' in shape.meta:
                    line = crtf_strings['symbol'].format(include, *coord,
                                                         symbol=shape.meta['symbol'])
                else:
                    line = crtf_strings['point'].format(include, *coord)
            elif shape.region_type == 'ellipse':
                coord[2:] = [x / 2 for x in coord[2:]]
                if len(coord) % 2 == 1:
                    coord[-1] *= 2
                line = crtf_strings['ellipse'].format(include, *coord)
            elif shape.region_type == 'text':
                line = crtf_strings['text'].format(include, *coord, text=shape.meta['text'])
            else:
                line = crtf_strings[shape.region_type].format(include, *coord)

            if meta_str.strip():
                output += "{0}, {1}\n".format(line, meta_str)
            else:
                output += "{0}\n".format(line)

        return output