Skip to content

Commit

Permalink
made necessary changes to support reading URI code in reference syste…
Browse files Browse the repository at this point in the history
…m INSPIRE field
  • Loading branch information
smanousopoulos committed Jun 10, 2015
1 parent 31e8c90 commit df07be3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 51 deletions.
10 changes: 5 additions & 5 deletions ckanext/publicamundi/lib/metadata/schemata/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,20 @@ class IReferenceSystem(IObject):
title= u'Coordinate reference system',
description = u'',
vocabulary = vocabularies.get_by_name('reference-systems').get('vocabulary'),
default = '2100',
default = 'http://www.opengis.net/def/crs/EPSG/0/2100',
required = True)

code_space = zope.schema.NativeStringLine(
title = u'Reference System code-space',
description = u'',
default = 'urn:ogc:def:crs:EPSG',
required = True)
#default = 'urn:ogc:def:crs:EPSG',
required = False)

version = zope.schema.NativeStringLine(
title = u'Reference System version',
description = u'',
default = '6.11.2',
required = True)
#default = '6.11.2',
required = False)


class IConformity(IObject):
Expand Down
26 changes: 19 additions & 7 deletions ckanext/publicamundi/lib/metadata/types/inspire_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from lxml import etree
from owslib.iso import MD_Metadata

from ckan.plugins.toolkit import toolkit

from ckanext.publicamundi import reference_data
from ckanext.publicamundi.lib.metadata.base import Object, object_null_adapter
from ckanext.publicamundi.lib.metadata.schemata.inspire_metadata import IInspireMetadata
Expand All @@ -19,6 +21,7 @@
from ckanext.publicamundi.lib.metadata.types.thesaurus import Thesaurus, ThesaurusTerms
from ckanext.publicamundi.lib.metadata.types._common import *

_ = toolkit._
strptime = datetime.datetime.strptime

class KeywordsFactory(object):
Expand Down Expand Up @@ -273,9 +276,8 @@ def to_responsible_party(alist):
spatial_list = []

if len(md.identification.distance) != len(md.identification.uom):
raise Exception(
'Found unequal list lengths distance,uom (%s, %s)' % (
md.identification.distance,md.identification.uom))
raise Exception(_('Found unequal list lengths distance,uom (%s, %s)' % (
md.identification.distance,md.identification.uom)))
else:
for i in range(0,len(md.identification.distance)):
spatial_list.append(SpatialResolution(
Expand All @@ -291,16 +293,26 @@ def to_responsible_party(alist):
# code_space = md.referenceSystem.codeSpace
reference_system = None
if md.referencesystem:
reference_system = ReferenceSystem(code = md.referencesystem.code)

code = md.referencesystem.code
reference_systems = vocabularies.get_by_name('reference-systems').get('vocabulary')
if code in reference_systems:
# Check whether the URI is provided
reference_system = ReferenceSystem(code = code)
else:
# Check whether just the EPSG code suffix is provided
code_full = 'http://www.opengis.net/def/crs/EPSG/0/{code}'.format(code=code)
if code_full in reference_systems:
reference_system = ReferenceSystem(code = code_full)
else:
raise Exception(_('Reference system not recognizable'))
if md.referencesystem.codeSpace:
reference_system.code_space = md.referencesystem.codeSpace
if md.referencesystem.version:
reference_system.version = md.referencesystem.version

if len(md.dataquality.conformancedate) != len(md.dataquality.conformancedatetype):
# Date list is unequal to datetype list, this means wrong XML so exception is thrown
raise Exception('Found unequal list lengths: conformance date, conformancedatetype')
raise Exception(_('Found unequal list lengths: conformance date, conformancedatetype'))
if len(md.dataquality.conformancedegree) != len(md.dataquality.conformancedate):
# Degree list is unequal to date/datetype lists, so we are unable to conclude
# to which conformity item each degree value corresponds, so all are set to
Expand Down
48 changes: 24 additions & 24 deletions ckanext/publicamundi/reference_data/inspire-vocabularies.json
Original file line number Diff line number Diff line change
Expand Up @@ -1124,30 +1124,30 @@
},
"Reference Systems" : {
"terms" : {
"2100": "GGRS87",
"3857": "WGS84 Web Mercator",
"4326": "WGS84",
"4936": "ETRS89-XYZ",
"4937": "ETRS89-GRS80h",
"4258": "ETRS89-GRS80",
"3035": "ETRS89-LAEA",
"3034": "ETRS89-LCC",
"3038": "ETRS89-TM26N",
"3039": "ETRS89-TM27N",
"3040": "ETRS89-TM28N",
"3041": "ETRS89-TM29N",
"3042": "ETRS89-TM30N",
"3043": "ETRS89-TM31N",
"3044": "ETRS89-TM32N",
"3045": "ETRS89-TM33N",
"3056": "ETRS89-TM34N",
"3047": "ETRS89-TM35N",
"3048": "ETRS89-TM36N",
"3049": "ETRS89-TM37N",
"3050": "ETRS89-TM38N",
"3051": "ETRS89-TM39N",
"5730": "EVRS",
"7409": "ETRS89-GRS80-EVRS"
"http://www.opengis.net/def/crs/EPSG/0/2100": "GGRS87",
"http://www.opengis.net/def/crs/EPSG/0/3857": "WGS84 Web Mercator",
"http://www.opengis.net/def/crs/EPSG/0/4326": "WGS84",
"http://www.opengis.net/def/crs/EPSG/0/4936": "ETRS89-XYZ",
"http://www.opengis.net/def/crs/EPSG/0/4937": "ETRS89-GRS80h",
"http://www.opengis.net/def/crs/EPSG/0/4258": "ETRS89-GRS80",
"http://www.opengis.net/def/crs/EPSG/0/3035": "ETRS89-LAEA",
"http://www.opengis.net/def/crs/EPSG/0/3034": "ETRS89-LCC",
"http://www.opengis.net/def/crs/EPSG/0/3038": "ETRS89-TM26N",
"http://www.opengis.net/def/crs/EPSG/0/3039": "ETRS89-TM27N",
"http://www.opengis.net/def/crs/EPSG/0/3040": "ETRS89-TM28N",
"http://www.opengis.net/def/crs/EPSG/0/3041": "ETRS89-TM29N",
"http://www.opengis.net/def/crs/EPSG/0/3042": "ETRS89-TM30N",
"http://www.opengis.net/def/crs/EPSG/0/3043": "ETRS89-TM31N",
"http://www.opengis.net/def/crs/EPSG/0/3044": "ETRS89-TM32N",
"http://www.opengis.net/def/crs/EPSG/0/3045": "ETRS89-TM33N",
"http://www.opengis.net/def/crs/EPSG/0/3046": "ETRS89-TM34N",
"http://www.opengis.net/def/crs/EPSG/0/3047": "ETRS89-TM35N",
"http://www.opengis.net/def/crs/EPSG/0/3048": "ETRS89-TM36N",
"http://www.opengis.net/def/crs/EPSG/0/3049": "ETRS89-TM37N",
"http://www.opengis.net/def/crs/EPSG/0/3050": "ETRS89-TM38N",
"http://www.opengis.net/def/crs/EPSG/0/3051": "ETRS89-TM39N",
"http://www.opengis.net/def/crs/EPSG/0/5730": "EVRS",
"http://www.opengis.net/def/crs/EPSG/0/7409": "ETRS89-GRS80-EVRS"
}
}
}
4 changes: 4 additions & 0 deletions ckanext/publicamundi/templates/package/inspire_iso.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@
<gmd:code>
<gco:CharacterString>{{ data.reference_system.code }}</gco:CharacterString>
</gmd:code>
{% if data.reference_system.code_space %}
<gmd:codeSpace>
<gco:CharacterString>{{ data.reference_system.code_space }}</gco:CharacterString>
</gmd:codeSpace>
{% endif %}
{% if data.reference_system.version %}
<gmd:version>
<gco:CharacterString>{{ data.reference_system.version }}</gco:CharacterString>
</gmd:version>
{% endif %}
</gmd:RS_Identifier>
</gmd:referenceSystemIdentifier>
</gmd:MD_ReferenceSystem>
Expand Down
22 changes: 7 additions & 15 deletions ckanext/publicamundi/tests/test_inspire_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,13 @@ def test_sr6():
# Fixtures

# Find reference system non-existing code
rs1 = ReferenceSystem(code='210000')
rs1 = ReferenceSystem(code='2100')

# Find reference system unicode version error
rs2 = ReferenceSystem(code='2100', code_space ='CustomSpace', version=u'5:2')
# Find reference system codespace and version provided
rs2 = ReferenceSystem(code='http://www.opengis.net/def/crs/EPSG/0/2100', code_space ='CustomSpace', version='5')

# Reference system correct
rs4 = ReferenceSystem(code='3857', code_space='CustomSpace', version='123')

# Reference system correct
rs5 = ReferenceSystem(code='2100')
rs5 = ReferenceSystem(code='http://www.opengis.net/def/crs/EPSG/0/2100')

# Tests

Expand All @@ -310,18 +307,13 @@ def test_rs1():

def test_rs2():
''' Find reference system unicode version error'''
assert_faulty_keys(rs2,
expected_keys=set(['version']))

def test_rs_correct():
'''Reference system correct schema '''
assert_faulty_keys(rs4)
assert_faulty_keys(rs2)
assert rs2.code_space == 'CustomSpace'
assert rs2.version == '5'

def test_rs_correct_2():
'''Reference system correct schema '''
assert_faulty_keys(rs5)
assert rs1.code_space == 'urn:ogc:def:crs:EPSG'
assert rs1.version == '6.11.2'

#
# Main
Expand Down

1 comment on commit df07be3

@kalxas
Copy link

@kalxas kalxas commented on df07be3 Jun 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.