diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index ab703c68df92ceb0cfac62695352b950bd353031..a41383ed4ea02c685ebcaeabc721a7bb2040ed28 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -4,6 +4,7 @@ import ast import ckan.plugins.toolkit as toolkit import ckan.logic as logic import ckan.model as model +import json from ckan.common import c get_action = logic.get_action @@ -46,3 +47,43 @@ def odsh_get_resource_views(pkg_dict, resource): return get_action('resource_view_list')( context, {'id': resource['id']}) +def odsh_get_bounding_box(pkg_dict): + try: + extras=pkg_dict.get('extras') + spatial=None + for f in extras: + if 'key' in f and f['key'] == 'spatial': + spatial=f['value'] + break + + if spatial is not None: + d = json.loads(spatial) + if 'coordinates' in d: + coords=d['coordinates'] + return compute_bounding_box(coords) + except Exception, e: + log.error('Error while bounding box %s: %s\nException: %s', + e.__class__.__name__, unicode(e), traceback.format_exc()) + return None + +def compute_bounding_box(coords): + if len(coords)==0: + return None + + coords = [c for sublist in coords for c in sublist] + + minx = min(coords, key = lambda t: t[0])[0] + maxx = max(coords, key = lambda t: t[0])[0] + miny = min(coords, key = lambda t: t[1])[1] + maxy = max(coords, key = lambda t: t[1])[1] + + return [maxx, minx, maxy, miny] + +def odsh_get_spatial_text(pkg_dict): + extras=pkg_dict.get('extras') + spatial=None + for f in extras: + if 'key' in f and f['key'] == 'spatial_text': + spatial=f['value'] + return spatial + return None \ No newline at end of file diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo index 1c1591e99aaf2584f0359eebf5b23e51f151bf71..ea33e500d2dfdaca01704f6b45d3afa93cdd7058 100644 Binary files a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo and b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo differ diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po index 204d8feeea2f01ee2567e5c37014341fc5b80090..15630acb997dd6a9f5110d937d07656a47488f18 100644 --- a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po +++ b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po @@ -243,3 +243,21 @@ msgstr "zurücksetzen" msgid "There is no description for this organization" msgstr "Es gibt keine Beschreibung für diesen Herausgeber" + +msgid "in east" +msgstr "im Osten" + +msgid "in west" +msgstr "im Westen" + +msgid "in north" +msgstr "im Norden" + +msgid "in south" +msgstr "im Süden" + +msgid "borders of map" +msgstr "Grenzen der Karte" + +msgid "Map showing the borders of {map_text}" +msgstr "Karte, die die Grenzen von {map_text} zeigt" \ No newline at end of file diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 5370eb1a161c9bc18b1ae15ffa82e3927a1e03e0..bdcdaeea858ea0e93bde9da4421d92eaca610ca6 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -83,7 +83,6 @@ def known_spatial_uri(key, data, errors, context): spatial_text = row[1] loaded = json.loads(row[2]) spatial = json.dumps(loaded['geometry']) - print spatial break if not_found: raise toolkit.Invalid("The specified URI is not known") @@ -133,7 +132,9 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'odsh_get_facet_items_dict': odsh_get_facet_items_dict, 'odsh_openness_score_dataset_html': odsh_helpers.odsh_openness_score_dataset_html, 'odsh_get_resource_details': odsh_helpers.odsh_get_resource_details, - 'odsh_get_resource_views': odsh_helpers.odsh_get_resource_views + 'odsh_get_resource_views': odsh_helpers.odsh_get_resource_views, + 'odsh_get_bounding_box': odsh_helpers.odsh_get_bounding_box, + 'odsh_get_spatial_text': odsh_helpers.odsh_get_spatial_text } def before_map(self, map): @@ -199,7 +200,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'groups': _('Kategorie')}) def _fields(self): - # return ['title','notes','tag_string'] return ['title','notes'] def _extraFields(self): @@ -223,13 +223,9 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm toolkit.get_converter('convert_to_extras')]}) for field in self._fields(): schema.update({field: [toolkit.get_converter('not_empty')]}) - # schema.update({ 'groups': [ - # # toolkit.get_converter('not_empty'), - # toolkit.get_converter('odsh_convert_groups_string')] }) + schema['resources'].update({ 'url' : [ toolkit.get_converter('not_empty') ] - # 'description' : [ toolkit.get_converter('not_empty') ], - # 'name' : [ toolkit.get_converter('not_empty') ] }) def create_package_schema(self): diff --git a/ckanext/odsh/public/odsh.css b/ckanext/odsh/public/odsh.css index c9f40b66254e881007881e005aec6867a662a1e1..abdb5c6a83f24a3f45c9c5335da4ea189f4a96d4 100644 --- a/ckanext/odsh/public/odsh.css +++ b/ckanext/odsh/public/odsh.css @@ -814,7 +814,13 @@ body { max-width: 193px; word-break: break-all; } - +.info-detail p{ + margin: 0; +} +.info-detail .map-text{ + margin-top: 5px; + margin-bottom: 5px; +} .odsh-dataset-heading { margin-bottom: 30px; } diff --git a/ckanext/odsh/templates/package/read_base.html b/ckanext/odsh/templates/package/read_base.html index 4cf4dc023b9ede84efaf6ef44bcde5a06e4f7d46..ef23352acc68178e54e53c100ea2134f0933164a 100644 --- a/ckanext/odsh/templates/package/read_base.html +++ b/ckanext/odsh/templates/package/read_base.html @@ -33,6 +33,26 @@ {% if dataset_extent %} {% snippet "spatial/snippets/dataset_map_sidebar.html", extent=dataset_extent %} {% endif %} +{% block spatial_info %} +{% set map_text = h.odsh_get_spatial_text(pkg) %} +<div class="spatial-detail info-detail"> + <div>{{ _('Spatial uri') }}:</div> + {%set ext=map_text if map_text else '-'%} + <p>{{ ext }}</p> +</div> + +<div class="info-detail"> + <p class='map-text'> {{_('Map showing the borders of {map_text}').format(map_text=map_text)}} </p> + {% set bbox = h.odsh_get_bounding_box(pkg) %} + {% if bbox%} + <div>{{ _('borders of map') }}:</div> + <p> {{ '{0:0.3f}'.format(bbox[0]).zfill(2).replace('.',',') }}° {{_('in east')}}</p> + <p> {{ '{0:0.3f}'.format(bbox[1]).replace('.',',') }}° {{_('in west')}}</p> + <p> {{ '{0:0.3f}'.format(bbox[2]).replace('.',',') }}° {{_('in south')}}</p> + <p> {{ '{0:0.3f}'.format(bbox[3]).replace('.',',') }}° {{_('in north')}}</p> + {% endif %} +</div> +{% endblock %} {% endblock %} {% endblock %} \ No newline at end of file diff --git a/ckanext/odsh/templates/package/snippets/info.html b/ckanext/odsh/templates/package/snippets/info.html index 46fadc1c2a901152c452eee6c9b350fd7af145da..df9121e8d8634b839cc777e2181ed20d31063839 100644 --- a/ckanext/odsh/templates/package/snippets/info.html +++ b/ckanext/odsh/templates/package/snippets/info.html @@ -33,14 +33,6 @@ Example: {% block nums %} {% endblock %} - {% block spatial %} - <div class="spatial-detail info-detail"> - <div>{{ _('Spatial uri') }}:</div> - {%set ext=pkg.spatial_uri if pkg.spatial_uri else '-'%} - <p>{{ ext }}</p> - </div> - {% endblock %} - {% block tags %} <div class="tags-detail info-detail"> <div>{{ _('Tags') }}:</div>