def get_source_and_dest_rect(self, dataset, subsets): size_x, size_y = dataset.RasterXSize, dataset.RasterYSize image_rect = Rect(0, 0, size_x, size_y) if not subsets: subset_rect = image_rect # pixel subset elif subsets.srid is None: # means "imageCRS" minx, miny, maxx, maxy = subsets.xy_bbox minx = int(minx) if minx is not None else image_rect.offset_x miny = int(miny) if miny is not None else image_rect.offset_y maxx = int(maxx) if maxx is not None else image_rect.upper_x maxy = int(maxy) if maxy is not None else image_rect.upper_y subset_rect = Rect(minx, miny, maxx - minx + 1, maxy - miny + 1) # subset in geographical coordinates else: vrt = VRTBuilder(*image_rect.size) vrt.copy_gcps(dataset) options = reftools.suggest_transformer(dataset) subset_rect = reftools.rect_from_subset(vrt.dataset, subsets.srid, *subsets.xy_bbox, **options) # check whether or not the subsets intersect with the image if not image_rect.intersects(subset_rect): raise RenderException("Subset outside coverage extent.", "subset") src_rect = subset_rect # & image_rect # TODO: why no intersection?? dst_rect = src_rect - subset_rect.offset return src_rect, dst_rect
def get_source_image_rect(self, dataset, subsets): size_x, size_y = dataset.RasterXSize, dataset.RasterYSize image_rect = Rect(0, 0, size_x, size_y) if not subsets: subset_rect = image_rect # pixel subset elif subsets.xy_srid is None: # means "imageCRS" minx, miny, maxx, maxy = subsets.xy_bbox minx = minx if minx is not None else image_rect.offset_x miny = miny if miny is not None else image_rect.offset_y maxx = maxx if maxx is not None else image_rect.upper_x maxy = maxy if maxy is not None else image_rect.upper_y subset_rect = Rect(minx, miny, maxx-minx, maxy-miny) else: vrt = VRTBuilder(size_x, size_y) vrt.copy_gcps(dataset) minx, miny, maxx, maxy = subsets.xy_bbox # subset in geographical coordinates subset_rect = reftools.rect_from_subset( vrt.dataset, subsets.xy_srid, minx, miny, maxx, maxy ) # check whether or not the subsets intersect with the image if not image_rect.intersects(subset_rect): raise Exception("Subset outside coverage extent.") # TODO: correct exception # in case the input and output rects are the same, return None to # indicate this #if image_rect == subset_rect: # return None return image_rect & subset_rect
def get_source_and_dest_rect(self, dataset, subsets): size_x, size_y = dataset.RasterXSize, dataset.RasterYSize image_rect = Rect(0, 0, size_x, size_y) if not subsets: subset_rect = image_rect # pixel subset elif subsets.srid is None: # means "imageCRS" minx, miny, maxx, maxy = subsets.xy_bbox minx = int(minx) if minx is not None else image_rect.offset_x miny = int(miny) if miny is not None else image_rect.offset_y maxx = int(maxx) if maxx is not None else image_rect.upper_x maxy = int(maxy) if maxy is not None else image_rect.upper_y subset_rect = Rect(minx, miny, maxx - minx + 1, maxy - miny + 1) # subset in geographical coordinates else: vrt = VRTBuilder(*image_rect.size) vrt.copy_gcps(dataset) options = reftools.suggest_transformer(dataset) subset_rect = reftools.rect_from_subset(vrt.dataset, subsets.srid, *subsets.xy_bbox, **options) # check whether or not the subsets intersect with the image if not image_rect.intersects(subset_rect): raise RenderException("Subset outside coverage extent.", "subset") src_rect = subset_rect #& image_rect # TODO: why no intersection?? dst_rect = src_rect - subset_rect.offset return src_rect, dst_rect