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 _group_layer(name, group=None): """ Create group layer from a coverage.""" layer = ms.layerObj() layer.name = name if group: layer.setMetaData("wms_layer_group", group) return layer
def _create_polygon_layer(self, name): layer = ms.layerObj() layer.name = name layer.type = ms.MS_LAYER_POLYGON self.apply_styles(layer) srid = 4326 layer.setProjection(crss.asProj4Str(srid)) layer.setMetaData("ows_srs", crss.asShortCode(srid)) layer.setMetaData("wms_srs", crss.asShortCode(srid)) layer.dump = True layer.header = os.path.join(settings.PROJECT_DIR, "conf", "outline_template_header.html") layer.template = os.path.join(settings.PROJECT_DIR, "conf", "outline_template_dataset.html") layer.footer = os.path.join(settings.PROJECT_DIR, "conf", "outline_template_footer.html") layer.setMetaData("gml_include_items", "all") layer.setMetaData("wms_include_items", "all") layer.addProcessing("ITEMS=identifier") layer.offsite = ms.colorObj(0, 0, 0) return layer
def generate_group(self, name): layer = ms.layerObj() layer.name = name layer.type = ms.MS_LAYER_POLYGON layer.connectiontype = ms.MS_UNION layer.connection = "" self.apply_styles(layer, fill=True) return layer
def _create_mask_polygon_layer(name): mask_layer = ms.layerObj() mask_layer.name = name mask_layer.type = ms.MS_LAYER_POLYGON mask_layer.setMetaData("eoxs_geometry_reversed", "true") cls = ms.classObj(mask_layer) style = ms.styleObj(cls) style.color.setRGB(0, 0, 0) return mask_layer
def _create_polygon_layer(map_obj): layer_obj = ms.layerObj(map_obj) layer_obj.type = ms.MS_LAYER_POLYGON layer_obj.status = ms.MS_ON layer_obj.offsite = ms.colorObj(0, 0, 0) srid = 4326 layer_obj.setProjection(crss.asProj4Str(srid)) layer_obj.setMetaData("ows_srs", crss.asShortCode(srid)) layer_obj.setMetaData("wms_srs", crss.asShortCode(srid)) layer_obj.dump = True return layer_obj
def _data_layer(self, cov, name, extent=None, group=None, offsite=None, wrapped=False, mask=None, indices=None, ropt=None): """ Create plain data layer from a coverage.""" layer = ms.layerObj() layer.name = name layer.type = ms.MS_LAYER_RASTER if extent: layer.setMetaData("wms_extent", "%.12e %.12e %.12e %.12e"%extent) layer.setExtent(*extent) #layer.setMetaData( # "wms_enable_request", "getcapabilities getmap getfeatureinfo" #) if wrapped: # set the info for the connector to wrap this layer around the dateline layer.setMetaData("eoxs_wrap_dateline", "true") # set projection sr = cov.spatial_reference layer.setProjection(sr.proj) layer.setMetaData("ows_srs", "EPSG:%d"%sr.srid) layer.setMetaData("wms_srs", "EPSG:%d"%sr.srid) if indices: #layer.addProcessing("CLOSE_CONNECTION=CLOSE") #What it this good for? layer.setProcessingKey("BANDS", ",".join("%d"%v for v in indices)) if group: layer.setMetaData("wms_layer_group", group) if offsite: layer.offsite = offsite else: layer.offsite = self._offsite_color(cov.range_type, indices) if ropt: if ropt.scale_min is not None and ropt.scale_max is not None: scale = "%d,%d"%(ropt.scale_min, ropt.scale_max) layer.setProcessingKey("SCALE", scale) elif ropt.scale_auto: layer.setProcessingKey("SCALE", "AUTO") if mask: layer.mask = mask return layer
def _polygon_masking_layer(cov, name, mask, group=None): layer = ms.layerObj() layer.name = name layer.type = ms.MS_LAYER_POLYGON #layer.setMetaData("eoxs_geometry_reversed", "true") if group: layer.setMetaData("wms_layer_group", group) cls = ms.classObj(layer) style = ms.styleObj(cls) style.color.setRGB(0, 0, 0) shape = ms.shapeObj.fromWKT(mask.wkt) shape.initValues(1) shape.setValue(0, cov.identifier) # add feature to the layer layer.addFeature(shape) return layer
def _create_layer(self, coverage, name, extent=None, group=None, wrapped=False): layer = ms.layerObj() layer.name = name layer.type = ms.MS_LAYER_RASTER if extent: layer.setMetaData("wms_extent", "%f %f %f %f" % extent) layer.setExtent(*extent) # layer.setMetaData( # "wms_enable_request", "getcapabilities getmap getfeatureinfo" # ) if wrapped: # set the info for the connector to wrap this layer around the dateline layer.setMetaData("eoxs_wrap_dateline", "true") self._set_projection(layer, coverage.spatial_reference) if group: layer.group = group return layer
def _create_layer(self, coverage, name, extent=None, group=None, wrapped=False): layer = ms.layerObj() layer.name = name layer.type = ms.MS_LAYER_RASTER if extent: layer.setMetaData("wms_extent", "%f %f %f %f" % extent) layer.setExtent(*extent) #layer.setMetaData( # "wms_enable_request", "getcapabilities getmap getfeatureinfo" #) if wrapped: # set the info for the connector to wrap this layer around the # dateline layer.setMetaData("eoxs_wrap_dateline", "true") self._set_projection(layer, coverage.spatial_reference) if group: layer.group = group return layer
def layer_for_coverage(self, coverage, native_format, version=None): """ Helper method to generate a WCS enabled MapServer layer for a given coverage. """ range_type = coverage.range_type bands = list(range_type) # create and configure layer layer = ms.layerObj() layer.name = coverage.identifier layer.type = ms.MS_LAYER_RASTER layer.setProjection(coverage.spatial_reference.proj) extent = coverage.extent size = coverage.size resolution = ((extent[2] - extent[0]) / float(size[0]), (extent[1] - extent[3]) / float(size[1])) layer.setExtent(*extent) ms.setMetaData(layer, { "title": coverage.identifier, "enable_request": "*" }, namespace="ows") ms.setMetaData(layer, { "label": coverage.identifier, "extent": "%.10g %.10g %.10g %.10g" % extent, "resolution": "%.10g %.10g" % resolution, "size": "%d %d" % size, "bandcount": str(len(bands)), "interval": "%f %f" % bands[0].allowed_values, "significant_figures": "%d" % bands[0].significant_figures, "rangeset_name": range_type.name, "rangeset_label": range_type.name, "imagemode": ms.gdalconst_to_imagemode_string(bands[0].data_type), "formats": " ".join([ f.wcs10name if version.startswith("1.0") else f.mimeType for f in self.get_wcs_formats()] ) }, namespace="wcs") if version is None or version.startswith("2.0"): ms.setMetaData(layer, { "band_names": " ".join([band.name for band in bands]), }, namespace="wcs") else: ms.setMetaData(layer, { "rangeset_axes": ",".join(band.name for band in bands), }, namespace="wcs") if native_format: if version.startswith("1.0"): native_format = next(( x.wcs10name for x in self.get_wcs_formats() if x.mimeType == native_format), native_format ) ms.setMetaData(layer, { "native_format": native_format, "nativeformat": native_format }, namespace="wcs") native_crs = "EPSG:%d" % coverage.spatial_reference.srid all_crss = crss.getSupportedCRS_WCS(format_function=crss.asShortCode) if native_crs in all_crss: all_crss.remove(native_crs) # setting the coverages CRS as the first one is important! all_crss.insert(0, native_crs) supported_crss = " ".join(all_crss) layer.setMetaData("ows_srs", supported_crss) layer.setMetaData("wcs_srs", supported_crss) for band in bands: ms.setMetaData(layer, { "band_description": band.description, "band_definition": band.definition, "band_uom": band.uom, }, namespace=band.name) # For MS WCS 1.x interface ms.setMetaData(layer, { "label": band.name, "interval": "%d %d" % band.allowed_values }, namespace="wcs_%s" % band.name) if bands[0].nil_value_set: nilvalues = " ".join( str(nil_value.value) for nil_value in bands[0].nil_value_set ) nilvalues_reasons = " ".join( nil_value.reason for nil_value in bands[0].nil_value_set ) if nilvalues: ms.setMetaData(layer, { "nilvalues": nilvalues, "nilvalues_reasons": nilvalues_reasons }, namespace="wcs") return layer
def layer_for_coverage(self, coverage, native_format, version=None): """ Helper method to generate a WCS enabled MapServer layer for a given coverage. """ range_type = coverage.range_type bands = list(range_type) # create and configure layer layer = ms.layerObj() layer.name = coverage.identifier layer.type = ms.MS_LAYER_RASTER layer.setProjection(coverage.spatial_reference.proj) extent = coverage.extent size = coverage.size resolution = ((extent[2] - extent[0]) / float(size[0]), (extent[1] - extent[3]) / float(size[1])) layer.setExtent(*extent) ms.setMetaData(layer, { "title": coverage.identifier, "enable_request": "*" }, namespace="ows") ms.setMetaData(layer, { "label": coverage.identifier, "extent": "%.10g %.10g %.10g %.10g" % extent, "resolution": "%.10g %.10g" % resolution, "size": "%d %d" % size, "bandcount": str(len(bands)), "interval": "%f %f" % bands[0].allowed_values, "significant_figures": "%d" % bands[0].significant_figures, "rangeset_name": range_type.name, "rangeset_label": range_type.name, "imagemode": ms.gdalconst_to_imagemode_string(bands[0].data_type), "formats": " ".join([ f.wcs10name if version.startswith("1.0") else f.mimeType for f in self.get_wcs_formats() ]) }, namespace="wcs") if version is None or version.startswith("2.0"): ms.setMetaData( layer, { "band_names": " ".join([band.name for band in bands]), }, namespace="wcs") else: ms.setMetaData( layer, { "rangeset_axes": ",".join(band.name for band in bands), }, namespace="wcs") if native_format: if version.startswith("1.0"): native_format = next( (x.wcs10name for x in self.get_wcs_formats() if x.mimeType == native_format), native_format) ms.setMetaData(layer, { "native_format": native_format, "nativeformat": native_format }, namespace="wcs") native_crs = "EPSG:%d" % coverage.spatial_reference.srid all_crss = crss.getSupportedCRS_WCS(format_function=crss.asShortCode) if native_crs in all_crss: all_crss.remove(native_crs) # setting the coverages CRS as the first one is important! all_crss.insert(0, native_crs) supported_crss = " ".join(all_crss) layer.setMetaData("ows_srs", supported_crss) layer.setMetaData("wcs_srs", supported_crss) for band in bands: ms.setMetaData(layer, { "band_description": band.description, "band_definition": band.definition, "band_uom": band.uom, }, namespace=band.name) # For MS WCS 1.x interface ms.setMetaData(layer, { "label": band.name, "interval": "%d %d" % band.allowed_values }, namespace="wcs_%s" % band.name) if bands[0].nil_value_set: nilvalues = " ".join( str(nil_value.value) for nil_value in bands[0].nil_value_set) nilvalues_reasons = " ".join( nil_value.reason for nil_value in bands[0].nil_value_set) if nilvalues: ms.setMetaData(layer, { "nilvalues": nilvalues, "nilvalues_reasons": nilvalues_reasons }, namespace="wcs") return layer
def get_empty_layers(self, name): layer = ms.layerObj() layer.name = name layer.setMetaData("wms_enable_request", "getmap") return (layer,)
def setup_map(self, layer_selection, map_, options): group_layers = SortedDict() session = ConnectorSession(options) # set up group layers before any "real" layers for collections, _, name, suffix in tuple(layer_selection.walk()): if not collections: continue # get a factory for the given suffix factory = self.get_layer_factory(suffix) if not factory: # raise or pass? continue # get the groups name, which is the name of the collection + the # suffix group_name = collections[-1].identifier + (suffix or "") # generate a group layer group_layer = factory.generate_group(group_name) group_layers[group_name] = group_layer # set up the actual layers for each coverage for collections, coverage, name, suffix in layer_selection.walk(): # get a factory for the given coverage and suffix factory = self.get_layer_factory(suffix) group_layer = None group_name = None if collections: group_name = collections[-1].identifier + (suffix or "") group_layer = group_layers.get(group_name) if not coverage: # add an empty layer to not produce errors out of bounds. if name: tmp_layer = ms.layerObj() tmp_layer.name = (name + suffix) if suffix else name layers_and_data_items = ((tmp_layer, ()),) else: layers_and_data_items = () elif not factory: tmp_layer = ms.layerObj() tmp_layer.name = name layers_and_data_items = ((tmp_layer, ()),) else: data_items = coverage.data_items.all() coverage.cached_data_items = data_items layers_and_data_items = tuple(factory.generate( coverage, group_layer, suffix, options )) for layer, data_items in layers_and_data_items: connector = self.get_connector(data_items) if group_name: layer.setMetaData("wms_layer_group", "/" + group_name) session.add(connector, coverage, data_items, layer) coverage_layers = [layer for _, layer, _ in session.coverage_layers] for layer in chain(group_layers.values(), coverage_layers): old_layer = map_.getLayerByName(layer.name) if old_layer: # remove the old layer and reinsert the new one, to # raise the layer to the top. # TODO: find a more efficient way to do this map_.removeLayer(old_layer.index) map_.insertLayer(layer) # apply any styles # TODO: move this to map/legendgraphic renderer only? for coverage, layer, data_items in session.coverage_layers: for applicator in self.style_applicators: applicator.apply(coverage, data_items, layer) return session
def generate_group(self, name): layer = ms.layerObj() layer.name = name layer.type = ms.MS_LAYER_RASTER return layer
def layer_for_coverage(self, coverage, native_format, version=None): """ Helper method to generate a WCS enabled MapServer layer for a given coverage. """ range_type = coverage.range_type bands = list(range_type) coverage_identifier = coverage.identifier if version and version.startswith('2'): try: models.identifier_validators[0](coverage_identifier) except Exception: coverage_identifier = 'not-ncname' # create and configure layer layer = ms.layerObj() layer.name = coverage_identifier layer.type = ms.MS_LAYER_RASTER sr = coverage.grid.spatial_reference layer.setProjection(sr.proj) extent = coverage.extent size = coverage.size resolution = ((extent[2] - extent[0]) / float(size[0]), (extent[1] - extent[3]) / float(size[1])) layer.setExtent(*extent) ms.setMetaData(layer, { "title": coverage_identifier, "enable_request": "*" }, namespace="ows") data_type = bands[0].data_type if bands[0].allowed_values: interval = bands[0].allowed_values[0] else: interval = gdal.GDT_NUMERIC_LIMITS[data_type] if bands[0].significant_figures is not None: significant_figures = bands[0].significant_figures else: significant_figures = gdal.GDT_SIGNIFICANT_FIGURES[data_type] ms.setMetaData(layer, { "label": coverage_identifier, "extent": "%.10g %.10g %.10g %.10g" % extent, "resolution": "%.10g %.10g" % resolution, "size": "%d %d" % size, "bandcount": str(len(bands)), "interval": "%f %f" % interval, "significant_figures": "%d" % significant_figures, "rangeset_name": range_type.name, "rangeset_label": range_type.name, "imagemode": ms.gdalconst_to_imagemode_string(bands[0].data_type), "formats": " ".join([ f.wcs10name if version.startswith("1.0") else f.mimeType for f in self.get_wcs_formats() ]) }, namespace="wcs") if version is None or version.startswith("2.0"): ms.setMetaData( layer, { "band_names": " ".join([band.identifier for band in bands]), }, namespace="wcs") else: ms.setMetaData( layer, { "rangeset_axes": ",".join(band.identifier for band in bands), }, namespace="wcs") if native_format: if version.startswith("1.0"): native_format = next( (x.wcs10name for x in self.get_wcs_formats() if x.mimeType == native_format), native_format) ms.setMetaData(layer, { "native_format": native_format, "nativeformat": native_format }, namespace="wcs") native_crs = "EPSG:%d" % sr.srid all_crss = list( crss.getSupportedCRS_WCS(format_function=crss.asShortCode)) if native_crs in all_crss: all_crss.remove(native_crs) # setting the coverages CRS as the first one is important! all_crss.insert(0, native_crs) supported_crss = " ".join(all_crss) layer.setMetaData("ows_srs", supported_crss) layer.setMetaData("wcs_srs", supported_crss) for band in bands: ms.setMetaData(layer, { "band_description": band.description, "band_definition": band.definition, "band_uom": band.unit_of_measure, }, namespace=band.identifier) if band.allowed_values: interval = band.allowed_values[0] else: interval = gdal.GDT_NUMERIC_LIMITS[band.data_type] # For MS WCS 1.x interface ms.setMetaData(layer, { "label": band.identifier, "interval": "%d %d" % interval }, namespace="wcs_%s" % band.identifier) if bands[0].nil_values: nilvalues, nilvalues_reasons = zip( *[[nv[0], nv[1]] for nv in bands[0].nil_values]) if nilvalues: ms.setMetaData(layer, { "nilvalues": " ".join(nilvalues), "nilvalues_reasons": " ".join(nilvalues_reasons) }, namespace="wcs") return layer