How to use the owslib.owscontext.common.extract_p function in OWSLib

To help you get started, we’ve selected a few OWSLib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geopython / OWSLib / owslib / owscontext / atom.py View on Github external
#   
    # 			
    if is_empty(d):
        return None
    else:
        try:
            offering_code = extract_p('code', d, None)
            offering = etree.Element(ns_elem("owc", "offering"), attrib={"code": offering_code}, nsmap=ns)

            # use axml_operation here
            operations = [axml_operation(do) for do in
                          extract_p('operations', d, [])]
            [offering.append(el) for el in operations if el is not None]
            # use axml_content here
            contents = [axml_content(do) for do in
                        extract_p('contents', d, [])]
            [offering.append(el) for el in contents if el is not None]
            # use axml_styeset here
            styles = [axml_styleset(do) for do in
                      extract_p('styles', d, [])]
            [offering.append(el) for el in styles if el is not None]
            return offering
        except Exception as ex:
            log.warn('could encode offering', ex)
            return None
github geopython / OWSLib / owslib / owscontext / atom.py View on Github external
except Exception as ex:
            log.warn('could encode bbox into georss:where', ex)
            pass

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

    language = extract_p('properties.lang', d, None)
    if language is not None: xml.set(ns_elem("xml", "lang"), language)

    title = extract_p('properties.title', d, None)
    if title is not None: etree.SubElement(xml, "title").text = title

    # 
github geopython / OWSLib / owslib / owscontext / atom.py View on Github external
def axml_content(d):
    """
    OwcContent dict to Atom XML
    :param d:
    :return:
    """
    #   
github geopython / OWSLib / owslib / owscontext / atom.py View on Github external
update_date = extract_p('properties.updated', d, None)
    if update_date is not None: etree.SubElement(xml, "updated").text = update_date

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

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

    creator_application = axml_creator_app(extract_p('properties.generator', d, None))
    if creator_application is not None and not is_empty(creator_application): xml.append(creator_application)

    creator_display = axml_display(extract_p('properties.display', d, None))
    if creator_display is not None: xml.append(creator_display)

    rights = extract_p('properties.rights', d, None)
    if rights is not None: etree.SubElement(xml, "rights").text = rights

    time_interval_of_interest = extract_p('properties.date', d, None)
    if time_interval_of_interest is not None: etree.SubElement(xml,
                                                               ns_elem("dc", "date")).text = time_interval_of_interest

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

    # here we generate single elements and attach them
    resources = [axml_resource(do) for do in
                 extract_p('features', d, [])]
    [xml.append(el) for el in resources if el is not None]

    return xml
github geopython / OWSLib / owslib / owscontext / atom.py View on Github external
[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))
    # 2500
    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))
    # 25000
    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)
github geopython / OWSLib / owslib / owscontext / atom.py View on Github external
def axml_content(d):
    """
    OwcContent dict to Atom XML
    :param d:
    :return:
    """
    #   
github geopython / OWSLib / owslib / owscontext / atom.py View on Github external
def axml_display(d):
    # 
    # 		
    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
github geopython / OWSLib / owslib / owscontext / atom.py View on Github external
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
</content>
github geopython / OWSLib / owslib / owscontext / core.py View on Github external
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)),
github geopython / OWSLib / owslib / owscontext / atom.py View on Github external
#       raster
    #       Default Raster
    #       A sample style that draws a 
    #       
    #     
    if is_empty(d):
        return None
    else:
        try:
            styleset = etree.Element(ns_elem("owc", "styleSet"), nsmap=ns)

            name = extract_p('name', d, None)
            if name is not None: etree.SubElement(styleset, ns_elem("owc", "name")).text = name
            title = extract_p('title', d, None)
            if title is not None: etree.SubElement(styleset, ns_elem("owc", "title")).text = title
            subtitle = extract_p('abstract', d, None)
            if subtitle is not None: etree.SubElement(styleset, ns_elem("owc", "abstract")).text = subtitle
            is_default = extract_p('default', d, None)
            # TODO no example for default setting on style set
            if is_default is not None: etree.SubElement(styleset, ns_elem("owc", "default")).text = is_default
            legend_url = extract_p('legendURL', d, None)
            if legend_url is not None: etree.SubElement(styleset, ns_elem("owc", "legendURL")).text = legend_url
            # TODO no example for content on style set
            content = extract_p('content', d, None)
            content_enc = None if content is None else axml_content(content)
            if content_enc is not None: styleset.append(content_enc)
            return styleset
        except Exception as ex:
            log.warn('could encode styleset', ex)
            return None