Skip to content

Commit

Permalink
[Fixes #4827] Line layer uploaded to GeoNode is rendered as point layer
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Oct 22, 2019
1 parent 2d22554 commit 5fd8c2a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
14 changes: 8 additions & 6 deletions geonode/catalogue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ def catalogue_post_save(instance, sender, **kwargs):
else:
raise err

msg = ('Metadata record for %s does not exist,'
' check the catalogue signals.' % instance.title)
assert record is not None, msg
if not record:
msg = ('Metadata record for %s does not exist,'
' check the catalogue signals.' % instance.title)
raise Exception(msg)

msg = ('Metadata record for %s should contain links.' % instance.title)
assert hasattr(record, 'links'), msg
if not hasattr(record, 'links'):
msg = ('Metadata record for %s should contain links.' % instance.title)
raise Exception(msg)

# Create the different metadata links with the available formats
for mime, name, metadata_url in record.links['metadata']:
Expand Down Expand Up @@ -110,7 +112,7 @@ def catalogue_post_save(instance, sender, **kwargs):
resources.update(csw_wkt_geometry=csw_wkt_geometry)
resources.update(csw_anytext=csw_anytext)
except BaseException as e:
LOGGER.exception(e)
LOGGER.debug(e)
finally:
# Revert temporarily changed publishing state
if not is_published:
Expand Down
52 changes: 35 additions & 17 deletions geonode/geoserver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,30 +237,48 @@ def extract_name_from_sld(gs_catalog, sld, sld_file=None):


def get_sld_for(gs_catalog, layer):
# GeoServer sometimes fails to associate a style with the data, so
# for now we default to using a point style.(it works for lines and
# polygons, hope this doesn't happen for rasters though)
name = None
gs_layer = None
_default_style = None
try:
_default_style = layer.default_style
except BaseException:
traceback.print_exc()
pass
gs_style = None
_default_style = layer.default_style if layer else None

try:
gs_catalog._cache.clear()
gs_layer = gs_catalog.get_layer(layer.name)
except BaseException:
traceback.print_exc()
if _default_style is None:
_max_retries, _tries = getattr(ogc_server_settings, "MAX_RETRIES", 5), 0
try:
name = gs_layer.default_style.name if gs_layer.default_style is not None else "raster"
gs_layer = gs_catalog.get_layer(layer.name)
if gs_layer.default_style:
gs_style = gs_layer.default_style.sld_body
set_layer_style(layer,
layer.alternate,
gs_style)
name = gs_layer.default_style.name
except BaseException:
traceback.print_exc()
name = None
while not name and _tries < _max_retries:
try:
gs_layer = gs_catalog.get_layer(layer.name)
if gs_layer.default_style:
gs_style = gs_layer.default_style.sld_body
set_layer_style(layer,
layer.alternate,
gs_style)
name = gs_layer.default_style.name
if name:
break
except BaseException:
name = None
_tries += 1
time.sleep(3)
else:
name = _default_style.name
gs_style = _default_style.sld_body

if not name:
msg = """
GeoServer didn't return a default style for this layer.
Consider increasing OGC_SERVER MAX_RETRIES value.''
"""
raise GeoNodeException(msg)

# Detect geometry type if it is a FeatureType
res = gs_layer.resource if gs_layer else None
Expand Down Expand Up @@ -289,7 +307,7 @@ def get_sld_for(gs_catalog, layer):
bg=bg,
mark=mark)
else:
return None
return gs_style


def fixup_style(cat, resource, style):
Expand Down

0 comments on commit 5fd8c2a

Please sign in to comment.