def _georef_from_parsed(parsed_browse, clipping=None): srid = fromShortCode(parsed_browse.reference_system_identifier) if (parsed_browse.reference_system_identifier == "RAW" and parsed_browse.geo_type != "modelInGeotiffBrowse"): raise IngestionException("Given referenceSystemIdentifier '%s' not " "valid for a '%s'." % (parsed_browse.reference_system_identifier, parsed_browse.geo_type)) if srid is None and parsed_browse.reference_system_identifier != "RAW": raise IngestionException("Given referenceSystemIdentifier '%s' not valid." % parsed_browse.reference_system_identifier) swap_axes = hasSwappedAxes(srid) if parsed_browse.geo_type == "rectifiedBrowse": coords = decode_coord_list(parsed_browse.coord_list, swap_axes) # values are for bottom/left and top/right pixel coords = [coord for pair in coords for coord in pair] assert(len(coords) == 4) return Extent(*coords, srid=srid) elif parsed_browse.geo_type == "footprintBrowse": # Generate GCPs from footprint coordinates pixels = decode_coord_list(parsed_browse.col_row_list) # substitute ncol and nrow with image size if clipping: clip_x, clip_y = clipping pixels[:] = [(clip_x if x == "ncol" else x, clip_y if y == "nrow" else y) for x, y in pixels] coord_list = decode_coord_list(parsed_browse.coord_list, swap_axes) if _coord_list_crosses_dateline(coord_list, CRS_BOUNDS[srid]): logger.info("Footprint crosses the dateline. Normalizing it.") coord_list = _unwrap_coord_list(coord_list, CRS_BOUNDS[srid]) assert(len(pixels) == len(coord_list)) gcps = [(x, y, pixel, line) for (x, y), (pixel, line) in zip(coord_list, pixels)] # check that the last point of the footprint is the first if not gcps[0] == gcps[-1]: raise IngestionException("The last value of the footprint is not " "equal to the first.") gcps.pop() return GCPList(gcps, srid) elif parsed_browse.geo_type == "regularGridBrowse": # calculate a list of pixel coordinates according to the values of the # parsed browse report (col_node_number * row_node_number) range_x = arange( 0.0, parsed_browse.row_node_number * parsed_browse.row_step, parsed_browse.row_step ) range_y = arange( 0.0, parsed_browse.col_node_number * parsed_browse.col_step, parsed_browse.col_step ) pixels = [(x, y) for x in range_x for y in range_y] # apply clipping if clipping: clip_x, clip_y = clipping pixels[:] = [ (min(clip_x, x), min(clip_y, y)) for x, y in pixels ] # decode coordinate lists and check if any crosses the dateline coord_lists = [] crosses_dateline = False for coord_list in parsed_browse.coord_lists: coord_list = decode_coord_list(coord_list, swap_axes) crosses_dateline = crosses_dateline or \ _coord_list_crosses_dateline(coord_list, CRS_BOUNDS[srid]) coord_lists.append(coord_list) # if any coordinate list was crossing the dateline, unwrap all # coordinate lists if crosses_dateline: logger.info("Regular grid crosses the dateline. Normalizing it.") coord_lists = [ _unwrap_coord_list(coord_list, CRS_BOUNDS[srid]) for coord_list in coord_lists ] coords = [] for coord_list in coord_lists: coords.extend(coord_list) # check validity of regularGrid if len(parsed_browse.coord_lists) != parsed_browse.row_node_number: raise IngestionException("Invalid regularGrid: number of coordinate " "lists is not equal to the given row node " "number.") elif len(coords) / len(parsed_browse.coord_lists) != parsed_browse.col_node_number: raise IngestionException("Invalid regularGrid: number of coordinates " "does not fit given columns number.") gcps = [(x, y, pixel, line) for (x, y), (pixel, line) in zip(coords, pixels)] return GCPList(gcps, srid) elif parsed_browse.geo_type == "modelInGeotiffBrowse": return None else: raise NotImplementedError("Invalid geo-reference type '%s'." % parsed_browse.geo_type)
def _georef_from_parsed(parsed_browse, clipping=None): srid = fromShortCode(parsed_browse.reference_system_identifier) if parsed_browse.reference_system_identifier == "RAW" and parsed_browse.geo_type != "modelInGeotiffBrowse": raise IngestionException( "Given referenceSystemIdentifier '%s' not " "valid for a '%s'." % (parsed_browse.reference_system_identifier, parsed_browse.geo_type) ) if srid is None and parsed_browse.reference_system_identifier != "RAW": raise IngestionException( "Given referenceSystemIdentifier '%s' not valid." % parsed_browse.reference_system_identifier ) swap_axes = hasSwappedAxes(srid) if parsed_browse.geo_type == "rectifiedBrowse": coords = decode_coord_list(parsed_browse.coord_list, swap_axes) # values are for bottom/left and top/right pixel coords = [coord for pair in coords for coord in pair] assert len(coords) == 4 return Extent(*coords, srid=srid) elif parsed_browse.geo_type == "footprintBrowse": # Generate GCPs from footprint coordinates pixels = decode_coord_list(parsed_browse.col_row_list) coord_list = decode_coord_list(parsed_browse.coord_list, swap_axes) if _coord_list_crosses_dateline(coord_list, CRS_BOUNDS[srid]): logger.info("Footprint crosses the dateline. Normalizing it.") coord_list = _unwrap_coord_list(coord_list, CRS_BOUNDS[srid]) assert len(pixels) == len(coord_list) gcps = [(x, y, pixel, line) for (x, y), (pixel, line) in zip(coord_list, pixels)] # check that the last point of the footprint is the first if not gcps[0] == gcps[-1]: raise IngestionException("The last value of the footprint is not " "equal to the first.") gcps.pop() return GCPList(gcps, srid) elif parsed_browse.geo_type == "regularGridBrowse": # calculate a list of pixel coordinates according to the values of the # parsed browse report (col_node_number * row_node_number) range_x = arange(0.0, parsed_browse.row_node_number * parsed_browse.row_step, parsed_browse.row_step) range_y = arange(0.0, parsed_browse.col_node_number * parsed_browse.col_step, parsed_browse.col_step) pixels = [(x, y) for x in range_x for y in range_y] # apply clipping if clipping: clip_x, clip_y = clipping pixels[:] = [(min(clip_x, x), min(clip_y, y)) for x, y in pixels] # decode coordinate lists and check if any crosses the dateline coord_lists = [] crosses_dateline = False for coord_list in parsed_browse.coord_lists: coord_list = decode_coord_list(coord_list, swap_axes) crosses_dateline = crosses_dateline or _coord_list_crosses_dateline(coord_list, CRS_BOUNDS[srid]) coord_lists.append(coord_list) # if any coordinate list was crossing the dateline, unwrap all # coordinate lists if crosses_dateline: logger.info("Regular grid crosses the dateline. Normalizing it.") coord_lists = [_unwrap_coord_list(coord_list, CRS_BOUNDS[srid]) for coord_list in coord_lists] coords = [] for coord_list in coord_lists: coords.extend(coord_list) # check validity of regularGrid if len(parsed_browse.coord_lists) != parsed_browse.row_node_number: raise IngestionException( "Invalid regularGrid: number of coordinate " "lists is not equal to the given row node " "number." ) elif len(coords) / len(parsed_browse.coord_lists) != parsed_browse.col_node_number: raise IngestionException("Invalid regularGrid: number of coordinates " "does not fit given columns number.") gcps = [(x, y, pixel, line) for (x, y), (pixel, line) in zip(coords, pixels)] return GCPList(gcps, srid) elif parsed_browse.geo_type == "modelInGeotiffBrowse": return None else: raise NotImplementedError("Invalid geo-reference type '%s'." % parsed_browse.geo_type)
def _georef_from_parsed(parsed_browse): srid = fromShortCode(parsed_browse.reference_system_identifier) if (parsed_browse.reference_system_identifier == "RAW" and parsed_browse.geo_type != "modelInGeotiffBrowse"): raise IngestionException("Given referenceSystemIdentifier '%s' not " "valid for a '%s'." % (parsed_browse.reference_system_identifier, parsed_browse.geo_type)) if srid is None and parsed_browse.reference_system_identifier != "RAW": raise IngestionException("Given referenceSystemIdentifier '%s' not valid." % parsed_browse.reference_system_identifier) swap_axes = hasSwappedAxes(srid) if parsed_browse.geo_type == "rectifiedBrowse": coords = decode_coord_list(parsed_browse.coord_list, swap_axes) # values are for bottom/left and top/right pixel coords = [coord for pair in coords for coord in pair] assert(len(coords) == 4) return Extent(*coords, srid=srid) elif parsed_browse.geo_type == "footprintBrowse": # Generate GCPs from footprint coordinates pixels = decode_coord_list(parsed_browse.col_row_list) coord_list = decode_coord_list(parsed_browse.coord_list, swap_axes) if _coord_list_crosses_dateline(coord_list, CRS_BOUNDS[srid]): logger.info("Footprint crosses the dateline. Normalizing it.") coord_list = _unwrap_coord_list(coord_list, CRS_BOUNDS[srid]) assert(len(pixels) == len(coord_list)) gcps = [(x, y, pixel, line) for (x, y), (pixel, line) in zip(coord_list, pixels)] # check that the last point of the footprint is the first if not gcps[0] == gcps[-1]: raise IngestionException("The last value of the footprint is not " "equal to the first.") gcps.pop() return GCPList(gcps, srid) elif parsed_browse.geo_type == "regularGridBrowse": # calculate a list of pixel coordinates according to the values of the # parsed browse report (col_node_number * row_node_number) range_x = arange( 0.0, parsed_browse.row_node_number * parsed_browse.row_step, parsed_browse.row_step ) range_y = arange( 0.0, parsed_browse.col_node_number * parsed_browse.col_step, parsed_browse.col_step ) pixels = [(x, y) for x in range_x for y in range_y] # get the lat-lon coordinates as tuple-lists # TODO: normalize if dateline is crossed coord_lists = [] for coord_list in parsed_browse.coord_lists: coord_list = decode_coord_list(coord_list, swap_axes) # TODO: iterate over every coord pair. if a dateline cross occurred # move all the negative values to the positive space if _coord_list_crosses_dateline(coord_list, CRS_BOUNDS[srid]): logger.info("Regular grid crosses the dateline. Normalizing it.") coord_list = _unwrap_coord_list(coord_list, CRS_BOUNDS[srid]) coord_lists.append(coord_list) coords = [] for coord_list in coord_lists: coords.extend(coord_list) # check validity of regularGrid if len(parsed_browse.coord_lists) != parsed_browse.row_node_number: raise IngestionException("Invalid regularGrid: number of coordinate " "lists is not equal to the given row node " "number.") elif len(coords) / len(parsed_browse.coord_lists) != parsed_browse.col_node_number: raise IngestionException("Invalid regularGrid: number of coordinates " "does not fit given columns number.") gcps = [(x, y, pixel, line) for (x, y), (pixel, line) in zip(coords, pixels)] return GCPList(gcps, srid) elif parsed_browse.geo_type == "modelInGeotiffBrowse": return None elif parsed_browse.geo_type == "verticalCurtainBrowse": pixels = decode_coord_list(parsed_browse.col_row_list) coord_list = decode_coord_list(parsed_browse.coord_list, swap_axes) if _coord_list_crosses_dateline(coord_list, CRS_BOUNDS[srid]): logger.info("Vertical curtain footprint crosses the dateline. Normalizing it.") coord_list = _unwrap_coord_list(coord_list, CRS_BOUNDS[srid]) gcps = [(x, y, pixel, line) for (x, y), (pixel, line) in zip(coord_list, pixels)] return VerticalCurtainGeoReference(gcps, srid) else: raise NotImplementedError("Invalid geo-reference type '%s'." % parsed_browse.geo_type)