def parse_ozi_map(map_file_name, cutline_type = None): """cutline_type can be 'projected', 'latlon' or None""" ozi_map = ozi_reader.read_map(open(map_file_name).readlines()) ozi_dir = os.path.split(os.path.abspath(map_file_name))[0] image_name = find_file_ci(ozi_dir, ozi_map.file_name) if not image_name: raise Exception('File "%s" not found.' % image_name) map_srs = get_srs_as_proj4(ozi_map.datum, ozi_map.projection) map_ll_srs = get_ozi_ll_srs(ozi_map.datum, ozi_map.projection) gcps = convert_ozi_gcps(ozi_map.gcps, map_srs, map_ll_srs) geotransform = gcps_to_geotransform(gcps) units_per_pixel = get_resolution(geotransform) if cutline_type and len(ozi_map.cutline) > 2: cutline_projected = {'projected': True, 'latlon': False}[cutline_type] if cutline_projected: cutline_points = convert_cutline(ozi_map.cutline, map_srs, map_ll_srs) cutline_srs = map_srs cutline_units_per_pixel = units_per_pixel else: cutline_points = convert_cutline(ozi_map.cutline) cutline_srs = map_ll_srs cutline_units_per_pixel = get_resolution(geotransform, map_srs, map_ll_srs) cutline = AttrDict(points = cutline_points, srs = cutline_srs, units_per_pixel = cutline_units_per_pixel) else: cutline = None result = AttrDict() result.image_name = image_name result.map_srs = map_srs result.gcps = gcps result.units_per_pixel = units_per_pixel result.cutline = cutline result.geotransform = geotransform result.datum = datum_names_map[ozi_map.datum] result.projection = ozi_map.projection result.inv_geotransform = gcps_to_geotransform([AttrDict(pixel = g.ref, ref = g.pixel) for g in gcps ]) return result