def test_delegates_distance_between_int_points_query_to_s2(mocker): mocker.patch.object(s2sphere.LatLng, 'get_distance', return_value=s2sphere.Angle(radians=3)) distance = spatial.distance_between_s2cellids( s2sphere.CellId.from_lat_lng(s2sphere.LatLng.from_degrees(53.483959, -2.244644)).id(), s2sphere.CellId.from_lat_lng(s2sphere.LatLng.from_degrees(53.583959, -2.344644)).id()) earth_radius_metres = 6371008.8 assert distance == 3 * earth_radius_metres s2sphere.LatLng.get_distance.assert_called_once()
def crowfly_distance(self): distance = 0 for prev_stop, next_stop in zip(self.ordered_stops[:-1], self.ordered_stops[1:]): # todo replace by accessing graph nodes distance += spatial.distance_between_s2cellids( self.stop(prev_stop).s2_id, self.stop(next_stop).s2_id) return distance
def generate_graph_edges(edges, reindexing_dict, nodes_and_attributes, config_path): edges_attributes = [] for edge, attribs in edges: u, v = str(edge[0]), str(edge[1]) if u in reindexing_dict: u = reindexing_dict[u] if v in reindexing_dict: v = reindexing_dict[v] link_attributes = find_matsim_link_values(attribs, Config(config_path)).copy() if 'lanes' in attribs: try: # overwrite the default matsim josm values link_attributes['permlanes'] = ceil(float(attribs['lanes'])) except Exception as e: logging.warning( f'Reading lanes from OSM resulted in {type(e)} with message "{e}".' f'Found at edge {edge}. Defaulting to permlanes={link_attributes["permlanes"]}' ) # compute link-wide capacity link_attributes['capacity'] = link_attributes[ 'permlanes'] * link_attributes['capacity'] link_attributes['oneway'] = '1' link_attributes['modes'] = attribs['modes'] link_attributes['from'] = u link_attributes['to'] = v link_attributes['s2_from'] = nodes_and_attributes[u]['s2_id'] link_attributes['s2_to'] = nodes_and_attributes[v]['s2_id'] link_attributes['length'] = spatial.distance_between_s2cellids( link_attributes['s2_from'], link_attributes['s2_to']) # the rest of the keys are osm attributes link_attributes['attributes'] = {} for key, val in attribs.items(): if key not in link_attributes: link_attributes['attributes']['osm:way:{}'.format(key)] = { 'name': 'osm:way:{}'.format(key), 'class': 'java.lang.String', 'text': str(val), } edges_attributes.append(link_attributes) return edges_attributes