Exemplo n.º 1
0
 def layer_group(self):
     """
     Returns layer group name from local OWS for this map instance.
     """
     if 'geonode.geoserver' in settings.INSTALLED_APPS:
         from geonode.geoserver.helpers import gs_catalog
         lg_name = '%s_%d' % (slugify(self.title), self.id)
         return gs_catalog.get_layergroup(lg_name)
     else:
         return None
Exemplo n.º 2
0
 def layer_group(self):
     """
     Returns layer group name from local OWS for this map instance.
     """
     if 'geonode.geoserver' in settings.INSTALLED_APPS:
         from geonode.geoserver.helpers import gs_catalog
         lg_name = '%s_%d' % (slugify(self.title), self.id)
         return gs_catalog.get_layergroup(lg_name)
     else:
         return None
Exemplo n.º 3
0
    def dataset_group(self):
        """
        Returns layer group name from local OWS for this map instance.
        """
        if check_ogc_backend(geoserver.BACKEND_PACKAGE):
            from geonode.geoserver.helpers import gs_catalog, ogc_server_settings

            lg_name = f"{slugify(self.title)}_{self.id}"
            try:
                return {"catalog": gs_catalog.get_layergroup(lg_name), "ows": ogc_server_settings.ows}
            except Exception:
                return {"catalog": None, "ows": ogc_server_settings.ows}
        else:
            return None
Exemplo n.º 4
0
 def layer_group(self):
     """
     Returns layer group name from local OWS for this map instance.
     """
     if check_ogc_backend(geoserver.BACKEND_PACKAGE):
         from geonode.geoserver.helpers import gs_catalog, ogc_server_settings
         lg_name = '%s_%d' % (slugify(self.title), self.id)
         try:
             return {
                 'catalog': gs_catalog.get_layergroup(lg_name),
                 'ows': ogc_server_settings.ows
             }
         except BaseException:
             return {'catalog': None, 'ows': ogc_server_settings.ows}
     else:
         return None
Exemplo n.º 5
0
 def layer_group(self):
     """
     Returns layer group name from local OWS for this map instance.
     """
     if 'geonode.geoserver' in settings.INSTALLED_APPS:
         from geonode.geoserver.helpers import gs_catalog, ogc_server_settings
         lg_name = '%s_%d' % (slugify(self.title), self.id)
         try:
             return {
                 'catalog': gs_catalog.get_layergroup(lg_name),
                 'ows': ogc_server_settings.ows
             }
         except:
             return {'catalog': None, 'ows': ogc_server_settings.ows}
     else:
         return None
Exemplo n.º 6
0
 def layer_group(self):
     """
     Returns layer group name from local OWS for this map instance.
     """
     if 'geonode.geoserver' in settings.INSTALLED_APPS:
         from geonode.geoserver.helpers import gs_catalog, ogc_server_settings
         lg_name = '%s_%d' % (slugify(self.title), self.id)
         try:
             return {
                 'catalog': gs_catalog.get_layergroup(lg_name),
                 'ows': ogc_server_settings.ows
             }
         except:
             return {
                 'catalog': None,
                 'ows': ogc_server_settings.ows
             }
     else:
         return None
Exemplo n.º 7
0
 def layer_group(self):
     """
     Returns layer group name from local OWS for this map instance.
     """
     if check_ogc_backend(geoserver.BACKEND_PACKAGE):
         from geonode.geoserver.helpers import gs_catalog, ogc_server_settings
         lg_name = '%s_%d' % (slugify(self.title), self.id)
         try:
             return {
                 'catalog': gs_catalog.get_layergroup(lg_name),
                 'ows': ogc_server_settings.ows
             }
         except BaseException:
             return {
                 'catalog': None,
                 'ows': ogc_server_settings.ows
             }
     else:
         return None
Exemplo n.º 8
0
def geoserver_pre_save(instance, sender, **kwargs):
    """Send information to geoserver.

       The attributes sent include:

        * Title
        * Abstract
        * Name
        * Keywords
        * Metadata Links,
        * Point of Contact name and url
    """

    # Don't run this signal handler if it is a tile layer or a remote store (Service)
    #    Currently only gpkg files containing tiles will have this type & will be served via MapProxy.
    if hasattr(instance, 'storeType') and getattr(
            instance, 'storeType') in ['tileStore', 'remoteStore']:
        return

    gs_resource = None

    # If the store in None then it's a new instance from an upload,
    # only in this case run the geonode_uplaod method
    if not instance.store or getattr(instance, 'overwrite', False):
        base_file, info = instance.get_base_file()

        # There is no need to process it if there is not file.
        if base_file is None:
            return
        gs_name, workspace, values, gs_resource = geoserver_upload(
            instance,
            base_file.file.path,
            instance.owner,
            instance.name,
            overwrite=True,
            title=instance.title,
            abstract=instance.abstract,
            # keywords=instance.keywords,
            charset=instance.charset)
        # Set fields obtained via the geoserver upload.
        instance.name = gs_name
        instance.workspace = workspace
        # Iterate over values from geoserver.
        for key in ['typename', 'store', 'storeType']:
            setattr(instance, key, values[key])

    if not gs_resource:
        gs_resource = gs_catalog.get_resource(instance.name,
                                              store=instance.store,
                                              workspace=instance.workspace)

    if gs_resource:
        gs_resource.title = instance.title if instance.title else ""
        gs_resource.abstract = instance.abstract if instance.abstract else ""
        gs_resource.name = instance.name if instance.name else ""

    # Get metadata links
    metadata_links = []
    for link in instance.link_set.metadata():
        metadata_links.append((link.mime, link.name, link.url))

    if gs_resource:
        gs_resource.metadata_links = metadata_links
    # gs_resource should only be called if
    # ogc_server_settings.BACKEND_WRITE_ENABLED == True
    if gs_resource and getattr(ogc_server_settings, "BACKEND_WRITE_ENABLED",
                               True):
        gs_catalog.save(gs_resource)

    if instance.storeType and instance.storeType == 'layerGroup':
        gs_layer = gs_catalog.get_layergroup(name=instance.name,
                                             workspace=instance.workspace)
    else:
        gs_layer = gs_catalog.get_layer(instance.name)

    if instance.poc and instance.poc:
        # gsconfig now utilizes an attribution dictionary
        gs_layer.attribution = {
            'title': str(instance.poc),
            'width': None,
            'height': None,
            'href': None,
            'url': None,
            'type': None
        }
        profile = Profile.objects.get(username=instance.poc.username)
        gs_layer.attribution_link = settings.SITEURL[:
                                                     -1] + profile.get_absolute_url(
                                                     )
        # gs_layer should only be called if
        # ogc_server_settings.BACKEND_WRITE_ENABLED == True
        if getattr(ogc_server_settings, "BACKEND_WRITE_ENABLED", True):
            try:
                # Some geogig layers will return a 500 on save
                gs_catalog.save(gs_layer)
            except geoserver.catalog.FailedRequestError:
                pass
    """Get information from geoserver.

       The attributes retrieved include:

       * Bounding Box
       * SRID
       * Download links (WMS, WCS or WFS and KML)
       * Styles (SLD)
    """

    if gs_resource:
        bbox = gs_resource.latlon_bbox

        # FIXME(Ariel): Correct srid setting below
        # self.srid = gs_resource.src

        instance.srid_url = "http://www.spatialreference.org/ref/" + \
            instance.srid.replace(':', '/').lower() + "/"

        # Set bounding box values
        instance.bbox_x0 = bbox[0]
        instance.bbox_x1 = bbox[1]
        instance.bbox_y0 = bbox[2]
        instance.bbox_y1 = bbox[3]

        # store the resource to avoid another geoserver call in the post_save
        instance.gs_resource = gs_resource
Exemplo n.º 9
0
def geoserver_pre_save(instance, sender, **kwargs):
    """Send information to geoserver.

       The attributes sent include:

        * Title
        * Abstract
        * Name
        * Keywords
        * Metadata Links,
        * Point of Contact name and url
    """

    # Don't run this signal handler if it is a tile layer or a remote store (Service)
    #    Currently only gpkg files containing tiles will have this type & will be served via MapProxy.
    if hasattr(instance, 'storeType') and getattr(instance, 'storeType') in ['tileStore', 'remoteStore']:
        return

    gs_resource = None

    # If the store in None then it's a new instance from an upload,
    # only in this case run the geonode_uplaod method
    if not instance.store or getattr(instance, 'overwrite', False):
        base_file, info = instance.get_base_file()

        # There is no need to process it if there is not file.
        if base_file is None:
            return
        gs_name, workspace, values, gs_resource = geoserver_upload(instance,
                                                                   base_file.file.path,
                                                                   instance.owner,
                                                                   instance.name,
                                                                   overwrite=True,
                                                                   title=instance.title,
                                                                   abstract=instance.abstract,
                                                                   # keywords=instance.keywords,
                                                                   charset=instance.charset)
        # Set fields obtained via the geoserver upload.
        instance.name = gs_name
        instance.workspace = workspace
        # Iterate over values from geoserver.
        for key in ['typename', 'store', 'storeType']:
            setattr(instance, key, values[key])

    if not gs_resource:
        gs_resource = gs_catalog.get_resource(
            instance.name,
            store=instance.store,
            workspace=instance.workspace)

    if gs_resource:
        gs_resource.title = instance.title if instance.title else ""
        gs_resource.abstract = instance.abstract if instance.abstract else ""
        gs_resource.name = instance.name if instance.name else ""

    # Get metadata links
    metadata_links = []
    for link in instance.link_set.metadata():
        metadata_links.append((link.mime, link.name, link.url))

    if gs_resource:
        gs_resource.metadata_links = metadata_links
    # gs_resource should only be called if
    # ogc_server_settings.BACKEND_WRITE_ENABLED == True
    if gs_resource and getattr(ogc_server_settings, "BACKEND_WRITE_ENABLED", True):
        gs_catalog.save(gs_resource)

    if instance.storeType and instance.storeType == 'layerGroup':
        gs_layer = gs_catalog.get_layergroup(name=instance.name, workspace=instance.workspace)
    else:
        gs_layer = gs_catalog.get_layer(instance.name)


    if instance.poc and instance.poc:
        # gsconfig now utilizes an attribution dictionary
        gs_layer.attribution = {'title': str(instance.poc),
                                'width': None,
                                'height': None,
                                'href': None,
                                'url': None,
                                'type': None}
        profile = Profile.objects.get(username=instance.poc.username)
        gs_layer.attribution_link = settings.SITEURL[
            :-1] + profile.get_absolute_url()
        # gs_layer should only be called if
        # ogc_server_settings.BACKEND_WRITE_ENABLED == True
        if getattr(ogc_server_settings, "BACKEND_WRITE_ENABLED", True):
            try:
                # Some geogig layers will return a 500 on save
                gs_catalog.save(gs_layer)
            except geoserver.catalog.FailedRequestError:
                pass

    """Get information from geoserver.

       The attributes retrieved include:

       * Bounding Box
       * SRID
       * Download links (WMS, WCS or WFS and KML)
       * Styles (SLD)
    """

    if gs_resource:
        bbox = gs_resource.latlon_bbox

        # FIXME(Ariel): Correct srid setting below
        # self.srid = gs_resource.src

        instance.srid_url = "http://www.spatialreference.org/ref/" + \
            instance.srid.replace(':', '/').lower() + "/"

        # Set bounding box values
        instance.bbox_x0 = bbox[0]
        instance.bbox_x1 = bbox[1]
        instance.bbox_y0 = bbox[2]
        instance.bbox_y1 = bbox[3]

        # store the resource to avoid another geoserver call in the post_save
        instance.gs_resource = gs_resource