def describe_collection(self, headers, args, dataset, identifier): fo = format_output.FormatOutput( self.config, ["/collections/" + dataset + "/" + identifier]) output = fo.create_links(False) content_type = args.get('outputFormat') output = fo.collections_description(dataset, True) output['name'] = dataset output['instance'] = identifier headers = {} try: if content_type is not None: if content_type.find('html') > -1: headers['Content-Type'] = 'text/html' output = _render_j2_template(self.config, "instance.html", output) elif content_type.find('xml') > -1: headers['Content-Type'] = 'application/xml' output = fo.get_xml(output) elif (content_type.find('yml') > -1) or (content_type.find('yaml') > -1): headers['Content-Type'] = 'application/x-yaml' output = fo.get_yaml(output) else: output = fo.get_json(output) headers['Content-Type'] = 'application/json' else: headers['Content-Type'] = 'text/html' output = _render_j2_template(self.config, "instance.html", output) except: output = _render_j2_template(self.config, 'error.html', {}) return headers, 200, output
def describe_group(self, headers, args, subpath=None): output = {} fo = format_output.FormatOutput(self.config, ['/groups']) output['links'] = fo.create_links(False) content_type = args.get('outputFormat') group_links = [] cdescrip = None headers = {} group_links, cdescrip = self.group_metadata(subpath) template_name = "group.html" if cdescrip == None: fo = format_output.FormatOutput(self.config, group_links) output['members'] = fo.create_links(True) else: fo = format_output.FormatOutput(self.config, ["/collections"]) co_descrip = fo.collections_description(cdescrip, False) output['members'] = [] for co_link in co_descrip: if co_link[3]['href'].find('collection') > -1: output['members'].append(co_link) if content_type is not None: if content_type.find('html') > -1: output = _render_j2_template(self.config, template_name, output) content_type = 'text/html' elif content_type.find('xml') > -1: output = fo.get_xml(output) content_type = 'application/xml' elif (content_type.find('yml') > -1) or (content_type.find('yaml') > -1): output = fo.get_yaml(output) content_type = 'application/x-yaml' else: output = fo.get_json(output) content_type = 'application/json' else: content_type = 'text/html' output = _render_j2_template(self.config, template_name, output) headers['Content-Type'] = content_type return headers, 200, output
def instance_desc(self, collection, iid, title, description, link_path): desc = {} desc['id'] = iid desc['title'] = title desc['description'] = description fo = format_output.FormatOutput(self.config, [link_path + "/" + iid]) desc['extent'] = fo.collections_description('extent£' + collection, True) desc['links'] = fo.create_links(False) return desc
def describe_collections(self, headers, environ, args, dataset=None): """ Provide feature collection metadata :param headers: dict of HTTP headers :param args: dict of HTTP request parameters :returns: tuple of headers, status code, content """ ipparts = environ['REMOTE_ADDR'].split('.') if len(headers.getlist("X-Forwarded-For")) > 0: ipparts = headers.getlist("X-Forwarded-For")[0].split('.') met_ip = False if (ipparts[0] == '151') and ( ipparts[1] == '170') or environ['REMOTE_ADDR'] == '127.0.0.1': met_ip = True fo = format_output.FormatOutput(self.config, ["/collections"], met_ip) content_type = args.get('outputFormat') output = fo.collections_description("all", True) headers = {} try: if content_type is not None: if content_type.find('html') > -1: headers['Content-Type'] = 'text/html' output = _render_j2_template(self.config, "collections.html", output) elif content_type.find('xml') > -1: headers['Content-Type'] = 'application/xml' output = fo.get_xml(output) elif (content_type.find('yml') > -1) or (content_type.find('yaml') > -1): headers['Content-Type'] = 'application/x-yaml' output = fo.get_yaml(output) else: output = fo.get_json(output) headers['Content-Type'] = 'application/json' else: headers['Content-Type'] = 'text/html' output = _render_j2_template(self.config, 'collections.html', output) except: output = _render_j2_template(self.config, 'error.html', {}) return headers, 200, output
def root(self, headers, args): """ Provide API :param headers: dict of HTTP headers :param args: dict of HTTP request parameters :returns: tuple of headers, status code, content """ headers = {} content_type = args.get('outputFormat') fo = format_output.FormatOutput(self.config, [ "/", "/api", "/metadata", "/conformance", "/groups", "/collections" ]) output = fo.create_links(True) if content_type is not None: if content_type.find('html') > -1: output = _render_j2_template(self.config, 'root.html', output) content_type = 'text/html' elif content_type.find('xml') > -1: output = fo.get_xml(output) content_type = 'application/xml' elif (content_type.find('yml') > -1) or (content_type.find('yaml') > -1): output = fo.get_yaml(output) content_type = 'application/x-yaml' else: output = fo.get_json(output) content_type = 'application/json' else: content_type = 'text/html' output = _render_j2_template(self.config, 'root.html', output) headers['Content-Type'] = content_type return headers, 200, output
def list_identifers(self, headers, args, collection): output = {} fo = format_output.FormatOutput(self.config, ["/collections/" + collection]) output['links'] = fo.create_links(False) output['instances'] = [] content_type = args.get('outputFormat') instance = self.set_instance_type(collection) output['instances'] = instance output['name'] = collection output['title'] = collection.replace('_', ' ') output['parameters'] = fo.get_parameter_list(collection) headers = {} if content_type is not None: if content_type.find('html') > -1: headers['Content-Type'] = 'text/html' output = _render_j2_template(self.config, "collection.html", output) elif content_type.find('xml') > -1: headers['Content-Type'] = 'application/xml' output = fo.get_xml(output) elif (content_type.find('yml') > -1) or (content_type.find('yaml') > -1): headers['Content-Type'] = 'application/x-yaml' output = fo.get_yaml(output) else: output = fo.get_json(output) headers['Content-Type'] = 'application/json' else: headers['Content-Type'] = 'text/html' output = _render_j2_template(self.config, "collection.html", output) return headers, 200, output