Пример #1
0
 public List<GeocodingResult> reverseGeocodingSearch(RoutingContext ctx, double lat, double lon)
     throws IOException {
   RoutePlannerFrontEnd rp = new RoutePlannerFrontEnd(false);
   List<GeocodingResult> lst = new ArrayList<GeocodingUtilities.GeocodingResult>();
   List<RouteSegmentPoint> listR = new ArrayList<BinaryRoutePlanner.RouteSegmentPoint>();
   rp.findRouteSegment(lat, lon, ctx, listR);
   double distSquare = 0;
   TLongHashSet set = new TLongHashSet();
   Set<String> streetNames = new HashSet<String>();
   for (RouteSegmentPoint p : listR) {
     RouteDataObject road = p.getRoad();
     if (!set.add(road.getId())) {
       continue;
     }
     //			System.out.println(road.toString() +  " " + Math.sqrt(p.distSquare));
     boolean emptyName =
         Algorithms.isEmpty(road.getName()) && Algorithms.isEmpty(road.getRef("", false, true));
     if (!emptyName) {
       if (distSquare == 0 || distSquare > p.distSquare) {
         distSquare = p.distSquare;
       }
       GeocodingResult sr = new GeocodingResult();
       sr.searchPoint = new LatLon(lat, lon);
       sr.streetName =
           Algorithms.isEmpty(road.getName()) ? road.getRef("", false, true) : road.getName();
       sr.point = p;
       sr.connectionPoint =
           new LatLon(MapUtils.get31LatitudeY(p.preciseY), MapUtils.get31LongitudeX(p.preciseX));
       sr.regionFP = road.region.getFilePointer();
       sr.regionLen = road.region.getLength();
       if (streetNames.add(sr.streetName)) {
         lst.add(sr);
       }
     }
     if (p.distSquare
             > STOP_SEARCHING_STREET_WITH_MULTIPLIER_RADIUS
                 * STOP_SEARCHING_STREET_WITH_MULTIPLIER_RADIUS
         && distSquare != 0
         && p.distSquare > THRESHOLD_MULTIPLIER_SKIP_STREETS_AFTER * distSquare) {
       break;
     }
     if (p.distSquare
         > STOP_SEARCHING_STREET_WITHOUT_MULTIPLIER_RADIUS
             * STOP_SEARCHING_STREET_WITHOUT_MULTIPLIER_RADIUS) {
       break;
     }
   }
   Collections.sort(lst, GeocodingUtilities.DISTANCE_COMPARATOR);
   return lst;
 }
 private void readRouteTreeData(
     RouteSubregion routeTree,
     TLongArrayList idTables,
     TLongObjectHashMap<TLongArrayList> restrictions)
     throws IOException {
   routeTree.dataObjects = new ArrayList<RouteDataObject>();
   idTables.clear();
   restrictions.clear();
   List<String> stringTable = null;
   while (true) {
     int t = codedIS.readTag();
     int tag = WireFormat.getTagFieldNumber(t);
     switch (tag) {
       case 0:
         TLongObjectIterator<TLongArrayList> it = restrictions.iterator();
         while (it.hasNext()) {
           it.advance();
           int from = (int) it.key();
           RouteDataObject fromr = routeTree.dataObjects.get(from);
           fromr.restrictions = new long[it.value().size()];
           for (int k = 0; k < fromr.restrictions.length; k++) {
             int to = (int) (it.value().get(k) >> RouteDataObject.RESTRICTION_SHIFT);
             long valto =
                 (idTables.get(to) << RouteDataObject.RESTRICTION_SHIFT)
                     | ((long) it.value().get(k) & RouteDataObject.RESTRICTION_MASK);
             fromr.restrictions[k] = valto;
           }
         }
         for (RouteDataObject o : routeTree.dataObjects) {
           if (o != null) {
             if (o.id < idTables.size()) {
               o.id = idTables.get((int) o.id);
             }
             if (o.names != null && stringTable != null) {
               int[] keys = o.names.keys();
               for (int j = 0; j < keys.length; j++) {
                 o.names.put(keys[j], stringTable.get(o.names.get(keys[j]).charAt(0)));
               }
             }
           }
         }
         return;
       case RouteDataBlock.DATAOBJECTS_FIELD_NUMBER:
         int length = codedIS.readRawVarint32();
         int oldLimit = codedIS.pushLimit(length);
         RouteDataObject obj =
             readRouteDataObject(routeTree.routeReg, routeTree.left, routeTree.top);
         while (obj.id >= routeTree.dataObjects.size()) {
           routeTree.dataObjects.add(null);
         }
         routeTree.dataObjects.set((int) obj.id, obj);
         codedIS.popLimit(oldLimit);
         break;
       case RouteDataBlock.IDTABLE_FIELD_NUMBER:
         long routeId = 0;
         length = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(length);
         idLoop:
         while (true) {
           int ts = codedIS.readTag();
           int tags = WireFormat.getTagFieldNumber(ts);
           switch (tags) {
             case 0:
               break idLoop;
             case IdTable.ROUTEID_FIELD_NUMBER:
               routeId += codedIS.readSInt64();
               idTables.add(routeId);
               break;
             default:
               skipUnknownField(ts);
               break;
           }
         }
         codedIS.popLimit(oldLimit);
         break;
       case RouteDataBlock.RESTRICTIONS_FIELD_NUMBER:
         length = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(length);
         long from = 0;
         long to = 0;
         long type = 0;
         idLoop:
         while (true) {
           int ts = codedIS.readTag();
           int tags = WireFormat.getTagFieldNumber(ts);
           switch (tags) {
             case 0:
               break idLoop;
             case RestrictionData.FROM_FIELD_NUMBER:
               from = codedIS.readInt32();
               break;
             case RestrictionData.TO_FIELD_NUMBER:
               to = codedIS.readInt32();
               break;
             case RestrictionData.TYPE_FIELD_NUMBER:
               type = codedIS.readInt32();
               break;
             default:
               skipUnknownField(ts);
               break;
           }
         }
         if (!restrictions.containsKey(from)) {
           restrictions.put(from, new TLongArrayList());
         }
         restrictions.get(from).add((to << RouteDataObject.RESTRICTION_SHIFT) + type);
         codedIS.popLimit(oldLimit);
         break;
       case RouteDataBlock.STRINGTABLE_FIELD_NUMBER:
         length = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(length);
         stringTable = map.readStringTable();
         //				codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
         codedIS.popLimit(oldLimit);
         break;
       default:
         skipUnknownField(t);
         break;
     }
   }
 }
 private RouteDataObject readRouteDataObject(RouteRegion reg, int pleftx, int ptopy)
     throws IOException {
   RouteDataObject o = new RouteDataObject(reg);
   TIntArrayList pointsX = new TIntArrayList();
   TIntArrayList pointsY = new TIntArrayList();
   TIntArrayList types = new TIntArrayList();
   List<TIntArrayList> globalpointTypes = new ArrayList<TIntArrayList>();
   while (true) {
     int ts = codedIS.readTag();
     int tags = WireFormat.getTagFieldNumber(ts);
     switch (tags) {
       case 0:
         o.pointsX = pointsX.toArray();
         o.pointsY = pointsY.toArray();
         o.types = types.toArray();
         if (globalpointTypes.size() > 0) {
           o.pointTypes = new int[globalpointTypes.size()][];
           for (int k = 0; k < o.pointTypes.length; k++) {
             TIntArrayList l = globalpointTypes.get(k);
             if (l != null) {
               o.pointTypes[k] = l.toArray();
             }
           }
         }
         return o;
       case RouteData.TYPES_FIELD_NUMBER:
         int len = codedIS.readRawVarint32();
         int oldLimit = codedIS.pushLimit(len);
         while (codedIS.getBytesUntilLimit() > 0) {
           types.add(codedIS.readRawVarint32());
         }
         codedIS.popLimit(oldLimit);
         break;
       case RouteData.STRINGNAMES_FIELD_NUMBER:
         o.names = new TIntObjectHashMap<String>();
         int sizeL = codedIS.readRawVarint32();
         int old = codedIS.pushLimit(sizeL);
         while (codedIS.getBytesUntilLimit() > 0) {
           int stag = codedIS.readRawVarint32();
           int pId = codedIS.readRawVarint32();
           o.names.put(stag, ((char) pId) + "");
         }
         codedIS.popLimit(old);
         break;
       case RouteData.POINTS_FIELD_NUMBER:
         len = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(len);
         int px = pleftx >> SHIFT_COORDINATES;
         int py = ptopy >> SHIFT_COORDINATES;
         while (codedIS.getBytesUntilLimit() > 0) {
           int x = (codedIS.readSInt32()) + px;
           int y = (codedIS.readSInt32()) + py;
           pointsX.add(x << SHIFT_COORDINATES);
           pointsY.add(y << SHIFT_COORDINATES);
           px = x;
           py = y;
         }
         codedIS.popLimit(oldLimit);
         break;
       case RouteData.POINTTYPES_FIELD_NUMBER:
         len = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(len);
         while (codedIS.getBytesUntilLimit() > 0) {
           int pointInd = codedIS.readRawVarint32();
           TIntArrayList pointTypes = new TIntArrayList();
           int lens = codedIS.readRawVarint32();
           int oldLimits = codedIS.pushLimit(lens);
           while (codedIS.getBytesUntilLimit() > 0) {
             pointTypes.add(codedIS.readRawVarint32());
           }
           codedIS.popLimit(oldLimits);
           while (pointInd >= globalpointTypes.size()) {
             globalpointTypes.add(null);
           }
           globalpointTypes.set(pointInd, pointTypes);
         }
         codedIS.popLimit(oldLimit);
         break;
       case RouteData.ROUTEID_FIELD_NUMBER:
         o.id = codedIS.readInt32();
         break;
       default:
         skipUnknownField(ts);
         break;
     }
   }
 }