Skip to content

Commit

Permalink
Improving reading of metadata formats by using the better suited pars…
Browse files Browse the repository at this point in the history
…e_iso8601 function.
  • Loading branch information
constantinius committed Dec 12, 2014
1 parent 6223996 commit 92cf3e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#-------------------------------------------------------------------------------


from django.utils.dateparse import parse_date, parse_datetime
from eoxserver.core.util.timetools import parse_iso8601
from django.contrib.gis.geos import Polygon, MultiPolygon

from eoxserver.core import Component, implements
Expand Down Expand Up @@ -102,7 +102,7 @@ def cond_set(dct, key, value):


def parse_date_or_datetime_11(string):
value = parse_date(string) or parse_datetime(string)
value = parse_iso8601(string)
if not value:
raise Exception("Could not parse date or datetime from '%s'." % string)
return value
Expand All @@ -129,7 +129,7 @@ def parse_size_11(elem):

def parse_geotransform_11(elem):
values = (
elem.findtext("ULXMAP"), elem.findtext("XDIM"), 0,
elem.findtext("ULXMAP"), elem.findtext("XDIM"), 0,
elem.findtext("ULYMAP"), 0, elem.findtext("YDIM")
)
return map(float, values)
Expand Down
9 changes: 3 additions & 6 deletions eoxserver/resources/coverages/metadata/formats/eoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@
# THE SOFTWARE.
#-------------------------------------------------------------------------------


from lxml import etree

from django.utils.dateparse import parse_datetime
from django.contrib.gis.geos import Polygon, MultiPolygon

from eoxserver.core.util.timetools import parse_iso8601
from eoxserver.core.util.xmltools import parse, NameSpace, NameSpaceMap
from eoxserver.core.util.iteratortools import pairwise
from eoxserver.core import Component, implements
Expand Down Expand Up @@ -81,8 +78,8 @@ def parse_ring(string):

class EOOMFormatDecoder(xml.Decoder):
identifier = xml.Parameter("eop:metaDataProperty/eop:EarthObservationMetaData/eop:identifier/text()", type=str, num=1)
begin_time = xml.Parameter("om:phenomenonTime/gml:TimePeriod/gml:beginPosition/text()", type=parse_datetime, num=1)
end_time = xml.Parameter("om:phenomenonTime/gml:TimePeriod/gml:endPosition/text()", type=parse_datetime, num=1)
begin_time = xml.Parameter("om:phenomenonTime/gml:TimePeriod/gml:beginPosition/text()", type=parse_iso8601, num=1)
end_time = xml.Parameter("om:phenomenonTime/gml:TimePeriod/gml:endPosition/text()", type=parse_iso8601, num=1)
polygons = xml.Parameter("om:featureOfInterest/eop:Footprint/eop:multiExtentOf/gml:MultiSurface/gml:surfaceMember/gml:Polygon", type=parse_polygon_xml, num="+")

namespaces = nsmap
13 changes: 5 additions & 8 deletions eoxserver/resources/coverages/metadata/formats/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
from lxml import etree
from lxml.builder import E

from django.utils.dateparse import parse_datetime
from django.contrib.gis.geos import Polygon, MultiPolygon

from eoxserver.core.util.xmltools import parse
from eoxserver.core.util.timetools import isoformat
from eoxserver.core.util.iteratortools import pairwise
from eoxserver.core.util.timetools import parse_iso8601
from eoxserver.core import Component, implements
from eoxserver.core.decoders import xml
from eoxserver.resources.coverages.metadata.interfaces import (
Expand All @@ -52,10 +52,8 @@ def test(self, obj):
xml = parse(obj)
return xml is not None and xml.tag == "Metadata"


def get_format_name(self, obj):
return "native"


def read(self, obj):
tree = parse(obj)
Expand All @@ -70,7 +68,6 @@ def read(self, obj):
}
raise Exception("Could not parse from obj '%s'." % repr(obj))


def write(self, values, file_obj, format=None, encoding=None, pretty=False):
def flip(point):
return point[1], point[0]
Expand All @@ -81,7 +78,7 @@ def flip(point):
E.BeginTime(isoformat(values["begin_time"])),
E.EndTime(isoformat(values["end_time"])),
E.Footprint(
*map(lambda polygon:
*map(lambda polygon:
E.Polygon(
E.Exterior(
" ".join([
Expand Down Expand Up @@ -112,14 +109,14 @@ def parse_polygon_xml(elem):
*map(lambda e: parse_ring(e.text), elem.findall("Interior"))
)


def parse_ring(string):
points = []
raw_coords = map(float, string.split(" "))
return [(lon, lat) for lat, lon in pairwise(raw_coords)]


class NativeFormatDecoder(xml.Decoder):
identifier = xml.Parameter("EOID/text()")
begin_time = xml.Parameter("BeginTime/text()", type=parse_datetime)
end_time = xml.Parameter("EndTime/text()", type=parse_datetime)
begin_time = xml.Parameter("BeginTime/text()", type=parse_iso8601)
end_time = xml.Parameter("EndTime/text()", type=parse_iso8601)
polygons = xml.Parameter("Footprint/Polygon", type=parse_polygon_xml, num="+")

0 comments on commit 92cf3e8

Please sign in to comment.