示例#1
0
    def generate(self, eo_object, group_layer, suffix, options):
        coverage = eo_object.cast()
        extent = coverage.extent
        srid = coverage.srid

        data_items = coverage.data_items.all()
        range_type = coverage.range_type

        offsite = self.offsite_color_from_range_type(range_type)
        options = self.get_render_options(coverage)

        if srid is not None and extent_crosses_dateline(extent, srid):
            identifier = coverage.identifier
            wrapped_extent = wrap_extent_around_dateline(extent, srid)
            layer = self._create_layer(
                coverage, identifier + "_unwrapped", extent, identifier
            )

            self.set_render_options(layer, offsite, options)
            self.set_render_options(layer, offsite, options)
            yield layer, data_items
            wrapped_layer = self._create_layer(
                coverage, identifier + "_wrapped", wrapped_extent, identifier, True
            )
            self.set_render_options(wrapped_layer, offsite, options)
            yield wrapped_layer, data_items
        else:
            layer = self._create_layer(
                coverage, coverage.identifier, extent
            )
            self.set_render_options(layer, offsite, options)
            yield layer, data_items
    def connect(self, coverage, data_items, layer):
        filtered = filter(lambda d: d.semantic.startswith("bands"), data_items)
        data = connect(filtered[0])

        if isinstance(coverage, models.ReferenceableDataset):
            vrt_path = join("/vsimem", uuid4().hex)
            reftools.create_rectified_vrt(data, vrt_path)
            data = vrt_path
            layer.setMetaData("eoxs_ref_data", data)

        if not layer.metadata.get("eoxs_wrap_dateline") == "true":
            layer.data = data
        else:
            e = wrap_extent_around_dateline(coverage.extent, coverage.srid)

            vrt_path = join("/vsimem", uuid4().hex)
            ds = gdal.Open(data)
            vrt_ds = create_simple_vrt(ds, vrt_path)
            size_x = ds.RasterXSize
            size_y = ds.RasterYSize
            
            dx = abs(e[0] - e[2]) / size_x
            dy = abs(e[1] - e[3]) / size_y 
            
            vrt_ds.SetGeoTransform([e[0], dx, 0, e[3], 0, -dy])
            vrt_ds = None
            
            layer.data = vrt_path
示例#3
0
    def generate(self, eo_object, group_layer, suffix, options):
        coverage = eo_object.cast()
        extent = coverage.extent
        srid = coverage.srid

        data_items = coverage.data_items.all()
        range_type = coverage.range_type

        offsite = self.offsite_color_from_range_type(range_type)
        options = self.get_render_options(coverage)

        if srid is not None and extent_crosses_dateline(extent, srid):
            identifier = coverage.identifier
            wrapped_extent = wrap_extent_around_dateline(extent, srid)
            layer = self._create_layer(
                coverage, identifier + "_unwrapped", extent, identifier
            )

            self.set_render_options(layer, offsite, options)
            self.set_render_options(layer, offsite, options)
            yield layer, data_items
            wrapped_layer = self._create_layer(
                coverage, identifier + "_wrapped", wrapped_extent, identifier, True
            )
            self.set_render_options(wrapped_layer, offsite, options)
            yield wrapped_layer, data_items
        else:
            layer = self._create_layer(
                coverage, coverage.identifier, extent
            )
            self.set_render_options(layer, offsite, options)
            yield layer, data_items
示例#4
0
    def connect(self, coverage, data_items, layer, options):
        data = data_items[0].path

        if coverage.grid.is_referenceable:
            vrt_path = join("/vsimem", uuid4().hex)
            reftools.create_rectified_vrt(data, vrt_path)
            data = vrt_path
            layer.setMetaData("eoxs_ref_data", data)

        if not layer.metadata.get("eoxs_wrap_dateline") == "true":
            layer.data = data
        else:
            sr = coverage.grid.spatial_reference
            extent = coverage.extent
            e = wrap_extent_around_dateline(extent, sr.srid)

            vrt_path = join("/vsimem", uuid4().hex)
            ds = gdal.Open(data)
            vrt_ds = create_simple_vrt(ds, vrt_path)
            size_x = ds.RasterXSize
            size_y = ds.RasterYSize

            dx = abs(e[0] - e[2]) / size_x
            dy = abs(e[1] - e[3]) / size_y

            vrt_ds.SetGeoTransform([e[0], dx, 0, e[3], 0, -dy])
            vrt_ds = None

            layer.data = vrt_path
示例#5
0
    def connect(self, coverage, data_items, layer, options):
        filtered = filter(lambda d: d.semantic.startswith("bands"), data_items)
        data = connect(filtered[0])

        if isinstance(coverage, models.ReferenceableDataset):
            vrt_path = join("/vsimem", uuid4().hex)
            reftools.create_rectified_vrt(data, vrt_path)
            data = vrt_path
            layer.setMetaData("eoxs_ref_data", data)

        if not layer.metadata.get("eoxs_wrap_dateline") == "true":
            layer.data = data
        else:
            e = wrap_extent_around_dateline(coverage.extent, coverage.srid)

            vrt_path = join("/vsimem", uuid4().hex)
            ds = gdal.Open(data)
            vrt_ds = create_simple_vrt(ds, vrt_path)
            size_x = ds.RasterXSize
            size_y = ds.RasterYSize

            dx = abs(e[0] - e[2]) / size_x
            dy = abs(e[1] - e[3]) / size_y

            vrt_ds.SetGeoTransform([e[0], dx, 0, e[3], 0, -dy])
            vrt_ds = None

            layer.data = vrt_path
示例#6
0
def _create_raster_layer_objs(map_obj, extent, sr, data, filename_generator,
                              resample=None):
    layer_obj = ms.layerObj(map_obj)
    layer_obj.type = ms.MS_LAYER_RASTER
    layer_obj.status = ms.MS_ON

    layer_obj.data = data

    layer_obj.offsite = ms.colorObj(0, 0, 0)

    if extent:
        layer_obj.setMetaData("wms_extent", "%f %f %f %f" % extent)
        layer_obj.setExtent(*extent)

        if sr.srid is not None:
            short_epsg = "EPSG:%d" % sr.srid
            layer_obj.setMetaData("ows_srs", short_epsg)
            layer_obj.setMetaData("wms_srs", short_epsg)

    layer_obj.setProjection(sr.proj)

    if resample:
        layer_obj.setProcessingKey('RESAMPLE', resample)

    if extent and sr.srid and extent_crosses_dateline(extent, sr.srid):
        wrapped_extent = wrap_extent_around_dateline(extent, sr.srid)

        wrapped_layer_obj = ms.layerObj(map_obj)
        wrapped_layer_obj.type = ms.MS_LAYER_RASTER
        wrapped_layer_obj.status = ms.MS_ON

        wrapped_data = filename_generator.generate()
        vrt.with_extent(data, wrapped_extent, wrapped_data)
        wrapped_layer_obj.data = wrapped_data

        wrapped_layer_obj.offsite = ms.colorObj(0, 0, 0)

        wrapped_layer_obj.setMetaData("ows_srs", short_epsg)
        wrapped_layer_obj.setMetaData("wms_srs", short_epsg)
        wrapped_layer_obj.setProjection(sr.proj)

        wrapped_layer_obj.setExtent(*wrapped_extent)
        wrapped_layer_obj.setMetaData(
            "wms_extent", "%f %f %f %f" % wrapped_extent
        )
        return [layer_obj, wrapped_layer_obj]
    else:
        return [layer_obj]
    def generate(self):
        def _get_bands(cov):
            return cov.data_items.filter(semantic__startswith="bands")

        group = self.group if self.is_groupped else None
        if group:
            yield self._group_layer(group), None, ()

        for cov, cov_name in self.coverages:
            layer_group = "/"+group if group else ""

            # NOTE: In order to assure proper rendering of the nested layers
            #       a unique name has to be assigned to each of them.
            #       Note that they will never be addressed by their true name.
            #       The top-level coverages must preserve their true identity
            #       though because they are requested by the WMS query.
            base_name = cov_name if not group else \
                        "%s_%s_%08x"%(group, cov_name, random.randrange(16**8))

            # coverage specific rendering options
            ropt = self._render_options(cov)

            # band indices
            indices = self._indeces(cov, self.options, ropt)

            # get the data items
            data_items = _get_bands(cov)

            # prepare mask layer(s)
            mask_geom = self._mask_geom(cov)
            if mask_geom and (not mask_geom.empty):
                mask_name = "%s%s__mask__"%(base_name, self.suffix)
                layer = self._polygon_masking_layer(cov, mask_name,
                                            mask_geom, layer_group)
                yield layer, None, ()
            else:
                mask_name = None

            # prepare data layers
            if not extent_crosses_dateline(cov.extent, cov.srid):
                name = "%s%s"%(base_name, self.suffix)
                layer = self._data_layer(cov, name, cov.extent, layer_group,
                                    mask=mask_name, indices=indices, ropt=ropt)
                yield layer, cov, data_items

            else: # image crosses the date-line
                name = "%s%s"%(base_name, self.suffix)
                yield self._group_layer(cov.identifier, layer_group), None, ()
                layer_subgroup = "%s/%s%s"%(layer_group, name, self.suffix)

                # layer with the original extent
                name = "%s_1%s"%(base_name, self.suffix)
                extent = cov.extent
                layer = self._data_layer(cov, name, extent, layer_subgroup,
                    wrapped=False, mask=mask_name, indices=indices, ropt=ropt)
                yield layer, cov, data_items

                # TODO: check masking for date-line crossing products
                # create additional layer with +/-360dg latitude offset
                name = "%s_2%s"%(base_name, self.suffix)
                extent = wrap_extent_around_dateline(cov.extent, cov.srid)
                layer = self._data_layer(cov, name, extent, layer_subgroup,
                    wrapped=True, mask=mask_name, indices=indices, ropt=ropt)
                yield layer, cov, data_items