def read_output_metadata(metadata_json, **kwargs): params = read_json(metadata_json, **kwargs) grid = params["pyramid"]["grid"] if grid["type"] == "geodetic" and grid["shape"] == [2, 1 ]: # pragma: no cover warnings.warn( DeprecationWarning( "Deprecated grid shape ordering found. " "Please change grid shape from [2, 1] to [1, 2] in %s." % metadata_json)) params["pyramid"]["grid"]["shape"] = [1, 2] if "crs" in grid and isinstance(grid["crs"], str): crs = CRS.from_string(grid["crs"]) warnings.warn( DeprecationWarning( "Deprecated 'srs' found in %s: '%s'. " "Use WKT representation instead: %s" % (metadata_json, grid["crs"], pformat(dict(wkt=crs.to_wkt()))))) params["pyramid"]["grid"].update(srs=dict(wkt=crs.to_wkt())) params.update(pyramid=BufferedTilePyramid( params["pyramid"]["grid"], metatiling=params["pyramid"].get("metatiling", 1), tile_size=params["pyramid"].get("tile_size", 256), pixelbuffer=params["pyramid"].get("pixelbuffer", 0))) return params
def _input_tile_directory_info(input_): conf = read_json(os.path.join(input_, "metadata.json")) pyramid = BufferedTilePyramid.from_dict(conf["pyramid"]) return dict( output_params=conf["driver"], pyramid=pyramid.to_dict(), crs=pyramid.crs, zoom_levels=None, pixel_size=None, input_type=OUTPUT_FORMATS[conf["driver"]["format"]]["data_type"], bounds=None)
def test_read_remote_json(s3_metadata_json, http_metadata_json): assert isinstance(read_json(s3_metadata_json), dict) assert isinstance(read_json(http_metadata_json), dict) with pytest.raises(FileNotFoundError): read_json("s3://mapchete-test/invalid_metadata.json") with pytest.raises(FileNotFoundError): read_json("https://ungarj.github.io/mapchete_testdata/tiled_data/raster/cleantopo/invalid_metadata.json")
def __init__(self, input_params, **kwargs): """Initialize.""" super(InputData, self).__init__(input_params, **kwargs) if "abstract" in input_params: self._params = input_params["abstract"] self.path = absolute_path(path=self._params["path"], base_dir=input_params["conf_dir"]) # define pyramid self.td_pyramid = BufferedTilePyramid( self._params["type"], metatiling=self._params.get("metatiling", 1), tile_size=self._params.get("tile_size", 256), pixelbuffer=self._params.get("pixelbuffer", 0)) elif "path" in input_params: self.path = absolute_path(path=input_params["path"], base_dir=input_params.get("conf_dir")) try: params = read_json(os.path.join(self.path, "metadata.json")) except FileNotFoundError: raise MapcheteConfigError("Cannot find metadata.json in %s" % input_params["path"]) # define pyramid self.td_pyramid = BufferedTilePyramid( params["pyramid"]["grid"]["type"], metatiling=params["pyramid"].get("metatiling", 1), tile_size=params["pyramid"].get("tile_size", 256), pixelbuffer=params["pyramid"].get("pixelbuffer", 0)) output = load_output_writer(dict( params["driver"], metatiling=self.td_pyramid.metatiling, pixelbuffer=self.td_pyramid.pixelbuffer, pyramid=self.td_pyramid, type=self.td_pyramid.type, path=self.path), readonly=True) logger.debug(output) self._params = dict( path=self.path, type=params["pyramid"]["grid"]["type"], metatiling=params["pyramid"].get("metatiling", 1), pixelbuffer=params["pyramid"].get("pixelbuffer", 0), tile_size=params["pyramid"].get("tile_size", 256), extension=output.file_extension.split(".")[-1], **params["driver"]) # validate parameters validate_values(self._params, [("path", six.string_types), ("type", six.string_types), ("extension", six.string_types)]) if not self._params["extension"] in [ "tif", "vrt", "png", "jpg", "mixed", "jp2", "geojson" ]: raise MapcheteConfigError("invalid file extension given: %s" % self._params["extension"]) self._ext = self._params["extension"] # additional params self._bounds = self._params.get("bounds", self.td_pyramid.bounds) self._file_type = ("vector" if self._params["extension"] == "geojson" else "raster") if self._file_type == "raster": self._params["count"] = self._params.get( "count", self._params.get("bands", None)) validate_values(self._params, [("dtype", six.string_types), ("count", int)]) self._profile = { "nodata": self._params.get("nodata", 0), "dtype": self._params["dtype"], "count": self._params["count"] } else: self._profile = None