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, 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 handle_map(self, bbox): """Implementation of the /map API. Parameters: bbox -- Bounding box coordinates. """ nodelist = [] relations = [] ways = [] # This implementation follows the current implementation of # the API server at api.openstreetmap.org (the 'rails' port). # Look up the geo coded documents covering the desired bbox. gckeys = self.get_geocodes(bbox) geodocs = self.datastore.fetch_keys(C.GEODOC, gckeys) # Step 1: Get the list of nodes contained in the given # bounding box. nodeset = _filter_in_bbox(bbox, [gd for (st, gd) in geodocs if st]) if len(nodeset) == 0: return (nodelist, ways, relations) nodelist = [z for (st, z) in self.datastore.fetch_keys( C.NODE, [n for n in nodeset]) if st] # Step 2: Retrieve all ways that reference at least one node # in the given bounding box. wayset = filter_references(C.WAY, nodelist) # Step 3: Retrieve any additional nodes referenced by the ways # retrieved. waynodeset = set() for (st,w) in self.datastore.fetch_keys(C.WAY, [w for w in wayset]): if st: ways.append(w) waynodeset.update(w.get_node_ids()) extranodeset = waynodeset - nodeset nodelist.extend([n for (st,n) in self.datastore.fetch_keys(C.NODE, [n for n in extranodeset]) if st]) nodeset = nodeset | extranodeset # Step 4: Retrieve the relations associated with these nodes. # ... all relations that reference nodes being returned. relset = filter_references(C.RELATION, nodelist) # ... and relations that reference one of the ways in the wayset. relset.update(filter_references(C.RELATION, ways)) # ... retrieve relations from the data store. relations = [xr for (st,xr) in self.datastore.fetch_keys(C.RELATION, [r for r in relset]) if st] # ... and relations referenced by existing relations # (one-pass only). extrarelset = filter_references(C.RELATION, relations) newrelset = extrarelset - relset newrels = [nr for (st, nr) in self.datastore.fetch_keys(C.RELATION, [r for r in newrelset]) if st] relations.extend(newrels) return (nodelist, ways, relations)
def handle_map(self, bbox): """Implementation of the /map API. Parameters: bbox -- Bounding box coordinates. """ nodelist = [] relations = [] ways = [] # This implementation follows the current implementation of # the API server at api.openstreetmap.org (the 'rails' port). # Look up the geo coded documents covering the desired bbox. gckeys = self.get_geocodes(bbox) geodocs = self.datastore.fetch_keys(C.GEODOC, gckeys) # Step 1: Get the list of nodes contained in the given # bounding box. nodeset = _filter_in_bbox(bbox, [gd for (st, gd) in geodocs if st]) if len(nodeset) == 0: return (nodelist, ways, relations) nodelist = [ z for (st, z) in self.datastore.fetch_keys(C.NODE, [n for n in nodeset]) if st ] # Step 2: Retrieve all ways that reference at least one node # in the given bounding box. wayset = filter_references(C.WAY, nodelist) # Step 3: Retrieve any additional nodes referenced by the ways # retrieved. waynodeset = set() for (st, w) in self.datastore.fetch_keys(C.WAY, [w for w in wayset]): if st: ways.append(w) waynodeset.update(w.get_node_ids()) extranodeset = waynodeset - nodeset nodelist.extend([ n for (st, n) in self.datastore.fetch_keys( C.NODE, [n for n in extranodeset]) if st ]) nodeset = nodeset | extranodeset # Step 4: Retrieve the relations associated with these nodes. # ... all relations that reference nodes being returned. relset = filter_references(C.RELATION, nodelist) # ... and relations that reference one of the ways in the wayset. relset.update(filter_references(C.RELATION, ways)) # ... retrieve relations from the data store. relations = [ xr for (st, xr) in self.datastore.fetch_keys( C.RELATION, [r for r in relset]) if st ] # ... and relations referenced by existing relations # (one-pass only). extrarelset = filter_references(C.RELATION, relations) newrelset = extrarelset - relset newrels = [ nr for (st, nr) in self.datastore.fetch_keys( C.RELATION, [r for r in newrelset]) if st ] relations.extend(newrels) return (nodelist, ways, relations)