def download_feature_info(self): try: search_url = self.feature_info_url + self.clear_code(self.code) self.log("Start downloading area info: %s" % search_url) response = self.make_request(search_url) resp = response data = json.loads(resp) if data: feature = data.get("feature") if feature: attrs = feature.get("attrs") if attrs: self.attrs = attrs self.code_id = attrs["id"] if feature.get("extent"): self.extent = feature["extent"] if feature.get("center"): x = feature["center"]["x"] y = feature["center"]["y"] if self.coord_out == "EPSG:4326": (x, y) = xy2lonlat(x, y) self.center = {"x": x, "y": y} self.attrs["center"] = self.center self.log("Area info downloaded.") return feature except TimeoutException: raise TimeoutException() except Exception as error: self.error(error) return False
def image_corners_to_coord(self, image_xy_corners): """calculate spatial coordinates from cartesian""" ex = self.get_extent_list(self.image_extent) dx = ((ex[2] - ex[0]) / self.width) dy = ((ex[3] - ex[1]) / self.height) xy_corners = [] for im_x, im_y in image_xy_corners: x = ex[0] + (im_x * dx) y = ex[3] - (im_y * dy) if self.coord_out == "EPSG:4326": (x, y) = xy2lonlat(x, y) xy_corners.append([x, y]) return xy_corners