コード例 #1
0
 def find_nearest_d(self, point, layers):
     """
     Like find_nearest but return a tuple of (Object, distance)
     """
     if isinstance(point, tuple):
         point = geojson.Point(coordinates=[point[0], point[1]])
         if len(point) == 3:
             point = self.transform(point, point[2], self.db_proj)
     o = self.find_nearest(point, layers)
     if o:
         return o, distance(point, o.point)
     else:
         return None, None
コード例 #2
0
 def get_data(self, request, object):
     ducts = []
     # Get all conduits
     conduits = defaultdict(list)
     for c, remote, _ in object.get_genderless_connections("conduits"):
         conduit, _ = c.p2p_get_other(object)
         for cc, t, _ in conduit.get_genderless_connections("conduits"):
             if t != object:
                 conduits[t] += [{
                     "id": str(conduit.id),
                     "n": int(conduit.name),
                     "x": cc.data["plan"]["x"],
                     "y": cc.data["plan"]["y"],
                     "d": 100,  # remote.data.get("...."),
                     "status": True,  # remote.data....
                 }]
     # Get neighbor ducts
     for c, remote, _ in object.get_genderless_connections("ducts"):
         map_distance = None
         br = None
         sbr = None
         if object.point and remote.point:
             map_distance = distance(object.point, remote.point)
             br = bearing(object.point, remote.point)
             sbr = bearing_sym(object.data, remote.data)
         cd = conduits[remote]
         ducts += [{
             "connection_id": str(c.id),
             "target_id": str(remote.id),
             "target_name": remote.name,
             "target_model_name": remote.model.name,
             "map_distance": map_distance,
             "project_distance": c.data.get("project_distance"),
             "n_conduits": len(cd),
             "conduits": cd,
             "bearing": br,
             "s_bearing": sbr,
         }]
     return {"id": str(object.id), "name": object.name, "ducts": ducts}
コード例 #3
0
 def api_get_neighbors(self, request, id):
     o = self.app.get_object_or_404(Object, id=id)
     if not o.point:
         return []
     layers = list(map.get_conduits_layers())
     connected = set(
         str(ro.id) for _, ro, _ in o.get_genderless_connections("ducts"))
     if self.is_single_connection(o) and connected:
         # Connection limits exceed
         return []
     r = []
     for ro in Object.objects.filter(
             id__ne=id,
             layer__in=layers,
             point__near=o.point,
             point__max_distance=self.MAX_CONDUIT_LENGTH,
     ):
         #  )).distance(o.point).order_by("distance"):
         # Check object has no connection with this one
         if ro in connected:
             continue
         # Exclude already connected cable entries
         if self.is_single_connection(ro) and len(
                 ro.get_genderless_connections("ducts")):
             continue
         # Feed data
         d = distance(o.point, ro.point)
         sbr = bearing_sym(o.point, ro.point)
         r += [{
             "id": str(ro.id),
             "label": "%s (%s, %dm)" % (ro.name, sbr, d),
             "s_bearing": sbr,
             "map_distance": d,
             "name": ro.name,
         }]
     return r
コード例 #4
0
ファイル: test_core_geo.py プロジェクト: marcosvella/noc
def test_geo_distance(config, config1, expected):
    assert int(distance(config, config1)) == expected