@Override
  public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
    if (topic.equals("Likaci/MqttMap")) {
      String msg = new String(mqttMessage.getPayload());
      JSONObject json = new JSONObject(msg);
      if (!json.getString("id").equals(id)) {
        Point p =
            (Point)
                GeometryEngine.project(
                    new Point(json.getDouble("x"), json.getDouble("y")),
                    SpatialReference.create(4326),
                    SpatialReference.create(3857));

        layer.removeAll();

        SimpleMarkerSymbol markerSymbol =
            new SimpleMarkerSymbol(
                Color.parseColor("#763382"), 15, SimpleMarkerSymbol.STYLE.DIAMOND);
        layer.addGraphic(new Graphic(p, markerSymbol));

        TextSymbol textSymbol =
            new TextSymbol(
                15,
                json.getString("id"),
                Color.parseColor("#763382"),
                TextSymbol.HorizontalAlignment.CENTER,
                TextSymbol.VerticalAlignment.MIDDLE);
        textSymbol.setOffsetY(-15);
        layer.addGraphic(new Graphic(p, textSymbol));
      }
    }
  }
Example #2
0
            @Override
            public void open() throws SourceException {
              if (roads.isEmpty()) {
                for (Entry entry : entries) {
                  Polyline geometry =
                      (Polyline)
                          GeometryEngine.geometryFromWkt(
                              entry.five(), WktImportFlags.wktImportDefaults, Type.Polyline);
                  roads.add(
                      new BaseRoad(
                          entry.one(),
                          entry.two(),
                          entry.three(),
                          entry.one(),
                          entry.four(),
                          (short) 0,
                          1.0f,
                          100.0f,
                          100.0f,
                          (float) spatial.length(geometry),
                          geometry));
                }
              }

              iterator = roads.iterator();
            }
        @Override
        public void onMouseClicked(MouseEvent e) {
          Point pt = map.toMapPoint(e.getX(), e.getY());

          Geometry buffer =
              GeometryEngine.buffer(
                  pt, map.getSpatialReference(), 200000, map.getSpatialReference().getUnit());

          Graphic g = new Graphic(buffer, bufferSymbol);
          graphicsLayer.addGraphic(g);
        }
  private void updateToNewLocation(Location location) {
    gpsLayer.removeAll();
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();

    Point ptMap1 =
        (Point)
            GeometryEngine.project(
                new Point(longitude, latitude),
                SpatialReference.create(4326),
                mMapView.getSpatialReference());

    gpsLayer.addGraphic(new Graphic(ptMap1, resultIcon));

    // mMapView.zoomToScale(ptMap1, 4223);
    // mMapView.centerAt(ptMap1, true);

  }
Example #5
0
  @Override
  protected Set<Tuple<MatcherCandidate, Double>> candidates(
      Set<MatcherCandidate> predecessors, MatcherSample sample) {
    if (logger.isTraceEnabled()) {
      logger.trace(
          "finding candidates for sample {} {}",
          new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ").format(sample.time()),
          GeometryEngine.geometryToWkt(sample.point(), WktExportFlags.wktExportPoint));
    }

    Set<RoadPoint> points_ = map.spatial().radius(sample.point(), radius);
    Set<RoadPoint> points = new HashSet<RoadPoint>(Minset.minimize(points_));

    Map<Long, RoadPoint> map = new HashMap<Long, RoadPoint>();
    for (RoadPoint point : points) {
      map.put(point.edge().id(), point);
    }

    for (MatcherCandidate predecessor : predecessors) {
      RoadPoint point = map.get(predecessor.point().edge().id());
      if (point != null && point.fraction() < predecessor.point().fraction()) {
        points.remove(point);
        points.add(predecessor.point());
      }
    }

    Set<Tuple<MatcherCandidate, Double>> candidates =
        new HashSet<Tuple<MatcherCandidate, Double>>();

    logger.debug("{} ({}) candidates", points.size(), points_.size());

    for (RoadPoint point : points) {
      double dz = spatial.distance(sample.point(), point.geometry());
      double emission = 1 / sqrt_2pi_sig2 * Math.exp((-1) * dz / (2 * sig2));

      MatcherCandidate candidate = new MatcherCandidate(point);
      candidates.add(new Tuple<MatcherCandidate, Double>(candidate, emission));

      logger.trace("{} {} {}", candidate.id(), dz, emission);
    }

    return candidates;
  }
  private ArrayList<Node> createNodes() {
    ArrayList<Node> nodes = new ArrayList<>();

    String[] tables = new String[] {"mark", "xiangti", "jing", "gan", "lupaihao", "fangdajixiang"};
    for (String tableName : tables) {
      Cursor c = SQLiteAction.queryPoint(mSQLiteDatabase, tableName);
      if (c != null) {
        if (c.moveToFirst()) {
          for (int i = 0; i < c.getCount(); ++i) {
            c.moveToPosition(i);

            String synchronize = c.getString(c.getColumnIndex("synchronize"));
            if (synchronize != null && synchronize.equalsIgnoreCase("true")) {
              continue;
            }

            Node node = new Node();
            node.id = mNodeCounter;
            mNodeCounter++;

            PointBean point = new PointBean();

            point.setSynchronize(false);

            String id = c.getString(c.getColumnIndex("id"));
            if (id != null && !id.equalsIgnoreCase("")) {
              point.setId(id);
            }

            byte[] geometrys = c.getBlob(c.getColumnIndex("geometry"));
            if (geometrys != null && geometrys.length > 0) {
              Geometry geometry =
                  GeometryEngine.geometryFromEsriShape(geometrys, Geometry.Type.POINT);
              point.setGeometry(geometry);
            }

            String name = c.getString(c.getColumnIndex("name"));
            if (name != null && !name.equalsIgnoreCase("")) {
              point.setName(name);
            }

            String typeString = c.getString(c.getColumnIndex("type"));
            if (typeString != null && !typeString.equalsIgnoreCase("")) {
              Integer index = Integer.parseInt(typeString);
              PointBean.Type type = PointBean.Type.values()[index];
              point.setType(type);
            }

            String description = c.getString(c.getColumnIndex("description"));
            if (description != null && !description.equalsIgnoreCase("")) {
              point.setDescription(description);
            }

            String remark = c.getString(c.getColumnIndex("remark"));
            if (remark != null && !remark.equalsIgnoreCase("")) {
              point.setRemark(remark);
            }

            String imageId = c.getString(c.getColumnIndex("imageIds"));
            if (imageId != null && !imageId.equalsIgnoreCase("")) {
              String[] imageIds = imageId.split("#");
              point.setImageIds(imageIds);
            }

            String creator = c.getString(c.getColumnIndex("creator"));
            if (creator != null && !creator.equalsIgnoreCase("")) {
              point.setCreator(creator);
            }

            String createTime = c.getString(c.getColumnIndex("createtime"));
            if (createTime != null && !createTime.equalsIgnoreCase("")) {
              point.setCreateTime(Long.parseLong(createTime));
            }

            String lastEditor = c.getString(c.getColumnIndex("lasteditor"));
            if (lastEditor != null && !lastEditor.equalsIgnoreCase("")) {
              point.setLastEditor(lastEditor);
            }

            String modifyTime = c.getString(c.getColumnIndex("modifytime"));
            if (modifyTime != null && !modifyTime.equalsIgnoreCase("")) {
              point.setModifyTime(Long.parseLong(modifyTime));
            }

            node.point = point;
            nodes.add(node);
          }
        }
      }
    }

    return nodes;
  }
Example #7
0
  @Override
  protected Map<MatcherCandidate, Map<MatcherCandidate, Tuple<MatcherTransition, Double>>>
      transitions(
          final Tuple<MatcherSample, Set<MatcherCandidate>> predecessors,
          final Tuple<MatcherSample, Set<MatcherCandidate>> candidates) {

    if (logger.isTraceEnabled()) {
      logger.trace(
          "finding transitions for sample {} {} with {} x {} candidates",
          new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ").format(candidates.one().time()),
          GeometryEngine.geometryToWkt(candidates.one().point(), WktExportFlags.wktExportPoint),
          predecessors.two().size(),
          candidates.two().size());
    }

    Stopwatch sw = new Stopwatch();
    sw.start();

    final Set<RoadPoint> targets = new HashSet<RoadPoint>();
    for (MatcherCandidate candidate : candidates.two()) {
      targets.add(candidate.point());
    }

    final AtomicInteger count = new AtomicInteger();
    final Map<MatcherCandidate, Map<MatcherCandidate, Tuple<MatcherTransition, Double>>>
        transitions =
            new ConcurrentHashMap<
                MatcherCandidate, Map<MatcherCandidate, Tuple<MatcherTransition, Double>>>();
    final double base =
        1.0 * spatial.distance(predecessors.one().point(), candidates.one().point()) / 60;
    final double bound =
        Math.max(
            1000d,
            Math.min(
                distance, ((candidates.one().time() - predecessors.one().time()) / 1000) * 100));

    InlineScheduler scheduler = StaticScheduler.scheduler();
    for (final MatcherCandidate predecessor : predecessors.two()) {
      scheduler.spawn(
          new Task() {
            @Override
            public void run() {
              Map<MatcherCandidate, Tuple<MatcherTransition, Double>> map =
                  new HashMap<MatcherCandidate, Tuple<MatcherTransition, Double>>();
              Stopwatch sw = new Stopwatch();
              sw.start();
              Map<RoadPoint, List<Road>> routes =
                  router.route(predecessor.point(), targets, cost, new Distance(), bound);
              sw.stop();

              logger.trace("{} routes ({} ms)", routes.size(), sw.ms());

              for (MatcherCandidate candidate : candidates.two()) {
                List<Road> edges = routes.get(candidate.point());

                if (edges == null) {
                  continue;
                }

                Route route = new Route(predecessor.point(), candidate.point(), edges);

                // According to Newson and Krumm 2009, transition probability is lambda *
                // Math.exp((-1.0) * lambda * Math.abs(dt - route.length())), however, we
                // experimentally choose lambda * Math.exp((-1.0) * lambda * Math.max(0,
                // route.length() - dt)) to avoid unnecessary routes in case of u-turns.

                double beta =
                    lambda == 0
                        ? (2.0
                            * Math.max(1d, candidates.one().time() - predecessors.one().time())
                            / 1000)
                        : 1 / lambda;

                double transition =
                    (1 / beta)
                        * Math.exp(
                            (-1.0) * Math.max(0, route.cost(new TimePriority()) - base) / beta);

                map.put(
                    candidate,
                    new Tuple<MatcherTransition, Double>(new MatcherTransition(route), transition));

                logger.trace(
                    "{} -> {} {} {} {}",
                    predecessor.id(),
                    candidate.id(),
                    base,
                    route.length(),
                    transition);
                count.incrementAndGet();
              }

              transitions.put(predecessor, map);
            }
          });
    }
    if (!scheduler.sync()) {
      throw new RuntimeException();
    }

    sw.stop();

    logger.trace("{} transitions ({} ms)", count.get(), sw.ms());

    return transitions;
  }