def save_vector_layer(self, *args, **kwargs): """Synchronizer la couche de données vectorielle avec le service OGC via MRA.""" organisation = self.resource.dataset.organisation ws_name = organisation.slug ds_name = 'public' if self.pk: try: Layer.objects.get(pk=self.pk) except Layer.DoesNotExist: pass else: # On vérifie si l'organisation du jeu de données a changée, # auquel cas il est nécessaire de supprimer les objets MRA # afin de les recréer dans le bon workspace (c-à-d Mapfile). previous_layer = MRAHandler.get_layer(self.name) regex = '/workspaces/(?P<ws_name>[a-z_\-]+)/datastores/' matched = re.search(regex, previous_layer['resource']['href']) if matched: previous_ws_name = matched.group('ws_name') if not ws_name == previous_ws_name: MRAHandler.del_layer(self.name) MRAHandler.del_featuretype(previous_ws_name, ds_name, self.name) MRAHandler.get_or_create_workspace(organisation) MRAHandler.get_or_create_datastore(ws_name, ds_name) MRAHandler.get_or_create_featuretype( ws_name, ds_name, self.name, enabled=True, title=self.resource.title, abstract=self.resource.description)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) organisation = self.resource.dataset.organisation ws_name = organisation.slug try: l = MRAHandler.get_layer(self.name) except MraBaseError: return # Récupération des informations de couche vecteur # =============================================== if self.type == 'vector': try: ft = MRAHandler.get_featuretype(ws_name, 'public', self.name) except MraBaseError: return if not l or not ft: return ll = ft['featureType']['latLonBoundingBox'] bbox = [[ll['miny'], ll['minx']], [ll['maxy'], ll['maxx']]] attributes = [ item['name'] for item in ft['featureType']['attributes'] ] default_style_name = l['defaultStyle']['name'] styles = [{ 'name': 'default', 'text': 'Style par défaut', 'url': l['defaultStyle']['href'].replace('json', 'sld'), 'sld': MRAHandler.get_style(l['defaultStyle']['name']) }] if l.get('styles'): for style in l.get('styles')['style']: styles.append({ 'name': style['name'], 'text': style['name'], 'url': style['href'].replace('json', 'sld'), 'sld': MRAHandler.get_style(style['name']) }) # Récupération des informations de couche raster # ============================================== elif self.type == 'raster': try: c = MRAHandler.get_coverage(ws_name, self.name, self.name) except MraBaseError: return if not l or not c: return ll = c['coverage']['latLonBoundingBox'] bbox = [[ll['miny'], ll['minx']], [ll['maxy'], ll['maxx']]] attributes = [] default_style_name = None styles = [] # Puis.. self.mra_info = { 'name': l['name'], 'title': l['title'], 'type': l['type'], 'enabled': l['enabled'], 'abstract': l['abstract'], 'bbox': bbox, 'attributes': attributes, 'styles': { 'default': default_style_name, 'styles': styles } }
def get_default_sld(self): style = MRAHandler.get_layer(self.name)['defaultStyle'] if style: return MRAHandler.get_style(style['name'])