Exemplo n.º 1
0
def get_meta(meta_url):
    """Get metadata from *meta_url*."""
    meta = meta_cache.get(meta_url)
    if meta is None:
        meta = ET.fromstring(read_url(meta_url))
        meta_cache[meta_url] = meta
    return meta
Exemplo n.º 2
0
def download_and_parse(query_id, args=None):
    """Download and parse the given stored query."""
    url = wfs.STORED_QUERY_URL + query_id
    if args:
        url = url + "&" + "&".join(args)
    xml = read_url(url)
    return ParseRadar(xml)
Exemplo n.º 3
0
def download_and_parse(query_id, args=None):
    """Download and parse the given stored query."""
    url = wfs.STORED_QUERY_URL + query_id
    if args:
        url = url + "&" + "&".join(args)
    xml = read_url(url)
    mode = query_id.split("::")[-1]
    return Lightning(xml, mode)
Exemplo n.º 4
0
def download_and_parse(query_id, args=None):
    """Download and parse the given stored query."""
    timeseries = False
    if "timeseries=True" in args:
        timeseries = True
        args.remove("timeseries=True")
    url = wfs.STORED_QUERY_URL + query_id
    if args:
        url = url + "&" + "&".join(args)
    xml = read_url(url)
    return MultiPoint(xml, query_id, timeseries=timeseries)
Exemplo n.º 5
0
 def download(self):
     """Download the data."""
     if self.data is None:
         with tempfile.NamedTemporaryFile() as fid:
             data = read_url(self.url)
             if len(data) < 10e3 and "ServiceException" in str(data):
                 msg = "WMS returned an exception: %s" % str(data)
                 raise ValueError(msg)
             fid.write(data)
             img = rasterio.open(fid.name)
             self.projection = img.crs.wkt
             self.data = img.read()
             self._dtype = self.data.dtype
Exemplo n.º 6
0
def get_wms_layers():
    """Get WMS layer info."""
    xml = read_url(WMS_BASE)
    root = ET.fromstring(xml)

    layers = root.findall(WMS_LAYERS)

    res = dict()
    for itm in layers:
        layer = WMSLayer(itm)
        if layer.name is not None:
            res[layer.name] = layer

    return res
Exemplo n.º 7
0
def write_description_md(fid, query_id):
    """Write available query parameters in markdown."""
    xml = ET.fromstring(read_url(wfs.BASE_URL + "DescribeStoredQueries&storedquery_id=" + query_id))
    fid.write(xml.findtext(wfs.WFS_ABSTRACT).strip())
    fid.write("\n\n")
    fid.write("* Query ID: `%s`\n" % query_id)
    fid.write("* Available arguments:\n")
    params = xml.findall(wfs.WFS_PARAMETER)
    for i, param in enumerate(params):
        fid.write("    * %s\n" % param.attrib["name"])
        param_title = param.findtext(wfs.WFS_TITLE)
        fid.write("        * %s\n" % param_title)
        param_abstract = param.findtext(wfs.WFS_ABSTRACT).strip()
        fid.write("        * %s\n" % param_abstract)
    fid.write("\n\n")
Exemplo n.º 8
0
def _parse_names_and_units(xml):
    type2obs = dict()

    for field in xml.findall(wfs.SWE_FIELD):
        typ = field.attrib["name"]
        try:
            url = field.attrib[wfs.LINK]
            root = ET.fromstring(read_url(url))
            name = root.findtext(wfs.OMOP_LABEL)
            try:
                units = root.find(wfs.OMOP_UOM).attrib["uom"]
            except AttributeError:
                units = ''
        except KeyError:
            name = field.findtext(wfs.SWE_LABEL)
            units = field.find(wfs.SWE_UOM).attrib['code']
        type2obs[typ] = dict({"name": name, "units": units})

    return type2obs
Exemplo n.º 9
0
def write_description(fid, query_id):
    """Write available query parameters."""
    xml = ET.fromstring(read_url(wfs.BASE_URL + "DescribeStoredQueries&storedquery_id=" + query_id))
    fid.write("<p>")
    fid.write(xml.findtext(wfs.WFS_ABSTRACT).strip())
    fid.write("</p>")
    fid.write("<ul>")
    fid.write("<li>Query ID: %s</li>" % query_id)
    fid.write("<li>Available arguments:</li>")
    fid.write("<ul>")
    params = xml.findall(wfs.WFS_PARAMETER)
    for i, param in enumerate(params):
        fid.write("<li>%s</li>" % param.attrib["name"])
        fid.write("<ul>")
        param_title = param.findtext(wfs.WFS_TITLE)
        fid.write("<li>%s</li>" % param_title)
        param_abstract = param.findtext(wfs.WFS_ABSTRACT).strip()
        fid.write("<li>%s</li>" % param_abstract)
        fid.write("</ul>")
    fid.write("</ul>")
    fid.write("</ul>")
    fid.write("</ul>")
Exemplo n.º 10
0
def get_req_xml(req):
    """Get request XML for *req*."""
    return read_url(BASE_URL + req)
Exemplo n.º 11
0
def get_wms_cababilities():
    """Get cababilities from WMS."""
    return read_url(WMS_BASE)