parameters: (self, p, is_get2=False, n_best=0, d_max=np.inf,
                           is_ending=True, is_detect_initial=False,
                           is_detect_final=False,
                           accesslevels=None)
docstring: Returns edge id which is closest to point p.
          Requires execution of make_segment_edge_map
docstring_summary: Returns edge id which is closest to point p.
          Requires execution of make_segment_edge_map
docstring_tokens: Returns edge id which is closest to point p . Requires execution of make_segment_edge_map
function: def get_closest_edge(self, p, is_get2=False, n_best=0, d_max=np.inf,
                           is_ending=True, is_detect_initial=False,
                           is_detect_final=False,
                           accesslevels=None):
          """
          Returns edge id which is closest to point p.
          Requires execution of make_segment_edge_map
          """
          # print 'get_closest_edge',p
          if len(self) == 0:
              return np.array([], np.int)
  
          if self._segvertices is None:
              self.make_segment_edge_map()
  
          vertices = self._segvertices
          x1 = vertices[:, 0, 0]
          y1 = vertices[:, 0, 1]
  
          x2 = vertices[:, 1, 0]
          y2 = vertices[:, 1, 1]
  
          # print '  x1', x1
          # print '  x2', x2
          #halfwidths = 0.5*self.get_widths_array()[self._polyinds]
          d2 = get_dist_point_to_segs(p[0:2], x1, y1, x2, y2, is_ending=is_ending,
                                      is_detect_initial=is_detect_initial,
                                      is_detect_final=is_detect_final)
  
          if is_detect_initial | is_detect_final | (not np.isinf(d_max)):
              # there may be nans if not projecting, replace by inf
              #inds_valid = np.logical_not(np.isnan(d2))
  
              # print '  ids_edge in range',set(self.get_ids(self._edgeinds[d2 < d_max**2]).tolist())
              # if 0:
              #    ind_range = d2 < d_max**2
              #    l=[]
              #    for d, id_edge in zip(np.sqrt(d2[ind_range]), self.get_ids(self._edgeinds[ind_range]) ):
              #        l.append((d, id_edge))
              #    l.sort()
              #    for  d, id_edge in l:
              #        print '    d',d,'id_edge',id_edge
  
              d2[d2 > d_max**2] = np.inf
              d2[np.isnan(d2)] = np.inf
  
              #inds_valid = ( d2<d_max**2 ) & np.logical_not(np.isnan(d2))
              # inds_valid = inds_valid[ np.flatnonzero( np.logical_not(np.isnan(d2[inds_valid]) ]
              inds_valid = np.logical_not(np.isinf(d2))
              # print '  inds_valid', np.flatnonzero(inds_valid)
              # print '  dists',np.sqrt(d2[inds_valid])
              # print '  ids_edge projecting:',set(self.get_ids(self._edgeinds[inds_valid]).tolist())
              #d2[np.isnan(d2)] = np.inf
              d2[np.logical_not(inds_valid)] = np.inf
  
          # print '  min(d)=',np.sqrt(np.min(d2)),'argmin=',np.argmin(d2),'id_edge=',self.get_ids(self._edgeinds[np.argmin(d2)])
  
          if is_get2:
              # return 2 best matches
              ind1 = np.argmin(d2)
              id_edge1 = self.get_ids(self._edgeinds[ind1])
              d2[ind1] = np.inf
              id_edge2 = self.get_ids(self._edgeinds[np.argmin(d2)])
              return [id_edge1, id_edge2]
  
          elif n_best > 0:
              ind = np.argmin(d2)
              dist2_min = d2[ind]
              if not np.isinf(dist2_min):
                  dists2_min = [dist2_min]
                  id_edge_min = self.get_ids(self._edgeinds[ind])
  
                  if accesslevels is not None:
                      # print '  id_edge_min',id_edge_min,'dists_min',np.sqrt(dists2_min),accesslevels[id_edge_min]
                      if accesslevels[id_edge_min] > -1:
                          ids_min = [id_edge_min]
                      else:
                          ids_min = []
                  else:
                      ids_min = [id_edge_min]
              else:
                  # print '  dist2_min',dist2_min,np.isinf(dist2_min)
                  return [], []
  
              # print '  min(d)=',np.sqrt(np.min(d2)),'argmin=',np.argmin(d2),'id_edge=',self.get_ids(self._edgeinds[np.argmin(d2)])
              is_cont = True
              while is_cont:
                  d2[ind] = np.inf
                  ind = np.argmin(d2)
                  dist2_min = d2[ind]
                  id_edge = self.get_ids(self._edgeinds[ind])
                  # print '  check id_edge',id_edge
                  if np.isinf(dist2_min):
                      is_cont = False
                  elif id_edge not in ids_min:
                      # print '  min(d)=',np.sqrt(np.min(d2)),'argmin=',np.argmin(d2),'id_edge=',self.get_ids(self._edgeinds[np.argmin(d2)])
                      #dist2_min = d2[ind]
                      if accesslevels is not None:
                          # print '  id_edge_min',id_edge,'dists_min',np.sqrt(dists2_min),accesslevels[id_edge]
                          if accesslevels[id_edge] > -1:
                              dists2_min.append(dist2_min)
                              ids_min.append(id_edge)
                      else:
                          dists2_min.append(dist2_min)
                          ids_min.append(id_edge)
  
                  if len(dists2_min) == n_best:
                      is_cont = False
              # print '  found ids_edge',ids_min
              return ids_min, np.sqrt(dists2_min)
  
          else:
              return self.get_ids(self._edgeinds[np.argmin(d2)])
function_tokens: def get_closest_edge ( self , p , is_get2 = False , n_best = 0 , d_max = np . inf , is_ending = True , is_detect_initial = False , is_detect_final = False , accesslevels = None ) : # print 'get_closest_edge',p if len ( self ) == 0 : return np . array ( [ ] , np . int ) if self . _segvertices is None : self . make_segment_edge_map ( ) vertices = self . _segvertices x1 = vertices [ : , 0 , 0 ] y1 = vertices [ : , 0 , 1 ] x2 = vertices [ : , 1 , 0 ] y2 = vertices [ : , 1 , 1 ] # print '  x1', x1 # print '  x2', x2 #halfwidths = 0.5*self.get_widths_array()[self._polyinds] d2 = get_dist_point_to_segs ( p [ 0 : 2 ] , x1 , y1 , x2 , y2 , is_ending = is_ending , is_detect_initial = is_detect_initial , is_detect_final = is_detect_final ) if is_detect_initial | is_detect_final | ( not np . isinf ( d_max ) ) : # there may be nans if not projecting, replace by inf #inds_valid = np.logical_not(np.isnan(d2)) # print '  ids_edge in range',set(self.get_ids(self._edgeinds[d2 < d_max**2]).tolist()) # if 0: #    ind_range = d2 < d_max**2 #    l=[] #    for d, id_edge in zip(np.sqrt(d2[ind_range]), self.get_ids(self._edgeinds[ind_range]) ): #        l.append((d, id_edge)) #    l.sort() #    for  d, id_edge in l: #        print '    d',d,'id_edge',id_edge d2 [ d2 > d_max ** 2 ] = np . inf d2 [ np . isnan ( d2 ) ] = np . inf #inds_valid = ( d2<d_max**2 ) & np.logical_not(np.isnan(d2)) # inds_valid = inds_valid[ np.flatnonzero( np.logical_not(np.isnan(d2[inds_valid]) ] inds_valid = np . logical_not ( np . isinf ( d2 ) ) # print '  inds_valid', np.flatnonzero(inds_valid) # print '  dists',np.sqrt(d2[inds_valid]) # print '  ids_edge projecting:',set(self.get_ids(self._edgeinds[inds_valid]).tolist()) #d2[np.isnan(d2)] = np.inf d2 [ np . logical_not ( inds_valid ) ] = np . inf # print '  min(d)=',np.sqrt(np.min(d2)),'argmin=',np.argmin(d2),'id_edge=',self.get_ids(self._edgeinds[np.argmin(d2)]) if is_get2 : # return 2 best matches ind1 = np . argmin ( d2 ) id_edge1 = self . get_ids ( self . _edgeinds [ ind1 ] ) d2 [ ind1 ] = np . inf id_edge2 = self . get_ids ( self . _edgeinds [ np . argmin ( d2 ) ] ) return [ id_edge1 , id_edge2 ] elif n_best > 0 : ind = np . argmin ( d2 ) dist2_min = d2 [ ind ] if not np . isinf ( dist2_min ) : dists2_min = [ dist2_min ] id_edge_min = self . get_ids ( self . _edgeinds [ ind ] ) if accesslevels is not None : # print '  id_edge_min',id_edge_min,'dists_min',np.sqrt(dists2_min),accesslevels[id_edge_min] if accesslevels [ id_edge_min ] > - 1 : ids_min = [ id_edge_min ] else : ids_min = [ ] else : ids_min = [ id_edge_min ] else : # print '  dist2_min',dist2_min,np.isinf(dist2_min) return [ ] , [ ] # print '  min(d)=',np.sqrt(np.min(d2)),'argmin=',np.argmin(d2),'id_edge=',self.get_ids(self._edgeinds[np.argmin(d2)]) is_cont = True while is_cont : d2 [ ind ] = np . inf ind = np . argmin ( d2 ) dist2_min = d2 [ ind ] id_edge = self . get_ids ( self . _edgeinds [ ind ] ) # print '  check id_edge',id_edge if np . isinf ( dist2_min ) : is_cont = False elif id_edge not in ids_min : # print '  min(d)=',np.sqrt(np.min(d2)),'argmin=',np.argmin(d2),'id_edge=',self.get_ids(self._edgeinds[np.argmin(d2)]) #dist2_min = d2[ind] if accesslevels is not None : # print '  id_edge_min',id_edge,'dists_min',np.sqrt(dists2_min),accesslevels[id_edge] if accesslevels [ id_edge ] > - 1 : dists2_min . append ( dist2_min ) ids_min . append ( id_edge ) else : dists2_min . append ( dist2_min ) ids_min . append ( id_edge ) if len ( dists2_min ) == n_best : is_cont = False # print '  found ids_edge',ids_min return ids_min , np . sqrt ( dists2_min ) else : return self . get_ids ( self . _edgeinds [ np . argmin ( d2 ) ] )