From 692f04568f16829096320ccb7e9c20106af69252 Mon Sep 17 00:00:00 2001 From: amercader Date: Wed, 15 May 2013 16:41:36 +0100 Subject: [PATCH] [#19] Extract thumbnail from ISO documents --- ckanext/spatial/harvesters/base.py | 11 ++++++ ckanext/spatial/model/harvested_metadata.py | 38 ++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/ckanext/spatial/harvesters/base.py b/ckanext/spatial/harvesters/base.py index 112e3e7..5006b66 100644 --- a/ckanext/spatial/harvesters/base.py +++ b/ckanext/spatial/harvesters/base.py @@ -259,6 +259,17 @@ class SpatialHarvester(HarvesterBase): extras['access_constraints'] = iso_values.get('limitations-on-public-access', '') + # Grpahic preview + browse_graphic = iso_values.get('browse-graphic') + if browse_graphic: + browse_graphic = browse_graphic[0] + extras['graphic-preview-file'] = browse_graphic.get('file') + if browse_graphic.get('description'): + extras['graphic-preview-description'] = browse_graphic.get('description') + if browse_graphic.get('type'): + extras['graphic-preview-type'] = browse_graphic.get('type') + + for key in ['temporal-extent-begin', 'temporal-extent-end']: if len(iso_values[key]) > 0: extras[key] = iso_values[key][0] diff --git a/ckanext/spatial/model/harvested_metadata.py b/ckanext/spatial/model/harvested_metadata.py index a505c4e..86700c5 100644 --- a/ckanext/spatial/model/harvested_metadata.py +++ b/ckanext/spatial/model/harvested_metadata.py @@ -344,6 +344,33 @@ class ISOBoundingBox(ISOElement): ), ] +class ISOBrowseGraphic(ISOElement): + + elements = [ + ISOElement( + name="file", + search_paths=[ + "gmd:fileName/gco:CharacterString/text()", + ], + multiplicity="1", + ), + ISOElement( + name="description", + search_paths=[ + "gmd:fileDescription/gco:CharacterString/text()", + ], + multiplicity="0..1", + ), + ISOElement( + name="type", + search_paths=[ + "gmd:fileType/gco:CharacterString/text()", + ], + multiplicity="0..1", + ), + ] + + class ISODocument(MappedXmlDocument): # Attribute specifications from "XPaths for GEMINI" by Peter Parslow. @@ -651,7 +678,16 @@ class ISODocument(MappedXmlDocument): "gmd:dataQualityInfo/gmd:DQ_DataQuality/gmd:lineage/gmd:LI_Lineage/gmd:statement/gco:CharacterString/text()", ], multiplicity="0..1", - ) + ), + ISOBrowseGraphic( + name="browse-graphic", + search_paths=[ + "gmd:identificationInfo/gmd:MD_DataIdentification/gmd:graphicOverview/gmd:MD_BrowseGraphic", + "gmd:identificationInfo/srv:SV_ServiceIdentification/gmd:graphicOverview/gmd:MD_BrowseGraphic", + ], + multiplicity="*", + ), + ] def infer_values(self, values):