Ejemplo n.º 1
0
def layer_v1tov2(session, layer):
    from c2cgeoportal_commons.models.main import OGCServer, LayerWMS, LayerWMTS, \
        LayergroupTreeitem, Dimension

    if layer.layer_type in ["internal WMS", "external WMS"]:
        # use the first one
        new_layer = LayerWMS()
        is_single_tile = layer.is_single_tile
        if is_single_tile is None:
            is_single_tile = False
        image_type = "image/png"
        if layer.layer_type == "internal WMS":
            url = "config://internal/mapserv"
        else:
            if layer.image_type is not None:
                image_type = layer.image_type
            url = layer.url
        ogc_server = session.query(OGCServer).filter(
            OGCServer.url == url,
            OGCServer.image_type == image_type,
            OGCServer.is_single_tile == is_single_tile
        ).one()

        new_layer.ogc_server = ogc_server

        new_layer.layer = layer.layer
        new_layer.style = layer.style
        new_layer.time_mode = layer.time_mode
        new_layer.time_widget = layer.time_widget
    elif layer.layer_type == "WMTS":
        new_layer = LayerWMTS()

        new_layer.url = layer.url
        new_layer.layer = layer.layer
        new_layer.style = layer.style
        new_layer.matrix_set = layer.matrix_set
        new_layer.image_type = layer.image_type or "image/png"

        if layer.dimensions is not None:
            dimensions = loads(layer.dimensions)
            for name, value in list(dimensions.items()):
                session.add(Dimension(name, value, new_layer))

    new_layer.name = layer.name
    new_layer.public = layer.public
    new_layer.geo_table = layer.geo_table
    new_layer.interfaces = layer.interfaces
    new_layer.restrictionareas = layer.restrictionareas

    for link in layer.parents_relation:
        new_link = LayergroupTreeitem()
        new_link.ordering = link.ordering
        new_link.description = link.description
        new_link.treegroup = link.treegroup
        new_link.treeitem = new_layer

    layer_add_metadata(layer, new_layer, session)

    session.add(new_layer)
Ejemplo n.º 2
0
def factory_build_layers(layer_builder, dbsession, add_dimension=True):
    from c2cgeoportal_commons.models.main import \
        RestrictionArea, LayergroupTreeitem, \
        Interface, Dimension, Metadata, LayerGroup

    restrictionareas = [RestrictionArea(name='restrictionarea_{}'.format(i))
                        for i in range(0, 5)]

    interfaces = [Interface(name) for name in ['desktop', 'mobile', 'edit', 'routing']]

    dimensions_protos = [('Date', '2017'),
                         ('Date', '2018'),
                         ('Date', '1988'),
                         ('CLC', 'all'), ]

    metadatas_protos = [('copyable', 'true'),
                        ('disclaimer', '© le momo'),
                        ('snappingConfig', '{"tolerance": 50}')]

    groups = [LayerGroup(name='layer_group_{}'.format(i)) for i in range(0, 5)]

    layers = []
    for i in range(0, 25):

        layer = layer_builder(i)

        if add_dimension:
            layer.dimensions = [Dimension(name=dimensions_protos[id][0],
                                          value=dimensions_protos[id][1],
                                          layer=layer)
                                for id in [i % 3, (i + 2) % 4, (i + 3) % 4]]

        layer.metadatas = [Metadata(name=metadatas_protos[id][0],
                                    value=metadatas_protos[id][1])
                           for id in [i % 3, (i + 2) % 3]]
        for metadata in layer.metadatas:
            metadata.item = layer

        if i % 10 != 1:
                layer.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]]

        layer.restrictionareas = [restrictionareas[i % 5], restrictionareas[(i + 2) % 5]]

        dbsession.add(LayergroupTreeitem(group=groups[i % 5],
                                         item=layer,
                                         ordering=len(groups[i % 5].children_relation)))
        dbsession.add(LayergroupTreeitem(group=groups[(i + 3) % 5],
                                         item=layer,
                                         ordering=len(groups[(i + 3) % 5].children_relation)))

        dbsession.add(layer)
        layers.append(layer)
    return {
        'restrictionareas': restrictionareas,
        'layers': layers,
        'interfaces': interfaces
    }
Ejemplo n.º 3
0
 def save(self):
     response = super().save()
     # correctly handles the validation error as if there is a validation error, cstruct is empty
     has_to_be_registred_in_parent = (hasattr(self, '_appstruct') and
                                      self._appstruct is not None and
                                      self._appstruct.get('parent_id'))
     if has_to_be_registred_in_parent:
         parent = self._request.dbsession.query(TreeGroup).get(has_to_be_registred_in_parent)
         rel = LayergroupTreeitem(parent, self._obj, 100)
         self._request.dbsession.add(rel)
     return response
Ejemplo n.º 4
0
def layer_v1tov2(session, layer):
    from c2cgeoportal_commons.models.main import OGCServer, LayerWMS, LayerWMTS, \
        LayergroupTreeitem, Dimension

    if layer.layer_type in ["internal WMS", "external WMS"]:
        # use the first one
        new_layer = LayerWMS()
        is_single_tile = layer.is_single_tile
        if is_single_tile is None:
            is_single_tile = False
        image_type = "image/png"
        if layer.layer_type == "internal WMS":
            url = "config://internal/mapserv"
        else:
            if layer.image_type is not None:
                image_type = layer.image_type
            url = layer.url
        ogc_server = session.query(OGCServer).filter(
            OGCServer.url == url, OGCServer.image_type == image_type,
            OGCServer.is_single_tile == is_single_tile).one()

        new_layer.ogc_server = ogc_server

        new_layer.layer = layer.layer
        new_layer.style = layer.style
        new_layer.time_mode = layer.time_mode
        new_layer.time_widget = layer.time_widget
    elif layer.layer_type == "WMTS":
        new_layer = LayerWMTS()

        new_layer.url = layer.url
        new_layer.layer = layer.layer
        new_layer.style = layer.style
        new_layer.matrix_set = layer.matrix_set
        new_layer.image_type = layer.image_type or "image/png"

        if layer.dimensions is not None:
            dimensions = loads(layer.dimensions)
            for name, value in list(dimensions.items()):
                session.add(Dimension(name, value, new_layer))

    new_layer.name = layer.name
    new_layer.public = layer.public
    new_layer.geo_table = layer.geo_table
    new_layer.interfaces = layer.interfaces
    new_layer.restrictionareas = layer.restrictionareas

    for link in layer.parents_relation:
        new_link = LayergroupTreeitem()
        new_link.ordering = link.ordering
        new_link.description = link.description
        new_link.treegroup = link.treegroup
        new_link.treeitem = new_layer

    layer_add_metadata(layer, new_layer, session)

    session.add(new_layer)
Ejemplo n.º 5
0
 def add_relation(parent_idx, child_idx):
     dbsession.add(LayergroupTreeitem(group=groups[parent_idx],
                                      item=groups[child_idx],
                                      ordering=len(group.children_relation)))
Ejemplo n.º 6
0
def theme_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import \
        Theme, Role, Functionality, LayergroupTreeitem, \
        Interface, Metadata, LayerGroup, LayerWMS, OGCServer

    interfaces = [
        Interface(name) for name in ['desktop', 'mobile', 'edit', 'routing']
    ]

    groups = [LayerGroup(name='layer_group_{}'.format(i)) for i in range(0, 5)]

    layer = LayerWMS(name='layer_wms')
    layer.ogc_server = OGCServer(name='server')
    dbsession.add(layer)
    layers = [layer]

    functionalities = [
        Functionality(name=name, value='value_{}'.format(v))
        for name in ('default_basemap', 'location') for v in range(0, 4)
    ]

    roles = [Role('secretary_' + str(i)) for i in range(0, 4)]

    metadatas_protos = [('copyable', 'true'), ('disclaimer', '© le momo'),
                        ('snappingConfig', '{"tolerance": 50}')]
    themes = []
    for i in range(0, 25):
        theme = Theme(name='theme_{}'.format(i),
                      ordering=1,
                      icon='icon_{}'.format(i))
        theme.public = 1 == i % 2
        theme.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]]
        theme.metadatas = [
            Metadata(name=metadatas_protos[id][0],
                     value=metadatas_protos[id][1])
            for id in [i % 3, (i + 2) % 3]
        ]
        for metadata in theme.metadatas:
            metadata.item = theme
        theme.functionalities = [
            functionalities[i % 8], functionalities[(i + 3) % 8]
        ]
        theme.restricted_roles = [roles[i % 4], roles[(i + 2) % 4]]

        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[i % 5],
                               ordering=len(groups[i % 5].children_relation)))
        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[(i + 3) % 5],
                               ordering=len(groups[(i + 3) %
                                                   5].children_relation)))

        dbsession.add(theme)
        themes.append(theme)

    dbsession.flush()

    yield {
        'themes': themes,
        'interfaces': interfaces,
        'groups': groups,
        'layers': layers,
        'functionalities': functionalities,
        'roles': roles,
    }
Ejemplo n.º 7
0
def theme_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import (
        Functionality,
        Interface,
        LayerGroup,
        LayergroupTreeitem,
        LayerWMS,
        Metadata,
        OGCServer,
        Role,
        Theme,
    )

    interfaces = [
        Interface(name) for name in ["desktop", "mobile", "edit", "routing"]
    ]

    groups = [LayerGroup(name="layer_group_{}".format(i)) for i in range(0, 5)]

    layer = LayerWMS(name="layer_wms")
    layer.ogc_server = OGCServer(name="server")
    dbsession.add(layer)
    layers = [layer]

    functionalities = [
        Functionality(name=name, value="value_{}".format(v))
        for name in ("default_basemap", "location") for v in range(0, 4)
    ]

    roles = [Role("secretary_" + str(i)) for i in range(0, 4)]

    metadatas_protos = [
        ("copyable", "true"),
        ("disclaimer", "© le momo"),
        ("snappingConfig", '{"tolerance": 50}'),
    ]
    themes = []
    for i in range(0, 25):
        theme = Theme(name="theme_{}".format(i),
                      ordering=1,
                      icon="icon_{}".format(i))
        theme.public = 1 == i % 2
        theme.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]]
        theme.metadatas = [
            Metadata(name=metadatas_protos[id][0],
                     value=metadatas_protos[id][1])
            for id in [i % 3, (i + 2) % 3]
        ]
        for metadata in theme.metadatas:
            metadata.item = theme
        theme.functionalities = [
            functionalities[i % 8], functionalities[(i + 3) % 8]
        ]
        theme.restricted_roles = [roles[i % 4], roles[(i + 2) % 4]]

        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[i % 5],
                               ordering=len(groups[i % 5].children_relation)))
        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[(i + 3) % 5],
                               ordering=len(groups[(i + 3) %
                                                   5].children_relation)))

        dbsession.add(theme)
        themes.append(theme)

    dbsession.flush()

    yield {
        "themes": themes,
        "interfaces": interfaces,
        "groups": groups,
        "layers": layers,
        "functionalities": functionalities,
        "roles": roles,
    }
Ejemplo n.º 8
0
def layertree_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import (
        LayerGroup,
        LayergroupTreeitem,
        LayerWMS,
        LayerWMTS,
        OGCServer,
        Theme,
    )

    layers_wms = []
    ogc_server = OGCServer(name="ogc_server")
    dbsession.add(ogc_server)
    for i in range(0, 10):
        layer_wms = LayerWMS(name="layer_wms_{}".format(i))
        layer_wms.ogc_server = ogc_server
        layers_wms.append(layer_wms)
        dbsession.add(layer_wms)

    layers_wmts = []
    for i in range(0, 10):
        layer_wmts = LayerWMTS(name="layer_wmts_{}".format(i))
        layer_wmts.url = "http://localhost/wmts"
        layer_wmts.layer = layer_wmts.name
        layers_wmts.append(layer_wmts)
        dbsession.add(layer_wmts)

    groups = []
    for i in range(0, 10):
        group = LayerGroup(name="layer_group_{}".format(i))
        groups.append(group)
        dbsession.add(group)

        for j, items in enumerate((layers_wms, layers_wmts)):
            dbsession.add(LayergroupTreeitem(group=group, item=items[i], ordering=j))

    # a group in a group
    dbsession.add(LayergroupTreeitem(group=groups[9], item=groups[8], ordering=3))

    themes = []
    for i in range(0, 5):
        theme = Theme(name="theme_{}".format(i))
        themes.append(theme)
        dbsession.add(theme)

        dbsession.add(LayergroupTreeitem(group=theme, item=groups[i], ordering=0))
        dbsession.add(LayergroupTreeitem(group=theme, item=groups[i + 5], ordering=1))

    themes[0].ordering = 1
    themes[3].ordering = 2
    themes[1].ordering = 3
    themes[2].ordering = 4
    themes[4].ordering = 5

    dbsession.flush()

    yield (
        {
            "themes": themes,
            "groups": groups,
            "layers_wms": layers_wms,
            "layers_wmts": layers_wmts,
            "ogc_servers": [ogc_server],
        }
    )
Ejemplo n.º 9
0
def factory_build_layers(layer_builder, dbsession, add_dimension=True):
    from c2cgeoportal_commons.models.main import (
        Dimension,
        Interface,
        LayerGroup,
        LayergroupTreeitem,
        Metadata,
        RestrictionArea,
    )

    restrictionareas = [
        RestrictionArea(name=f"restrictionarea_{i}") for i in range(0, 5)
    ]

    interfaces = [
        Interface(name) for name in ["desktop", "mobile", "edit", "routing"]
    ]

    dimensions_protos = [("Date", "2017"), ("Date", "2018"), ("Date", "1988"),
                         ("CLC", "all")]

    metadatas_protos = [
        ("copyable", "true"),
        ("disclaimer", "© le momo"),
        ("snappingConfig", '{"tolerance": 50}'),
    ]

    groups = [LayerGroup(name=f"layer_group_{i}") for i in range(0, 5)]

    layers = []
    for i in range(0, 25):

        layer = layer_builder(i)

        if add_dimension:
            layer.dimensions = [
                Dimension(name=dimensions_protos[id][0],
                          value=dimensions_protos[id][1],
                          layer=layer)
                for id in [i % 3, (i + 2) % 4, (i + 3) % 4]
            ]

        layer.metadatas = [
            Metadata(name=metadatas_protos[id][0],
                     value=metadatas_protos[id][1])
            for id in [i % 3, (i + 2) % 3]
        ]
        for metadata in layer.metadatas:
            metadata.item = layer

        if i % 10 != 1:
            layer.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]]

        layer.restrictionareas = [
            restrictionareas[i % 5], restrictionareas[(i + 2) % 5]
        ]

        dbsession.add(
            LayergroupTreeitem(group=groups[i % 5],
                               item=layer,
                               ordering=len(groups[i % 5].children_relation)))
        dbsession.add(
            LayergroupTreeitem(group=groups[(i + 3) % 5],
                               item=layer,
                               ordering=len(groups[(i + 3) %
                                                   5].children_relation)))

        dbsession.add(layer)
        layers.append(layer)
    return {
        "restrictionareas": restrictionareas,
        "layers": layers,
        "interfaces": interfaces
    }