Skip to content

Commit

Permalink
Merge pull request #211 from geopython/issue-210
Browse files Browse the repository at this point in the history
improve ISO import and OARec contact output
  • Loading branch information
tomkralidis committed Feb 20, 2023
2 parents 716ab0e + 9315c9e commit 69e4b99
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
python3 -m pip install --upgrade pip
pip3 install "pyproj < 3.3.0"
pip3 install -r requirements-dev.txt
pip3 install -U https://github.com/geopython/OWSLib/archive/master.zip
- name: Install package 📦
run: python3 setup.py install
- name: run tests ⚙️
Expand Down
62 changes: 33 additions & 29 deletions pygeometa/schemas/iso19139/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,58 +99,62 @@ def import_(self, metadata: str) -> dict:
mcf['metadata']['hierarchylevel'] = m.hierarchy
mcf['metadata']['datestamp'] = m.datestamp

LOGGER.debug('Setting language')
if m.language:
mcf['metadata']['language'] = m.language
elif m.languagecode:
mcf['metadata']['language'] = m.languagecode

identification = m.identificationinfo[0]

LOGGER.debug('Setting identification')
mcf['identification']['title'] = m.identification.title
mcf['identification']['abstract'] = m.identification.abstract
mcf['identification']['title'] = identification.title
mcf['identification']['abstract'] = identification.abstract

if m.identification.date:
if identification.date:
mcf['identification']['dates'] = {}
for date_ in m.identification.date:
for date_ in identification.date:
mcf['identification']['dates'][date_.type] = date_.date

if m.identification.keywords2:
if identification.keywords:
mcf['identification']['keywords'] = {}
for count, value in enumerate(m.identification.keywords2):
for count, value in enumerate(identification.keywords):
key = f'keywords-{count}'
mcf['identification']['keywords'][key] = {
'type': value.type,
'keywords': value.keywords
'keywords': [k.name for k in value.keywords]
}
mcf['identification']['topiccategory'] = m.identification.topiccategory # noqa
mcf['identification']['topiccategory'] = identification.topiccategory # noqa

mcf['identification']['extents'] = {
'spatial': [{
'bbox': [
ast.literal_eval(m.identification.extent.boundingBox.minx),
ast.literal_eval(m.identification.extent.boundingBox.miny),
ast.literal_eval(m.identification.extent.boundingBox.maxx),
ast.literal_eval(m.identification.extent.boundingBox.maxy)
ast.literal_eval(identification.extent.boundingBox.minx),
ast.literal_eval(identification.extent.boundingBox.miny),
ast.literal_eval(identification.extent.boundingBox.maxx),
ast.literal_eval(identification.extent.boundingBox.maxy)
]
}],
'temporal': []
}

temp_extent = {}
if m.identification.temporalextent_start:
temp_extent['begin'] = m.identification.temporalextent_start
if m.identification.temporalextent_end:
temp_extent['end'] = m.identification.temporalextent_end
if identification.temporalextent_start:
temp_extent['begin'] = identification.temporalextent_start
if identification.temporalextent_end:
temp_extent['end'] = identification.temporalextent_end

mcf['identification']['extents']['temporal'].append(temp_extent)

if m.identification.accessconstraints:
mcf['identification']['accessconstraints'] = m.identification.accessconstraints[0] # noqa

mcf['identification']['status'] = m.identification.status
if identification.accessconstraints:
mcf['identification']['accessconstraints'] = identification.accessconstraints[0] # noqa

LOGGER.debug('Setting contact')
if m.contact:
for c in m.contact:
mcf['contact'].update(get_contact(c))
mcf['identification']['status'] = identification.status

if m.distribution.distributor:
for d in m.distribution.distributor:
mcf['contact'].update(get_contact(d.contact))
LOGGER.debug('Setting contacts')
# for contact in m.get_all_contacts():
# mcf['contact'].update(get_contact(contact))
mcf['contact'].update(get_contact(m.contact[0]))

LOGGER.debug('Setting distribution')
if m.distribution:
Expand All @@ -173,8 +177,8 @@ def get_contact(contact: CI_ResponsibleParty) -> dict:
mcf_contact = {contact.role: {}}

cm_lookup = {
'name': 'name',
'organization': 'organization',
'individualname': 'name',
'positionname': 'position',
'phone': 'phone',
'fax': 'fax',
Expand All @@ -187,7 +191,7 @@ def get_contact(contact: CI_ResponsibleParty) -> dict:
}

for key, value in cm_lookup.items():
if hasattr(contact, value):
if getattr(contact, value) is not None:
mcf_contact[contact.role][key] = getattr(contact, value)

if hasattr(contact.onlineresource, 'url'):
Expand Down
21 changes: 11 additions & 10 deletions pygeometa/schemas/ogcapi_records/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,20 @@ def generate_responsible_party(self, contact: dict,
country = get_charstring(contact.get('country'),
self.lang1, self.lang2)

rp = {
'name': organization_name[0],
'individual': contact['individualname'],
rp = {}

if organization_name[0] == contact.get('organization'):
LOGGER.debug('Contact name is organization')
rp['name'] = organization_name[0]

rp.update({
'positionName': position_name[0],
'contactInfo': {
'phone': {
'office': contact['phone']
'office': contact.get('phone')
},
'email': {
'office': contact['fax']
'office': contact.get('email')
},
'address': {
'office': {
Expand All @@ -262,18 +266,15 @@ def generate_responsible_party(self, contact: dict,
'administrativeArea': administrative_area[0],
'postalCode': postalcode[0],
'country': country[0]
},
'onlineResource': {
'href': contact['url']
},
}
},
'hoursOfService': hours_of_service[0],
'contactInstructions': contact_instructions[0]
},
'roles': [{
'name': role
}]
}
})

if 'url' in contact:
rp['contactInfo']['url'] = {
Expand Down

0 comments on commit 69e4b99

Please sign in to comment.