Logo Search packages:      
Sourcecode: navit version File versions

static struct route_info * route_find_nearest_street ( struct vehicleprofile vehicleprofile,
struct mapset ms,
struct pcoord pc 
) [static, read]

Finds the nearest street to a given coordinate.

Parameters:
ms The mapset to search in for the street
pc The coordinate to find a street nearby
Returns:
The nearest street

Definition at line 2310 of file route.c.

References street_data::c, street_data::count, vehicleprofile::flags, street_data::flags, vehicleprofile::flags_forward_mask, vehicleprofile::flags_reverse_mask, map_projection(), map_rect_destroy(), map_rect_get_item(), map_rect_new(), map_selection_destroy(), mapset_close(), mapset_next(), mapset_open(), pcoord::pro, route_rect(), street_data_free(), street_get_data(), pcoord::x, coord::x, pcoord::y, and coord::y.

Referenced by route_set_destination(), and route_set_position().

{
      struct route_info *ret=NULL;
      int max_dist=1000;
      struct map_selection *sel;
      int dist,mindist=0,pos;
      struct mapset_handle *h;
      struct map *m;
      struct map_rect *mr;
      struct item *item;
      struct coord lp;
      struct street_data *sd;
      struct coord c;
      struct coord_geo g;

      ret=g_new0(struct route_info, 1);
      mindist = INT_MAX;

      h=mapset_open(ms);
      while ((m=mapset_next(h,1))) {
            c.x = pc->x;
            c.y = pc->y;
            if (map_projection(m) != pc->pro) {
                  transform_to_geo(pc->pro, &c, &g);
                  transform_from_geo(map_projection(m), &g, &c);
            }
            sel = route_rect(18, &c, &c, 0, max_dist);
            if (!sel)
                  continue;
            mr=map_rect_new(m, sel);
            if (!mr) {
                  map_selection_destroy(sel);
                  continue;
            }
            while ((item=map_rect_get_item(mr))) {
                  if (item_get_default_flags(item->type)) {
                        sd=street_get_data(item);
                        if (!sd)
                              continue;
                        dist=transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos);
                        if (dist < mindist && (
                              (sd->flags & vehicleprofile->flags_forward_mask) == vehicleprofile->flags ||
                              (sd->flags & vehicleprofile->flags_reverse_mask) == vehicleprofile->flags)) {
                              mindist = dist;
                              if (ret->street) {
                                    street_data_free(ret->street);
                              }
                              ret->c=c;
                              ret->lp=lp;
                              ret->pos=pos;
                              ret->street=sd;
                              dbg(1,"dist=%d id 0x%x 0x%x pos=%d\n", dist, item->id_hi, item->id_lo, pos);
                        } else {
                              street_data_free(sd);
                        }
                  }
            }
            map_selection_destroy(sel);
            map_rect_destroy(mr);
      }
      mapset_close(h);

      if (!ret->street || mindist > max_dist*max_dist) {
            if (ret->street) {
                  street_data_free(ret->street);
                  dbg(1,"Much too far %d > %d\n", mindist, max_dist);
            }
            g_free(ret);
            ret = NULL;
      }

      return ret;
}


Generated by  Doxygen 1.6.0   Back to index