public synchronized void initIndexes() {
   if (vertexIndex != null) {
     return;
   }
   graphService.setLoadLevel(LoadLevel.DEBUG);
   Graph graph = graphService.getGraph();
   vertexIndex = new STRtree();
   edgeIndex = new STRtree();
   for (Vertex v : graph.getVertices()) {
     Envelope vertexEnvelope = new Envelope(v.getCoordinate());
     vertexIndex.insert(vertexEnvelope, v);
     for (Edge e : v.getOutgoing()) {
       Envelope envelope;
       Geometry geometry = e.getGeometry();
       if (geometry == null) {
         envelope = vertexEnvelope;
       } else {
         envelope = geometry.getEnvelopeInternal();
       }
       edgeIndex.insert(envelope, e);
     }
   }
   vertexIndex.build();
   edgeIndex.build();
 }
 /*
  * Iterate through all vertices and their (outgoing) edges. If they are of 'interesting' types, add them to the corresponding spatial index.
  */
 public synchronized void buildSpatialIndex() {
   vertexIndex = new STRtree();
   edgeIndex = new STRtree();
   Envelope env;
   // int xminx, xmax, ymin, ymax;
   for (Vertex v : graph.getVertices()) {
     Coordinate c = v.getCoordinate();
     env = new Envelope(c);
     vertexIndex.insert(env, v);
     for (Edge e : v.getOutgoing()) {
       if (e.getGeometry() == null) continue;
       if (e instanceof PatternEdge || e instanceof StreetTransitLink || e instanceof StreetEdge) {
         env = e.getGeometry().getEnvelopeInternal();
         edgeIndex.insert(env, e);
       }
     }
   }
   vertexIndex.build();
   edgeIndex.build();
 }
Esempio n. 3
0
 /**
  * areaTree全国区域拓扑树初始化
  *
  * @param fileName
  * @throws Exception void
  */
 public static void buildTree(String fileName) throws Exception {
   FileInputStream fis = new FileInputStream(new File(fileName));
   BufferedReader br = new BufferedReader(new InputStreamReader(fis, "utf-8"));
   String line = null;
   AreaNode node = null;
   while ((line = br.readLine()) != null) { // 读取区域文件
     String[] lines = line.split(";");
     Geometry polygon = new WKTReader().read(lines[lines.length - 1]);
     node = new AreaNode(); // 创建节点
     node.setAreaCode(Long.parseLong(lines[0]));
     node.setAreaName(lines[1]);
     node.setPolygon(polygon);
     areaTree.insert(polygon.getEnvelopeInternal(), node); // 向树上添加节点
   }
   fis.close();
   br.close();
   areaTree.build(); // 构建树
 }
Esempio n. 4
0
  /*
   * Builds geographic geoIndex from list of sensors currently loaded in the system
   * */
  public static void buildGeoIndex() {

    geoIndex = new STRtree();
    geometryFactory = new GeometryFactory();
    sensors = new Vector<String>();
    coordinates = new Vector<Point>();

    getListOfSensors();

    for (int i = 0; i < sensors.size(); i++) {
      geoIndex.insert(coordinates.get(i).getEnvelopeInternal(), coordinates.get(i));
      logger.warn(
          sensors.get(i)
              + " : "
              + coordinates.get(i)
              + " : "
              + searchForSensors_String(coordinates.get(i)));
    }
    geoIndex.build();
  }
  @SuppressWarnings("unchecked")
  public Map<NBStop, List<Stop>> getPotentialStopMatches(
      List<NBRoute> nbRoutes, Collection<Stop> gtfsStops) {

    Map<String, NBStop> nbStopsByTag = getStopsByTag(nbRoutes);

    STRtree tree = new STRtree(gtfsStops.size());
    for (Stop stop : gtfsStops) {
      tree.insert(new Envelope(new Coordinate(stop.getLon(), stop.getLat())), stop);
    }
    tree.build();

    Map<NBStop, List<Stop>> potentialMatches = new HashMap<NBStop, List<Stop>>();
    int stopsWithNoMatches = 0;
    for (NBStop nbStop : nbStopsByTag.values()) {
      CoordinateBounds b =
          SphericalGeometryLibrary.bounds(
              nbStop.getLat(), nbStop.getLon(), _stopMatchingDistanceThreshold);
      Envelope env = new Envelope(b.getMinLon(), b.getMaxLon(), b.getMinLat(), b.getMaxLat());
      List<Stop> stopsInEnvelope = tree.query(env);
      if (stopsInEnvelope.isEmpty()) {
        _log.warn(
            "stop with no match: tag="
                + nbStop.getTag()
                + " lat="
                + nbStop.getLat()
                + " lon="
                + nbStop.getLon());
        stopsWithNoMatches++;
      }
      potentialMatches.put(nbStop, stopsInEnvelope);
    }

    if (stopsWithNoMatches > 0) {
      _log.warn("stops without matches: " + stopsWithNoMatches + "/" + nbStopsByTag.size());
    }

    return potentialMatches;
  }