Skip to content
Snippets Groups Projects
Commit edf65ddc authored by anonymous's avatar anonymous
Browse files

ODPSH-137: add bounding box to info page

parent 0476f0bf
No related branches found
No related tags found
No related merge requests found
......@@ -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
No preview for this file type
......@@ -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
......@@ -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):
......
......@@ -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;
}
......
......@@ -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
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment