'Create a .poly file for OpenStreetMap exports
http://wiki.openstreetmap.org/wiki/Osmosis/Polygon_Filter_File_Format'

@staticmethod
def create_poly(feature):

    from shapely.wkt import loads as wkt_loads
    try:
        from shapely import speedups
        speedups.enable()
    except:
        current.log.info('S3GIS', 'Upgrade    Shapely    for    Performance    enhancements')
    name = feature.name
    if ('wkt' in feature):
        wkt = feature.wkt
    else:
        table = current.s3db.gis_location
        wkt = current.db((table.id == feature.id)).select(table.wkt, limitby=(0, 1)).first().wkt
    try:
        shape = wkt_loads(wkt)
    except:
        error = ('Invalid    WKT:    %s' % name)
        current.log.error(error)
        return error
    geom_type = shape.geom_type
    if (geom_type == 'MultiPolygon'):
        polygons = shape.geoms
    elif (geom_type == 'Polygon'):
        polygons = [shape]
    else:
        error = ('Unsupported    Geometry:    %s,    %s' % (name, geom_type))
        current.log.error(error)
        return error
    if os.path.exists(os.path.join(os.getcwd(), 'temp')):
        TEMP = os.path.join(os.getcwd(), 'temp')
    else:
        import tempfile
        TEMP = tempfile.gettempdir()
    filename = ('%s.poly' % name)
    filepath = os.path.join(TEMP, filename)
    File = open(filepath, 'w')
    File.write(('%s\n' % filename))
    count = 1
    for polygon in polygons:
        File.write(('%s\n' % count))
        points = polygon.exterior.coords
        for point in points:
            File.write((' DCTB %s DCTB %s\n' % (point[0], point[1])))
        File.write('END\n')
        count += 1
    File.write('END\n')
    File.close()
    return None
