コード例 #1
0
    def write(self, process_tile):
        """
        Write data from process tiles into GeoTIFF file(s).

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        process_tile.data = prepare_array(
            process_tile.data,
            masked=True,
            nodata=self.nodata,
            dtype=self.profile(process_tile)["dtype"])
        if process_tile.data.mask.all():
            return
        # Convert from process_tile to output_tiles
        for tile in self.pyramid.intersecting(process_tile):
            out_path = self.get_path(tile)
            self.prepare_path(tile)
            out_tile = BufferedTile(tile, self.pixelbuffer)
            write_raster_window(in_tile=process_tile,
                                out_profile=self.profile(out_tile),
                                out_tile=out_tile,
                                out_path=out_path)
コード例 #2
0
ファイル: png_hillshade.py プロジェクト: gijs/mapchete
    def write(self, process_tile):
        """
        Write data from process tiles into PNG file(s).

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        data = prepare_array(process_tile.data,
                             dtype="uint8",
                             masked=False,
                             nodata=0)
        if self.old_band_num:
            data = np.stack(
                (np.zeros(process_tile.shape), np.zeros(process_tile.shape),
                 np.zeros(process_tile.shape), data[0]))
        else:
            data = np.stack((np.zeros(process_tile.shape), data[0]))
        process_tile.data = prepare_array(data,
                                          dtype="uint8",
                                          masked=True,
                                          nodata=255)
        # Convert from process_tile to output_tiles
        for tile in self.pyramid.intersecting(process_tile):
            # skip if file exists and overwrite is not set
            out_path = self.get_path(tile)
            self.prepare_path(tile)
            out_tile = BufferedTile(tile, self.pixelbuffer)
            write_raster_window(in_tile=process_tile,
                                out_profile=self.profile(out_tile),
                                out_tile=out_tile,
                                out_path=out_path)
コード例 #3
0
ファイル: geojson.py プロジェクト: jkrizan/mapchete
    def write(self, process_tile, data):
        """
        Write data from process tiles into GeoJSON file(s).

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        if data is None or len(data) == 0:
            return
        if not isinstance(data, (list, types.GeneratorType)):
            raise TypeError(
                "GeoJSON driver data has to be a list or generator of GeoJSON objects"
            )

        data = list(data)
        if not len(data):
            logger.debug("no features to write")
        else:
            # in case of S3 output, create an boto3 resource
            bucket_resource = get_boto3_bucket(
                self._bucket) if self._bucket else None

            # Convert from process_tile to output_tiles
            for tile in self.pyramid.intersecting(process_tile):
                out_path = self.get_path(tile)
                self.prepare_path(tile)
                out_tile = BufferedTile(tile, self.pixelbuffer)
                write_vector_window(in_data=data,
                                    out_schema=self.output_params["schema"],
                                    out_tile=out_tile,
                                    out_path=out_path,
                                    bucket_resource=bucket_resource)
コード例 #4
0
    def write(self, process_tile, data):
        """
        Write data from process tiles into GeoJSON file(s).

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        if data is None or len(data) == 0:
            return
        if not os.path.exists(self.path):
            os.makedirs(self.path)
        assert isinstance(data, (list, types.GeneratorType))
        data = list(data)
        # Convert from process_tile to output_tiles
        for tile in self.pyramid.intersecting(process_tile):
            # skip if file exists and overwrite is not set
            out_path = self.get_path(tile)
            self.prepare_path(tile)
            out_tile = BufferedTile(tile, self.pixelbuffer)
            write_vector_window(in_data=data,
                                out_schema=self.output_params["schema"],
                                out_tile=out_tile,
                                out_path=out_path)
コード例 #5
0
    def write(self, process_tile, data):
        """
        Write data from process tiles into PNG file(s).

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        data = self._prepare_array(data)

        if data.mask.all():  # pragma: no cover
            logger.debug("data empty, nothing to write")
        else:
            # in case of S3 output, create an boto3 resource
            bucket_resource = get_boto3_bucket(
                self._bucket) if self._bucket else None

            # Convert from process_tile to output_tiles and write
            for tile in self.pyramid.intersecting(process_tile):
                out_path = self.get_path(tile)
                self.prepare_path(tile)
                out_tile = BufferedTile(tile, self.pixelbuffer)
                write_raster_window(in_tile=process_tile,
                                    in_data=data,
                                    out_profile=self.profile(out_tile),
                                    out_tile=out_tile,
                                    out_path=out_path,
                                    bucket_resource=bucket_resource)
コード例 #6
0
    def write(self, process_tile, data):
        """
        Write data from one or more process tiles.

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        rgba = self._prepare_array_for_png(data)
        data = ma.masked_where(rgba == self.nodata, rgba)

        if data.mask.all():
            logger.debug("data empty, nothing to write")
        else:
            # in case of S3 output, create an boto3 resource
            bucket_resource = (
                boto3.resource('s3').Bucket(self._bucket)
                if self._bucket
                else None
            )

            # Convert from process_tile to output_tiles and write
            for tile in self.pyramid.intersecting(process_tile):
                out_path = self.get_path(tile)
                self.prepare_path(tile)
                out_tile = BufferedTile(tile, self.pixelbuffer)
                write_raster_window(
                    in_tile=process_tile,
                    in_data=data,
                    out_profile=self.profile(out_tile),
                    out_tile=out_tile,
                    out_path=out_path,
                    bucket_resource=bucket_resource
                )
コード例 #7
0
ファイル: gtiff.py プロジェクト: Milk-oolong/mapchete
    def write(self, process_tile, data):
        """
        Write data from process tiles into GeoTIFF file(s).

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        data = prepare_array(data,
                             masked=True,
                             nodata=self.output_params["nodata"],
                             dtype=self.profile(process_tile)["dtype"])

        if data.mask.all():
            logger.debug("data empty, nothing to write")
        else:
            # Convert from process_tile to output_tiles and write
            for tile in self.pyramid.intersecting(process_tile):
                out_tile = BufferedTile(tile, self.pixelbuffer)
                write_window = from_bounds(
                    *out_tile.bounds,
                    transform=self.rio_file.transform,
                    height=self.rio_file.height,
                    width=self.rio_file.width).round_lengths(
                        pixel_precision=0).round_offsets(pixel_precision=0)
                if _window_in_out_file(write_window, self.rio_file):
                    logger.debug("write data to window: %s", write_window)
                    self.rio_file.write(
                        extract_from_array(in_raster=data,
                                           in_affine=process_tile.affine,
                                           out_tile=out_tile)
                        if process_tile != out_tile else data,
                        window=write_window,
                    )
コード例 #8
0
    def write(self, process_tile, data):
        """
        Write data from process tiles into GeoTIFF file(s).

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        if (
            isinstance(data, tuple) and
            len(data) == 2 and
            isinstance(data[1], dict)
        ):
            data, tags = data
        else:
            tags = {}
        data = prepare_array(
            data, masked=True, nodata=self.nodata,
            dtype=self.profile(process_tile)["dtype"])
        if data.mask.all():
            return
        # Convert from process_tile to output_tiles
        for tile in self.pyramid.intersecting(process_tile):
            out_path = self.get_path(tile)
            self.prepare_path(tile)
            out_tile = BufferedTile(tile, self.pixelbuffer)
            write_raster_window(
                in_tile=process_tile, in_data=data,
                out_profile=self.profile(out_tile), out_tile=out_tile,
                out_path=out_path, tags=tags)
コード例 #9
0
ファイル: __init__.py プロジェクト: ungarj/mapchete-s3
    def write(self, process_tile, data):
        """
        Write data from process tiles into GeoTIFF file(s).

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        if (isinstance(data, tuple) and len(data) == 2
                and isinstance(data[1], dict)):
            data, tags = data
        else:
            tags = {}
        data = prepare_array(data,
                             masked=True,
                             nodata=self.nodata,
                             dtype=self.profile(process_tile)["dtype"])
        if data.mask.all():
            logger.debug((process_tile.id, "empty data"))
            return
        bucket = boto3.resource('s3').Bucket(self.bucket)
        for tile in self.pyramid.intersecting(process_tile):
            logger.debug((tile.id, "prepare to upload", self.get_path(tile)))
            out_tile = BufferedTile(tile, self.pixelbuffer)
            with RasterWindowMemoryFile(in_tile=process_tile,
                                        in_data=data,
                                        out_profile=self.profile(out_tile),
                                        out_tile=out_tile,
                                        tags=tags) as memfile:
                logger.debug(
                    (tile.id, "upload tile", self.get_bucket_key(tile)))
                bucket.put_object(Key=self.get_bucket_key(tile), Body=memfile)
コード例 #10
0
ファイル: png.py プロジェクト: puqiu/mapchete
    def write(self, process_tile, data):
        """
        Write data from one or more process tiles.

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        rgba = self._prepare_array_for_png(data)
        data = ma.masked_where(rgba == self.nodata, rgba)
        # Convert from process_tile to output_tiles
        for tile in self.pyramid.intersecting(process_tile):
            # skip if file exists and overwrite is not set
            self.prepare_path(tile)
            out_tile = BufferedTile(tile, self.pixelbuffer)
            write_raster_window(in_tile=process_tile,
                                in_data=data,
                                out_tile=BufferedTile(tile, self.pixelbuffer),
                                out_profile=self.profile(out_tile),
                                out_path=self.get_path(tile))
コード例 #11
0
ファイル: gtiff.py プロジェクト: elfmon/mapchete
    def write(self, process_tile, data):
        """
        Write data from process tiles into GeoTIFF file(s).

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        data : ``np.ndarray``
        """
        if (
            isinstance(data, tuple) and
            len(data) == 2 and
            isinstance(data[1], dict)
        ):
            data, tags = data
        else:
            tags = {}
        data = prepare_array(
            data,
            masked=True,
            nodata=self.output_params["nodata"],
            dtype=self.profile(process_tile)["dtype"]
        )

        if data.mask.all():
            logger.debug("data empty, nothing to write")
        else:
            # in case of S3 output, create an boto3 resource
            bucket_resource = get_boto3_bucket(self._bucket) if self._bucket else None

            # Convert from process_tile to output_tiles and write
            for tile in self.pyramid.intersecting(process_tile):
                out_path = self.get_path(tile)
                self.prepare_path(tile)
                out_tile = BufferedTile(tile, self.pixelbuffer)
                write_raster_window(
                    in_tile=process_tile,
                    in_data=data,
                    out_profile=self.profile(out_tile),
                    out_tile=out_tile,
                    out_path=out_path,
                    tags=tags,
                    bucket_resource=bucket_resource
                )
コード例 #12
0
ファイル: png_hillshade.py プロジェクト: puqiu/mapchete
    def write(self, process_tile, data):
        """
        Write data from process tiles into PNG file(s).

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        data = self._prepare_array(data)
        # Convert from process_tile to output_tiles
        for tile in self.pyramid.intersecting(process_tile):
            # skip if file exists and overwrite is not set
            out_path = self.get_path(tile)
            self.prepare_path(tile)
            out_tile = BufferedTile(tile, self.pixelbuffer)
            write_raster_window(
                in_tile=process_tile, in_data=data,
                out_profile=self.profile(out_tile), out_tile=out_tile,
                out_path=out_path)
コード例 #13
0
    def write(self, process_tile):
        """
        Write data from process tiles into NumPy array dumps.

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``
        """
        if not os.path.exists(self.path):
            os.makedirs(self.path)
        process_tile.data = prepare_array(
            process_tile.data, masked=True, nodata=self.nodata,
            dtype=self.output_params["dtype"]
        )
        # Convert from process_tile to output_tiles
        for tile in self.pyramid.intersecting(process_tile):
            out_tile = BufferedTile(tile, self.pixelbuffer)
            out_data = extract_from_tile(process_tile, out_tile)
            self.prepare_path(tile)
            out_data.dump(self.get_path(out_tile))