-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom XML field to parse mv_mtaw fields.
- Loading branch information
Showing
9 changed files
with
143 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import numpy as np | ||
|
||
from pydov.types.fields import _CustomXmlField | ||
|
||
|
||
class MvMtawField(_CustomXmlField): | ||
"""Field for retrieving the mv_mtaw value from the height of the point in | ||
relavant cases.""" | ||
|
||
def __init__(self, definition): | ||
"""Initialise a MvMtawField (mv_mtaw) with given definition. | ||
Parameters | ||
---------- | ||
definition : string | ||
Type-specific definition of the mv_mtaw field. | ||
""" | ||
super().__init__( | ||
name='mv_mtaw', | ||
definition=definition, | ||
datatype='float', | ||
notnull=False | ||
) | ||
|
||
def calculate(self, cls, tree): | ||
# Support the old format too | ||
oorspronkelijk_maaiveld = cls._parse( | ||
func=tree.findtext, | ||
xpath='.//oorspronkelijk_maaiveld/waarde', | ||
namespace=None, | ||
returntype='float' | ||
) | ||
if oorspronkelijk_maaiveld is not np.nan: | ||
return oorspronkelijk_maaiveld | ||
|
||
# Check if referentiepunt is Maaiveld | ||
referentiepunt = cls._parse( | ||
func=tree.findtext, | ||
xpath='.//ligging/metadata_hoogtebepaling/referentiepunt_type', | ||
namespace=None, | ||
returntype='string' | ||
) | ||
if referentiepunt != 'Maaiveld': | ||
# If referentiepunt is not Maaiveld, we don't know the height of | ||
# maaiveld | ||
return np.nan | ||
|
||
# If referentiepunt is Maaiveld, height of the ligging is Maaiveld | ||
point = tree.findtext( | ||
'.//ligging/{http://www.opengis.net/gml/3.2}Point/' | ||
'{http://www.opengis.net/gml/3.2}pos' | ||
) | ||
hoogte = float(point.split(' ')[-1]) | ||
return hoogte |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters