def get(self, *args, **kwargs): '''Service a GET request to the '/map' URI. The 'bbox' parameter contains 4 coordinates "l" (w), "b" (s), "r" (e) and "t" (n).''' # Sanity check the input. bbox_arg = self.get_argument('bbox', None) if not bbox_arg: raise tornado.web.HTTPError(400) # Bad Syntax bbox = bbox_arg.split(',') if len(bbox) != 4: raise tornado.web.HTTPError(400) try: w,s,e,n = map(float, bbox) except ValueError: raise tornado.web.HTTPError(400) # Check the "l,b,r,t" coordinates passed in for sanity. if w < C.LON_MIN or w > C.LON_MAX or \ e < C.LON_MIN or e > C.LON_MAX or \ s < C.LAT_MIN or s > C.LAT_MAX or \ n < C.LAT_MIN or n > C.LAT_MAX or \ n < s or e < w: raise tornado.web.HTTPError(400) nodelist, ways, relations = self.handle_map(bbox) response = self.build_bbox_response(nodelist, ways, relations, bbox) self.set_header(C.CONTENT_TYPE, C.TEXT_XML) self.write(response_to_xml(response))
def get(self): self.set_header(C.CONTENT_TYPE, C.TEXT_XML) def _get(name): return self.cfg.get(C.FRONT_END, name) osm = new_osm_response() api = ET.SubElement(osm, "api") version = ET.SubElement(api, "version") version.attrib['minimum'] = _get(C.API_VERSION_MINIMUM) version.attrib['maximum'] = _get(C.API_VERSION_MAXIMUM) area = ET.SubElement(api, "area") area.attrib['maximum'] = _get(C.AREA_MAX) tracepoints = ET.SubElement(api, "tracepoints") tracepoints.attrib['per_page'] = _get(C.TRACEPOINTS_PER_PAGE) waynodes = ET.SubElement(api, "waynodes") waynodes.attrib['maximum'] = _get(C.WAYNODES_MAX) changesets = ET.SubElement(api, "changesets") changesets.attrib['maximum_elements'] = _get(C.CHANGESETS_MAX) timeout = ET.SubElement(api, "timeout") timeout.attrib['seconds'] = _get(C.API_CALL_TIMEOUT) self.write(response_to_xml(osm))
def get(self, *args, **kwargs): '''Service a GET request to the '/map' URI. The 'bbox' parameter contains 4 coordinates "l" (w), "b" (s), "r" (e) and "t" (n).''' # Sanity check the input. bbox_arg = self.get_argument('bbox', None) if not bbox_arg: raise tornado.web.HTTPError(400) # Bad Syntax bbox = bbox_arg.split(',') if len(bbox) != 4: raise tornado.web.HTTPError(400) try: w, s, e, n = map(float, bbox) except ValueError: raise tornado.web.HTTPError(400) # Check the "l,b,r,t" coordinates passed in for sanity. if w < C.LON_MIN or w > C.LON_MAX or \ e < C.LON_MIN or e > C.LON_MAX or \ s < C.LAT_MIN or s > C.LAT_MAX or \ n < C.LAT_MIN or n > C.LAT_MAX or \ n < s or e < w: raise tornado.web.HTTPError(400) nodelist, ways, relations = self.handle_map(bbox) response = self.build_bbox_response(nodelist, ways, relations, bbox) self.set_header(C.CONTENT_TYPE, C.TEXT_XML) self.write(response_to_xml(response))
def get(self, namespace, ident): self.set_header(C.CONTENT_TYPE, C.TEXT_XML) elem = self.datastore.fetch(namespace, ident) if elem is None: raise tornado.web.HTTPError(404) self.write(response_to_xml(elem.build_response(new_osm_response())))
def get(self, nodeid): "Retrieve the ways associated with a node." elem = self.datastore.fetch(C.NODE, nodeid) if elem is None: raise tornado.web.HTTPError(404) osm = new_osm_response() wayset = filter_references(C.WAY, [elem]) if len(wayset) > 0: ways = self.datastore.fetch_keys(C.WAY, [w for w in wayset]) for (st,w) in ways: if st: w.build_response(osm) self.set_header(C.CONTENT_TYPE, C.TEXT_XML) self.write(response_to_xml(osm))
def get(self, element): """Retrieve multiple elements. The elements are specified by (nodes|ways|relations) parameter to the request, as a comma separated list of element IDs. """ if element not in [C.NODES, C.WAYS, C.RELATIONS]: # Programming error. raise tornado.web.HTTPError(500) # Determine the name space to use. if element == C.NODES: namespace = C.NODE elif element == C.WAYS: namespace = C.WAY elif element == C.RELATIONS: namespace = C.RELATION else: assert False, "Unexpected element '%s'" % element # The name of the parameter (i.e., one of "nodes", "ways" or # "relations") match the last component of the URI. params = self.get_argument(element, None) if not params: raise tornado.web.HTTPError(400) # Create a new response. osm = new_osm_response() # Add elements to the response. for (st,r) in self.datastore.fetch_keys(namespace, params.split(",")): if st: r.build_response(osm) # Send the XML representation back to the client. self.set_header(C.CONTENT_TYPE, C.TEXT_XML) self.write(response_to_xml(osm))
def get(self, namespace, ident): """Retrieve relations for an element. The element can be a 'node' or 'way'. """ if namespace not in [C.NODE, C.WAY, C.RELATION]: raise tornado.web.HTTPError(500) elem = self.datastore.fetch(namespace, ident) osm = new_osm_response() if elem: relset = filter_references(C.RELATION, [elem]) if len(relset) > 0: relations = self.datastore.fetch_keys(C.RELATION, [r for r in relset]) for (st,r) in relations: if st: r.build_response(osm) self.set_header(C.CONTENT_TYPE, C.TEXT_XML) self.write(response_to_xml(osm))
def get(self, namespace, elemid): """Implement a 'GET' operation. For a way: - Return the way itself, - Return the full XML of all nodes referenced by the way. For a relation: - Return the relation itself, - All nodes and ways that are members of the relation. - All nodes referenced from the ways above. """ # Retrieve the element. element = self.datastore.fetch(namespace, elemid) if element is None: raise tornado.web.HTTPError(404) nodes = [] ways = [] relations = [] if namespace == C.RELATION: # Retrieve nodes directly referenced by the relation. nodeset = element.get_member_ids(C.NODE) nodes.extend([z for (st,z) in self.datastore.fetch_keys(C.NODE, [n for n in nodeset]) if st]) # Retrieve way IDs directly referenced by the relation. wayset = element.get_member_ids(C.WAY) # Include the relation itself. relations.append(element) else: nodeset = set() wayset = set([elemid]) # Fetch all ways. if len(wayset) > 0: ways.extend([z for (st, z) in self.datastore.fetch_keys(C.WAY, [w for w in wayset]) if st]) # Fetch additional nodes referenced by the ways in the # way set. additional_nodes = set() for w in ways: additional_nodes.update(w.get_node_ids()) additional_nodes = additional_nodes - nodeset nodes.extend([z for (st, z) in self.datastore.fetch_keys(C.NODE, [n for n in additional_nodes]) if st]) # Build and return a response. osm = new_osm_response() for n in nodes: n.build_response(osm) for w in ways: w.build_response(osm) for r in relations: r.build_response(osm) self.set_header(C.CONTENT_TYPE, C.TEXT_XML) self.write(response_to_xml(osm))