Ejemplo n.º 1
0
 def from_dict(cls, d):
     return OwcResource(
         id=d['id'],
         geospatial_extent=extract_p('geometry', d, None),
         title=d['properties']['title'],
         subtitle=extract_p('properties.abstract', d, None),
         update_date=extract_p('properties.updated', d, None),
         authors=[OwcAuthor.from_dict(do) for do in
                  extract_p('properties.authors', d, [])],
         publisher=extract_p('properties.publisher', d, None),
         rights=extract_p('properties.rights', d, None),
         temporal_extent=TimeIntervalFormat.from_string(
             extract_p('properties.date', d, None)),
         keywords=[OwcCategory.from_dict(do) for do in
                   extract_p('properties.categories', d, [])],
         resource_metadata=[OwcLink.from_dict(do) for do in
                            extract_p('properties.links.via', d, [])],
         content_description=[OwcLink.from_dict(do)
                              for do in extract_p('properties.links.alternates', d, [])],
         preview=[OwcLink.from_dict(do) for do in
                  extract_p('properties.links.previews', d, [])],
         content_by_ref=[OwcLink.from_dict(do) for do in
                         extract_p('properties.links.data', d, [])],
         offerings=[OwcOffering.from_dict(do) for do in
                    extract_p('properties.offerings', d, [])],
         active=extract_p('properties.active', d, None),
         min_scale_denominator=try_float(extract_p(
             'properties.minscaledenominator', d, None)),
         max_scale_denominator=try_float(extract_p(
             'properties.maxscaledenominator', d, None)),
         folder=extract_p('properties.folder', d, None),
     )
Ejemplo n.º 2
0
def axml_display(d):
    # <owc:display>
    # 		<owc:pixelWidth>
    if is_empty(d):
        return None
    else:
        try:
            creator_display = etree.Element(ns_elem("owc", "display"),
                                            nsmap=ns)
            pixel_width = try_int(extract_p('pixelWidth', d, None))
            if pixel_width is not None:
                etree.SubElement(creator_display,
                                 ns_elem("owc",
                                         "pixelWidth")).text = str(pixel_width)
            pixel_height = try_int(extract_p('pixelHeight', d, None))
            if pixel_height is not None:
                etree.SubElement(creator_display, ns_elem(
                    "owc", "pixelHeight")).text = str(pixel_height)
            mm_per_pixel = try_float(extract_p('mmPerPixel', d, None))
            if mm_per_pixel is not None:
                etree.SubElement(creator_display, ns_elem(
                    "owc", "mmPerPixel")).text = str(mm_per_pixel)
            return creator_display
        except Exception as ex:
            log.warning('could encode creator_display', ex)
            return None
Ejemplo n.º 3
0
def axml_display(d):
    # <owc:display>
    # 		<owc:pixelWidth>
    if is_empty(d):
        return None
    else:
        try:
            creator_display = etree.Element(ns_elem("owc", "display"), nsmap=ns)
            pixel_width = try_int(extract_p('pixelWidth', d, None))
            if pixel_width is not None: etree.SubElement(creator_display,
                                                         ns_elem("owc", "pixelWidth")).text = str(pixel_width)
            pixel_height = try_int(extract_p('pixelHeight', d, None))
            if pixel_height is not None: etree.SubElement(creator_display,
                                                          ns_elem("owc", "pixelHeight")).text = str(pixel_height)
            mm_per_pixel = try_float(extract_p('mmPerPixel', d, None))
            if mm_per_pixel is not None: etree.SubElement(creator_display,
                                                          ns_elem("owc", "mmPerPixel")).text = str(mm_per_pixel)
            return creator_display
        except Exception as ex:
            log.warn('could encode creator_display', ex)
            return None
Ejemplo n.º 4
0
def axml_resource(d):
    """
    encodes an OwcResource as dict into atom xml tree
    :param d:
    :return:
    """
    entry = etree.Element("entry", nsmap=ns)

    etree.SubElement(entry, "id").text = d['id']

    geospatial_extent = extract_p('geometry', d, None)
    if geospatial_extent is not None:
        try:
            gml = etree.fromstring(geospatial_extent)
            georss = etree.SubElement(entry, ns_elem("georss", "where"))
            georss.append(gml)
        except Exception as ex:
            log.warning('could encode geometry into georss:where', ex)
            pass

    title = d['properties']['title']
    if title is not None:
        etree.SubElement(entry, "title").text = title

    subtitle = extract_p('properties.abstract', d, None)
    # <content type = "text" >
    if subtitle is not None:
        etree.SubElement(entry, "content").text = subtitle

    update_date = extract_p('properties.updated', d, None)
    if update_date is not None:
        etree.SubElement(entry, "updated").text = update_date

    authors = [
        axml_author(do) for do in extract_p('properties.authors', d, [])
    ]
    [entry.append(el) for el in authors if el is not None]

    publisher = extract_p('properties.publisher', d, None)
    if update_date is not None:
        etree.SubElement(entry, ns_elem("dc", "publisher")).text = publisher

    rights = extract_p('properties.rights', d, None)
    if update_date is not None:
        etree.SubElement(entry, ns_elem("dc", "rights")).text = rights

    temporal_extent = extract_p('properties.date', d, None)
    if temporal_extent is not None:
        etree.SubElement(entry, "date").text = temporal_extent

    keywords = [
        axml_category(do) for do in extract_p('properties.categories', d, [])
    ]
    [entry.append(el) for el in keywords if el is not None]

    resource_metadata = [
        axml_link(do) for do in extract_p('properties.links.via', d, [])
    ]
    [entry.append(el) for el in resource_metadata if el is not None]

    content_description = [
        axml_content(do)
        for do in extract_p('properties.links.alternates', d, [])
    ]
    [entry.append(el) for el in content_description if el is not None]

    preview = [
        axml_link(do) for do in extract_p('properties.links.preview', d, [])
    ]
    [entry.append(el) for el in preview if el is not None]

    content_by_ref = [
        axml_link(do) for do in extract_p('properties.links.data', d, [])
    ]
    [entry.append(el) for el in content_by_ref if el is not None]

    offerings = [
        axml_offering(do) for do in extract_p('properties.offerings', d, [])
    ]
    [entry.append(el) for el in offerings if el is not None]

    # TODO no examples for active attribute
    active = extract_p('properties.active', d, None)
    if active is not None:
        etree.SubElement(entry, "active").text = active

    min_scale_denominator = try_float(
        extract_p('properties.minscaledenominator', d, None))
    # <owc:minScaleDenominator>2500</owc:minScaleDenominator>
    if min_scale_denominator is not None:
        etree.SubElement(entry, ns_elem(
            "owc", "minScaleDenominator")).text = str(min_scale_denominator)

    max_scale_denominator = try_float(
        extract_p('properties.maxscaledenominator', d, None))
    # <owc:maxScaleDenominator>25000</owc:maxScaleDenominator>
    if max_scale_denominator is not None:
        etree.SubElement(entry, ns_elem(
            "owc", "maxScaleDenominator")).text = str(max_scale_denominator)

    # TODO no examples for folder attribute
    folder = extract_p('properties.folder', d, None)
    if folder is not None:
        etree.SubElement(entry, "folder").text = folder

    # xml.append(entry)
    return entry
Ejemplo n.º 5
0
def axml_resource(d):
    """
    encodes an OwcResource as dict into atom xml tree
    :param d:
    :return:
    """
    entry = etree.Element("entry", nsmap=ns)

    etree.SubElement(entry, "id").text = d['id']

    geospatial_extent = extract_p('geometry', d, None)
    if geospatial_extent is not None:
        try:
            gml = etree.fromstring(geospatial_extent)
            georss = etree.SubElement(entry, ns_elem("georss", "where"))
            georss.append(gml)
        except Exception as ex:
            log.warn('could encode geometry into georss:where', ex)
            pass

    title = d['properties']['title']
    if title is not None: etree.SubElement(entry, "title").text = title

    subtitle = extract_p('properties.abstract', d, None)
    # <content type = "text" >
    if subtitle is not None: etree.SubElement(entry, "content").text = subtitle

    update_date = extract_p('properties.updated', d, None)
    if update_date is not None: etree.SubElement(entry, "updated").text = update_date

    authors = [axml_author(do) for do in
               extract_p('properties.authors', d, [])]
    [entry.append(el) for el in authors if el is not None]

    publisher = extract_p('properties.publisher', d, None)
    if update_date is not None: etree.SubElement(entry, ns_elem("dc", "publisher")).text = publisher

    rights = extract_p('properties.rights', d, None)
    if update_date is not None: etree.SubElement(entry, ns_elem("dc", "rights")).text = rights

    temporal_extent = extract_p('properties.date', d, None)
    if temporal_extent is not None: etree.SubElement(entry, "date").text = temporal_extent

    keywords = [axml_category(do) for do in
                extract_p('properties.categories', d, [])]
    [entry.append(el) for el in keywords if el is not None]

    resource_metadata = [axml_link(do) for do in
                         extract_p('properties.links.via', d, [])]
    [entry.append(el) for el in resource_metadata if el is not None]

    content_description = [axml_content(do)
                           for do in extract_p(
            'properties.links.alternates', d, [])]
    [entry.append(el) for el in content_description if el is not None]

    preview = [axml_link(do) for do in
               extract_p('properties.links.preview', d, [])]
    [entry.append(el) for el in preview if el is not None]

    content_by_ref = [axml_link(do) for do in
                      extract_p('properties.links.data', d, [])]
    [entry.append(el) for el in content_by_ref if el is not None]

    offerings = [axml_offering(do) for do in
                 extract_p('properties.offerings', d, [])]
    [entry.append(el) for el in offerings if el is not None]

    # TODO no examples for active attribute
    active = extract_p('properties.active', d, None)
    if active is not None: etree.SubElement(entry, "active").text = active

    min_scale_denominator = try_float(extract_p(
        'properties.minscaledenominator', d, None))
    # <owc:minScaleDenominator>2500</owc:minScaleDenominator>
    if min_scale_denominator is not None: etree.SubElement(entry, ns_elem("owc",
                                                                          "minScaleDenominator")).text = str(min_scale_denominator)

    max_scale_denominator = try_float(extract_p(
        'properties.maxscaledenominator', d, None))
    # <owc:maxScaleDenominator>25000</owc:maxScaleDenominator>
    if max_scale_denominator is not None: etree.SubElement(entry, ns_elem("owc",
                                                                          "maxScaleDenominator")).text = str(max_scale_denominator)

    # TODO no examples for folder attribute
    folder = extract_p('properties.folder', d, None)
    if folder is not None: etree.SubElement(entry, "folder").text = folder

    # xml.append(entry)
    return entry
Ejemplo n.º 6
0
 def from_dict(cls, d):
     return OwcCreatorDisplay(
         pixel_width=try_int(extract_p('pixelWidth', d, None)),
         pixel_height=try_int(extract_p('pixelHeight', d, None)),
         mm_per_pixel=try_float(extract_p('mmPerPixel', d, None))
     )