Skip to content

Commit e2b193c

Browse files
author
Matt Bertrand
committed
Enhancements to base processor class for adding description and category to geonode layer; create style only if it doesn't already exist
1 parent d7a7ce4 commit e2b193c

1 file changed

Lines changed: 34 additions & 23 deletions

File tree

dataqs/processor_base.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
validate\ connections=true
5656
Connection\ timeout=10
5757
preparedStatements=true
58+
TypeNames=false
5859
"""
5960

6061
GPMOSAIC_TIME_REGEX = "regex=[0-9]{8}T[0-9]{9}Z"
@@ -214,11 +215,15 @@ def update_gs_metadata(self, layer_name, json_data, vector=False,
214215
res.raise_for_status()
215216
return res.content
216217

217-
def update_geonode(self, layer_name, title="", bounds=None, store=None):
218+
def update_geonode(self, layer_name, title="", description="",
219+
category=None, bounds=None, store=None):
218220
"""
219221
Update a layer and it's title in GeoNode
220222
:param layer_name: Name of the layer
221-
:param title: New title for layer
223+
:param title: Title for layer
224+
:param description: Description for layer
225+
:param bounds: Bounds for layer
226+
:param store: Store for layer
222227
"""
223228
# Update the layer in GeoNode
224229
ulc = UpdateLayersCommand()
@@ -229,6 +234,9 @@ def update_geonode(self, layer_name, title="", bounds=None, store=None):
229234
from geonode.layers.models import Layer
230235
lyr = Layer.objects.get(typename='geonode:{}'.format(layer_name))
231236
lyr.title = title
237+
lyr.abstract = description
238+
if category:
239+
lyr.category = category
232240
lyr.save()
233241
if bounds:
234242
from geonode.layers.models import Layer
@@ -239,39 +247,42 @@ def update_geonode(self, layer_name, title="", bounds=None, store=None):
239247
gs_catalog = Catalog(url, _user, _password)
240248
gs_catalog.save(res)
241249

242-
def set_default_style(self, layer_name, sld_name, sld_content):
250+
def set_default_style(self, layer_name, sld_name, sld_content, create=True):
243251
"""
244252
Create a style and assign it as default to a layer
245253
:param layer_name: the layer to assign the style to
246254
:param sld_name: the name to give the style
247255
:param sld_content: the actual XML content for the style
256+
:param create: create the style if true
248257
:return: None
249258
"""
250-
gs_url = self.gs_style_url.format(ogc_server_settings.hostname)
251259

252-
# Create the style
253-
s = "<style><name>{name}</name><filename>{name}.sld</filename></style>"
254-
data = s.format(name=sld_name)
260+
gs_url = self.gs_style_url.format(ogc_server_settings.hostname)
255261
_user, _password = ogc_server_settings.credentials
256-
res = requests.post(url=gs_url,
257-
data=data,
258-
auth=(_user, _password),
259-
headers={'Content-Type': 'text/xml'})
260262

261-
res.raise_for_status()
263+
if create:
264+
# Create the style
265+
s = "<style><name>{n}</name><filename>{n}.sld</filename></style>"
266+
data = s.format(n=sld_name)
267+
res = requests.post(url=gs_url,
268+
data=data,
269+
auth=(_user, _password),
270+
headers={'Content-Type': 'text/xml'})
262271

263-
# Populate the style
264-
data = sld_content
265-
url = urljoin(gs_url, sld_name)
266-
logger.debug(url)
267-
res = requests.put(url=url,
268-
data=data,
269-
auth=(_user, _password),
270-
headers={
271-
'Content-Type': 'application/vnd.ogc.sld+xml'
272-
})
272+
res.raise_for_status()
273273

274-
res.raise_for_status()
274+
# Populate the style
275+
data = sld_content
276+
url = urljoin(gs_url, sld_name)
277+
logger.debug(url)
278+
res = requests.put(url=url,
279+
data=data,
280+
auth=(_user, _password),
281+
headers={
282+
'Content-Type': 'application/vnd.ogc.sld+xml'
283+
})
284+
285+
res.raise_for_status()
275286

276287
# Assign to the layer
277288
layer_typename = "{}%3A{}".format(DEFAULT_WORKSPACE, layer_name)

0 commit comments

Comments
 (0)