Skip to content

Commit

Permalink
Move scale_denominator inside new spatial_resolution metadata property
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Aug 3, 2021
1 parent 42aa2a6 commit 60b9ebf
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 53 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
- Fix: Raise error when more than one main layer file is sent in [POST Workspace Layers](doc/rest.md#post-workspace-layers) or [PATCH Workspace Layer](doc/rest.md#patch-workspace-layer).
- Fix [#408](https://github.com/LayerManager/layman/issues/408) Skip non WMS layers in thumbnail generation. Previously thumbnail generation failed.
- Fix [GET Workspace Layer](doc/rest.md#get-workspace-layer) documentation, where was incorrectly `style` item instead of `sld`.
- New metadata property [`spatial_resolution`](doc/metadata.md#spatial_resolution) is available.
- Metadata property `scale_denominator` was removed. It's value is now accessible as subproperty of new [`spatial_resolution`](doc/metadata.md#spatial_resolution) metadata property.
## v1.13.2
2021-06-25
Expand Down Expand Up @@ -370,7 +372,7 @@ There is a critical bug in this release, posting new layer breaks Layman: https:
- Guess metadata properties
- [`md_language`](doc/metadata.md#md_language) of both Layer and Map using pycld2 library
- [`language`](doc/metadata.md#language) of Layer using pycld2 library
- [`scale_denominator`](doc/metadata.md#scale_denominator) of Layer using distanced between vertices
- [`scale_denominator`](doc/metadata.md#spatial_resolution) of Layer using distanced between vertices
- Change multiplicity of [`language`](doc/metadata.md#language) metadata property from `1` to `1..n` according to XML Schema
- Remove [`language`](doc/metadata.md#language) metadata property from Map according to XML Schema
- Build Layman as a part of `make start-demo*` commands.
Expand Down
17 changes: 11 additions & 6 deletions doc/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,23 @@ XPath for Layer: `/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentificat
XPath for Map: `/gmd:MD_Metadata/gmd:identificationInfo/srv:SV_ServiceIdentification/gmd:citation/gmd:CI_Citation/gmd:date[gmd:CI_Date/gmd:dateType/gmd:CI_DateTypeCode[@codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode" and @codeListValue="revision"]]/gmd:CI_Date/gmd:date/gco:Date/text()`


### scale_denominator
Guessed from distances between vertices of line and polygon features.

### spatial_resolution
Multiplicity: 1

Shape: Integer
Shape: Object with one of following keys:
- *scale_denominator*: Integer. Scale denominator, used for vector data, guessed from distances between vertices of line and polygon features.

Example: `25000`
Example:
```json5
// Spatial resolution of vector data:
{
"scale_denominator": 10000
}
```

Synchronizable: yes

XPath for Layer: `/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:spatialResolution/gmd:MD_Resolution/gmd:equivalentScale/gmd:MD_RepresentativeFraction/gmd:denominator/gco:Integer/text()`
XPath for Layer: `/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:spatialResolution`


### title
Expand Down
2 changes: 1 addition & 1 deletion src/layman/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def extent_equals(ext1, ext2):
'graphic_url': {
'upper_mp': '1',
},
'scale_denominator': {
'spatial_resolution': {
'upper_mp': '1',
},
'language': {
Expand Down
38 changes: 38 additions & 0 deletions src/layman/common/micka/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,44 @@ def adjust_operates_on(prop_el, prop_value):
_add_unknown_reason(prop_el)


def extract_spatial_resolution(prop_els):
scale_denominator = None
if prop_els:
prop_el = prop_els[0]
scale_strings = prop_el.xpath('./gmd:MD_Resolution/gmd:equivalentScale/gmd:MD_RepresentativeFraction/'
'gmd:denominator/gco:Integer/text()', namespaces=NAMESPACES)
scale_denominator = int(scale_strings[0]) if scale_strings else None
result = {}
if scale_denominator:
result['scale_denominator'] = scale_denominator
result = result or None
return result


def adjust_spatial_resolution(prop_el, prop_value):
_clear_el(prop_el)
child_el = None
if prop_value is not None:
parser = ET.XMLParser(remove_blank_text=True)
scale_denominator = prop_value.get('scale_denominator')
if scale_denominator is not None:
child_el = ET.fromstring(f"""
<gmd:MD_Resolution xmlns:gmd="{NAMESPACES['gmd']}" xmlns:gco="{NAMESPACES['gco']}">
<gmd:equivalentScale>
<gmd:MD_RepresentativeFraction>
<gmd:denominator>
<gco:Integer>{str(scale_denominator)}</gco:Integer>
</gmd:denominator>
</gmd:MD_RepresentativeFraction>
</gmd:equivalentScale>
</gmd:MD_Resolution>
""", parser=parser)
if child_el:
prop_el.append(child_el)
else:
_add_unknown_reason(prop_el)


def get_record_element_by_id(csw, ident):
csw.getrecordbyid(id=[ident], esn='full', outputschema=NAMESPACES['gmd'])
xml = csw._exml # pylint: disable=protected-access
Expand Down
2 changes: 1 addition & 1 deletion src/layman/layer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_layer_info_keys(file_type):
'language',
'revision_date',
'reference_system',
'scale_denominator',
'spatial_resolution',
'title',
'wfs_url',
'wms_url',
Expand Down
19 changes: 11 additions & 8 deletions src/layman/layer/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ def _get_property_values(
west, south, east, north = extent or [11.87, 48.12, 19.13, 51.59]
extent = [max(west, -180), max(south, -90), min(east, 180), min(north, 90)]
languages = languages or []
spatial_resolution = {
'scale_denominator': scale_denominator,
} if scale_denominator else None

result = {
'md_file_identifier': get_metadata_uuid(uuid),
Expand All @@ -220,7 +223,7 @@ def _get_property_values(
'wms_url': f"{wms.add_capabilities_params_to_url(wms_url)}&LAYERS={layername}",
'wfs_url': f"{wfs.add_capabilities_params_to_url(wfs_url)}&LAYERS={layername}",
'layer_endpoint': url_for('rest_workspace_layer.get', workspace=workspace, layername=layername),
'scale_denominator': scale_denominator,
'spatial_resolution': spatial_resolution,
'language': languages,
'md_organisation_name': md_organisation_name,
'organisation_name': organisation_name,
Expand Down Expand Up @@ -317,12 +320,12 @@ def _get_property_values(
'xpath_extract_fn': lambda l: l[0] if l else None,
'adjust_property_element': common_util.adjust_graphic_url,
},
'scale_denominator': {
'xpath_parent': '/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:spatialResolution/gmd:MD_Resolution/gmd:equivalentScale/gmd:MD_RepresentativeFraction',
'xpath_property': './gmd:denominator',
'xpath_extract': './gco:Integer/text()',
'xpath_extract_fn': lambda l: int(l[0]) if l else None,
'adjust_property_element': common_util.adjust_integer,
'spatial_resolution': {
'xpath_parent': '/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification',
'xpath_property': './gmd:spatialResolution',
'xpath_extract': '.',
'xpath_extract_fn': common_util.extract_spatial_resolution,
'adjust_property_element': common_util.adjust_spatial_resolution,
},
'language': {
'xpath_parent': '/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification',
Expand Down Expand Up @@ -390,7 +393,7 @@ def get_metadata_comparison(workspace, layername):
'publication_date',
'revision_date',
'reference_system',
'scale_denominator',
'spatial_resolution',
'title',
'wfs_url',
'wms_url',
Expand Down
10 changes: 1 addition & 9 deletions src/layman/layer/micka/record-template-filled.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,7 @@
<gmd:spatialRepresentationType>
<gmd:MD_SpatialRepresentationTypeCode codeListValue="vector" codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_SpatialRepresentationTypeCode">vector</gmd:MD_SpatialRepresentationTypeCode>
</gmd:spatialRepresentationType>
<gmd:spatialResolution>
<gmd:MD_Resolution>
<gmd:equivalentScale>
<gmd:MD_RepresentativeFraction>
<gmd:denominator gco:nilReason="unknown"/>
</gmd:MD_RepresentativeFraction>
</gmd:equivalentScale>
</gmd:MD_Resolution>
</gmd:spatialResolution>
<gmd:spatialResolution gco:nilReason="unknown"/>
<gmd:language>
<gmd:LanguageCode codeListValue="cze" codeList="http://www.loc.gov/standards/iso639-2/">cze</gmd:LanguageCode>
</gmd:language>
Expand Down
10 changes: 1 addition & 9 deletions src/layman/layer/micka/record-template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,7 @@ xsi:schemaLocation="http://www.isotc211.org/2005/gmd http://schemas.opengis.net/
<gmd:MD_SpatialRepresentationTypeCode codeListValue="vector" codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_SpatialRepresentationTypeCode">vector</gmd:MD_SpatialRepresentationTypeCode>
</gmd:spatialRepresentationType>

<gmd:spatialResolution>
<gmd:MD_Resolution>
<gmd:equivalentScale>
<gmd:MD_RepresentativeFraction>
<gmd:denominator gco:nilReason="unknown" />
</gmd:MD_RepresentativeFraction>
</gmd:equivalentScale>
</gmd:MD_Resolution>
</gmd:spatialResolution>
<gmd:spatialResolution gco:nilReason="unknown" />

<gmd:language gco:nilReason="unknown" />

Expand Down
6 changes: 3 additions & 3 deletions src/layman/layer/micka/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_parse_md_properties():
'organisation_name',
'publication_date',
'reference_system',
'scale_denominator',
'spatial_resolution',
'title',
'wfs_url',
'wms_url',
Expand All @@ -79,7 +79,7 @@ def test_parse_md_properties():
'md_date_stamp': '2007-05-25',
'md_organisation_name': None,
'organisation_name': None,
'scale_denominator': None,
'spatial_resolution': None,
'language': [],
'reference_system': [4326, 3857],
'title': 'CORINE - Krajinný pokryv CLC 90',
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_fill_xml_template():
'abstract': None,
'organisation_name': 'My Organization',
'graphic_url': 'https://example.com/myimage.png',
'scale_denominator': None,
'spatial_resolution': None,
'language': ['cze', 'eng'],
'extent': [11.87, 48.12, 19.13, 51.59],
'wms_url': 'https://example.com/wms',
Expand Down
10 changes: 1 addition & 9 deletions src/layman/layer/micka/util_test_filled_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,7 @@
<gmd:spatialRepresentationType>
<gmd:MD_SpatialRepresentationTypeCode codeListValue="vector" codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_SpatialRepresentationTypeCode">vector</gmd:MD_SpatialRepresentationTypeCode>
</gmd:spatialRepresentationType>
<gmd:spatialResolution>
<gmd:MD_Resolution>
<gmd:equivalentScale>
<gmd:MD_RepresentativeFraction>
<gmd:denominator gco:nilReason="unknown"/>
</gmd:MD_RepresentativeFraction>
</gmd:equivalentScale>
</gmd:MD_Resolution>
</gmd:spatialResolution>
<gmd:spatialResolution gco:nilReason="unknown"/>
<gmd:language gco:nilReason="unknown"/>
<gmd:characterSet>
<gmd:MD_CharacterSetCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_CharacterSetCode" codeListValue="utf8">utf8</gmd:MD_CharacterSetCode>
Expand Down
22 changes: 16 additions & 6 deletions src/layman/layer/rest_workspace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
'publication_date',
'reference_system',
'revision_date',
'scale_denominator',
'spatial_resolution',
'title',
'wfs_url',
'wms_url',
Expand Down Expand Up @@ -336,7 +336,9 @@ def test_post_layers_simple(client):
'publication_date': TODAY_DATE,
'reference_system': [3857, 4326, 5514],
'revision_date': None,
'scale_denominator': 100000000,
'spatial_resolution': {
'scale_denominator': 100000000,
},
'title': 'ne_110m_admin_0_countries',
}
check_metadata(client, username, layername, METADATA_PROPERTIES_EQUAL, expected_md_values)
Expand Down Expand Up @@ -587,7 +589,9 @@ def test_post_layers_complex(client):
'publication_date': TODAY_DATE,
'reference_system': [3857, 4326, 5514],
'revision_date': None,
'scale_denominator': 100000000,
'spatial_resolution': {
'scale_denominator': 100000000,
},
'title': "staty",
}
check_metadata(client, username, layername, METADATA_PROPERTIES_EQUAL, expected_md_values)
Expand Down Expand Up @@ -742,7 +746,9 @@ def test_patch_layer_title(client):
'publication_date': TODAY_DATE,
'reference_system': [3857, 4326, 5514],
'revision_date': TODAY_DATE,
'scale_denominator': 100000000,
'spatial_resolution': {
'scale_denominator': 100000000,
},
'title': "New Title of Countries",
}
check_metadata(client, username, layername, METADATA_PROPERTIES_EQUAL, expected_md_values)
Expand Down Expand Up @@ -807,7 +813,9 @@ def test_patch_layer_style(client):
'publication_date': TODAY_DATE,
'reference_system': [3857, 4326, 5514],
'revision_date': TODAY_DATE,
'scale_denominator': 100000000,
'spatial_resolution': {
'scale_denominator': 100000000,
},
'title': 'countries in blue',
}
check_metadata(client, username, layername, METADATA_PROPERTIES_EQUAL, expected_md_values)
Expand Down Expand Up @@ -952,7 +960,9 @@ def test_patch_layer_data(client):
'publication_date': TODAY_DATE,
'reference_system': [3857, 4326, 5514],
'revision_date': TODAY_DATE,
'scale_denominator': None,
'spatial_resolution': {
'scale_denominator': 100000000
},
'title': 'populated places',
}
check_metadata(client, username, layername, METADATA_PROPERTIES_EQUAL, expected_md_values)
Expand Down

0 comments on commit 60b9ebf

Please sign in to comment.