def extent_to_ewkb(db, table_index, file):
    """Reads a polygon from a file and returns its EWKB.

    I didn't find a simple way to safely get SRIDs from the input geometry
    with Shapely, therefore it is obtained from the database and the CRS of the
    polygon is assumed to be the same as of the tile indexes.

    Parameters
    ----------
    db : db Class instance
    table_index : dict
        {'schema' : str, 'table' : str} of the table of tile index.
    file : str
        Path to the polygon for clipping the input.
        Must be in the same CRS as the table_index.

    Returns
    -------
    [Shapely polygon, EWKB str]
    """
    schema = sql.Identifier(table_index['schema'])
    table = sql.Identifier(table_index['table'])

    query = sql.SQL("""SELECT st_srid(geom) AS srid
                    FROM {schema}.{table}
                    LIMIT 1;""").format(schema=schema, table=table)
    srid = db.getQuery(query)[0][0]

    assert srid is not None

    # Get clip polygon and set SRID
    with fiona.open(file, 'r') as src:
        poly = shape(src[0]['geometry'])
        # Change a the default mode to add this, if SRID is set
        geos.WKBWriter.defaults['include_srid'] = True
        # set SRID for polygon
        geos.lgeos.GEOSSetSRID(poly._geom, srid)
        ewkb = poly.wkb_hex

    return([poly, ewkb])