Skip to content

Commit

Permalink
[Fixes #4827] Line layer uploaded to GeoNode is rendered as point lay…
Browse files Browse the repository at this point in the history
…er (#5116)
  • Loading branch information
Alessio Fabiani authored and capooti committed Oct 25, 2019
1 parent a863217 commit 9f4009c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
4 changes: 4 additions & 0 deletions geonode/geoserver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,9 @@ def decimal_encode(bbox):
thumbnail_create_url = request_body['thumbnail_create_url']
elif 'layers' in request_body:
layers = request_body['layers']
styles = ''
if 'styles' in request_body:
styles = request_body['styles']

ogc_server_location = request_body["ogc_server_location"] if "ogc_server_location" \
in request_body else ogc_server_settings.LOCATION
Expand All @@ -2054,6 +2057,7 @@ def decimal_encode(bbox):
'version': wms_version,
'request': 'GetMap',
'layers': layers.replace(' ', '+'),
'styles': styles,
'format': wms_format,
# 'TIME': '-99999999999-01-01T00:00:00.0Z/99999999999-01-01T00:00:00.0Z'
}
Expand Down
57 changes: 55 additions & 2 deletions geonode/geoserver/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@
from guardian.shortcuts import assign_perm, remove_perm

from geonode import geoserver
from geonode import GeoNodeException
from geonode.decorators import on_ogc_backend
from geonode.geoserver.helpers import OGC_Servers_Handler, extract_name_from_sld

from geonode.layers.models import Layer, Style
from geonode.layers.populate_layers_data import create_layer_data
from geonode.layers.models import Layer
from geonode.layers.utils import create_gs_thumbnail_geonode
from geonode.geoserver.helpers import (
gs_catalog,
get_sld_for,
OGC_Servers_Handler,
extract_name_from_sld,
create_gs_thumbnail,
_prepare_thumbnail_body_from_opts)

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -974,6 +983,23 @@ def test_ogc_server_defaults(self):
height = 512
width = 512

# Default Style (expect exception since we are offline)
style = None
with self.assertRaises(GeoNodeException):
style = get_sld_for(gs_catalog, instance)
self.assertIsNone(style)
style = gs_catalog.get_style("line")
self.assertIsNotNone(style)
instance.default_style, _ = Style.objects.get_or_create(
name=style.name,
defaults=dict(
sld_title=style.sld_title,
sld_body=style.sld_body
)
)
self.assertIsNotNone(instance.default_style)
self.assertIsNotNone(instance.default_style.name)

# WMS Links
wms_links = wms_links(ogc_settings.public_url + 'wms?',
instance.alternate.encode('utf-8'),
Expand Down Expand Up @@ -1021,6 +1047,33 @@ def test_ogc_server_defaults(self):
logger.debug('%s --> %s' % (identifier, _link[3]))
self.assertTrue(identifier in _link[3])

# Thumbnails Generation Default
create_gs_thumbnail(instance, overwrite=True)
self.assertIsNotNone(instance.get_thumbnail_url())

# Thumbnails Generation Through "remote url"
create_gs_thumbnail_geonode(instance, overwrite=True, check_bbox=True)

# Thumbnails Generation Through "image"
request_body = {
'width': width,
'height': height,
'layers': instance.alternate
}
if hasattr(instance, 'default_style'):
if instance.default_style:
request_body['styles'] = instance.default_style.name
self.assertIsNotNone(request_body['styles'])

try:
image = _prepare_thumbnail_body_from_opts(request_body)
except BaseException as e:
logger.exception(e)
image = None
# We are offline here, the layer does not exists in GeoServer
# - we expect the image is None
self.assertIsNone(image)

@on_ogc_backend(geoserver.BACKEND_PACKAGE)
def test_importer_configuration(self):
database_settings = self.DATABASE_DEFAULT_SETTINGS.copy()
Expand Down
2 changes: 1 addition & 1 deletion geonode/layers/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def test_layer_links(self):

links = Link.objects.filter(resource=lyr.resourcebase_ptr, link_type="image")
self.assertIsNotNone(links)
self.assertEquals(len(links), 9)
self.assertEquals(len(links), 8)

def test_get_valid_user(self):
# Verify it accepts an admin user
Expand Down
8 changes: 8 additions & 0 deletions geonode/layers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,10 @@ def create_thumbnail(instance, thumbnail_remote_url, thumbnail_create_url=None,
elif instance.alternate:
request_body['layers'] = instance.alternate

if hasattr(instance, 'default_style'):
if instance.default_style:
request_body['styles'] = instance.default_style.name

try:
image = _prepare_thumbnail_body_from_opts(request_body)
except BaseException:
Expand All @@ -994,6 +998,10 @@ def create_thumbnail(instance, thumbnail_remote_url, thumbnail_create_url=None,
params['bbox'] = instance.bbox_string
params['crs'] = instance.srid

if hasattr(instance, 'default_style'):
if instance.default_style:
params['styles'] = instance.default_style.name

for _p in params.keys():
if _p.lower() not in thumbnail_create_url.lower():
thumbnail_create_url = thumbnail_create_url + '&%s=%s' % (_p, params[_p])
Expand Down

0 comments on commit 9f4009c

Please sign in to comment.