def proj4_to_epsg(projection):
    def make_definition(value):
        return {x.strip().lower() for x in value.split('+') if x}
    match = EPSG_RE.search(projection.srs)
    if match:
        return int(match.group(1))
    pyproj_data_dir = os.path.join(os.path.dirname(pyproj.__file__), 'data')
    pyproj_epsg_file = os.path.join(pyproj_data_dir, 'epsg')
    if os.path.exists(pyproj_epsg_file):
        definition = make_definition(projection.srs)
        f = open(pyproj_epsg_file, 'r')
        for line in f.readlines():
            match = PYPROJ_EPSG_FILE_RE.search(line)
            if match:
                file_definition = make_definition(match.group(2))
                if definition == file_definition:
                    return int(match.group(1))
    return None