Пример #1
0
  public void produceRelation(HashSet<Channel> subset, int n) {
    if (isProduced(subset)) {
      return;
    }
    LinkedList<OsmPrimitive> ways = new LinkedList<OsmPrimitive>();
    Iterator<Channel> cit = subset.iterator();
    while (cit.hasNext()) {
      Channel c = cit.next();
      // System.out.println(c.getWay().getId());
      if (!(ways.contains(
          plugin.getOsmlayer().data.getPrimitiveById(c.getWay().getId(), OsmPrimitiveType.WAY)))) {
        ways.add(
            plugin.getOsmlayer().data.getPrimitiveById(c.getWay().getId(), OsmPrimitiveType.WAY));
      }
    }
    Main.map.mapView.setActiveLayer(plugin.getOsmlayer());
    plugin.getOsmlayer().data.setSelected(ways);

    Relation jrelation = new Relation();
    jrelation.put("type", "junction");
    jrelation.put("n", Integer.toString(n));
    for (int i = 0; i < ways.size(); i++) {
      jrelation.addMember(new RelationMember("part of", ways.get(i)));
    }

    plugin.getOsmlayer().data.addPrimitive(jrelation);
  }
Пример #2
0
 protected Relation createRouteMaster(LineType line) {
   Relation r = createPtRelation(OSM_ROUTE_MASTER, line);
   switch (line.getTransportModeName()) {
     case BUS:
       r.put(OSM_ROUTE_MASTER, OSM_BUS);
       break;
     case AIR:
       r.put(OSM_ROUTE_MASTER, OSM_AERIALWAY);
       break;
     case FERRY:
       r.put(OSM_ROUTE_MASTER, OSM_FERRY);
       break;
     case METRO:
       r.put(OSM_ROUTE_MASTER, OSM_SUBWAY);
       break;
     case TRAIN:
       r.put(OSM_ROUTE_MASTER, OSM_TRAIN);
       break;
     case TRAMWAY:
       r.put(OSM_ROUTE_MASTER, OSM_TRAM);
       break;
     case TROLLEYBUS:
       r.put(OSM_ROUTE_MASTER, OSM_TROLLEYBUS);
       break;
     default:
       Main.warn("Unsupported transport mode: " + line.getTransportModeName());
   }
   r.put("ref", line.getNumber());
   r.put(
       "name",
       line.getTransportModeName().value() + " " + line.getNumber() + ": " + line.getName());
   return r;
 }
 @Override
 public void updateDataSet(DataSet ds) {
   for (Relation r : ds.getRelations()) {
     replace(r, "TEXT", "name");
     r.put("polling_station", "2012");
     r.put("building", "yes");
     String name = r.getName();
     if (name != null) {
       if (name.contains("ECOLE") || name.contains("MATERNELLE")) {
         r.put("amenity", "school");
       } else if (name.contains("MAIRIE")) {
         r.put("amenity", "townhall");
       } else if (name.contains("PISCINE")) {
         r.put("leisure", "swimming_pool");
       }
     }
   }
 }
Пример #4
0
  public void addTurn(List<Road> via, Road.End to) {
    assert equals(to.getJunction());

    Relation existing = null;
    for (Turn t : to.getTurns()) {
      if (t.getFrom().getOutgoingRoadEnd().equals(getOutgoingRoadEnd()) && t.getVia().equals(via)) {
        if (t.getFrom().equals(this)) {
          // was already added
          return;
        }

        existing = t.getRelation();
      }
    }

    final Relation r;
    if (existing == null) {
      r = new Relation();
      r.put("type", Constants.TYPE_TURNS);

      r.addMember(new RelationMember(Constants.TURN_ROLE_FROM, getOutgoingRoadEnd().getWay()));
      if (via.isEmpty()) {
        r.addMember(new RelationMember(Constants.TURN_ROLE_VIA, getOutgoingJunction().getNode()));
      } else {
        for (Way w :
            Utils.flattenVia(getOutgoingJunction().getNode(), via, to.getJunction().getNode())) {
          r.addMember(new RelationMember(Constants.TURN_ROLE_VIA, w));
        }
      }
      r.addMember(new RelationMember(Constants.TURN_ROLE_TO, to.getWay()));

      getOutgoingJunction().getNode().getDataSet().addPrimitive(r);
    } else {
      r = existing;
    }

    final String key = isExtra() ? Constants.TURN_KEY_EXTRA_LANES : Constants.TURN_KEY_LANES;
    final List<Integer> lanes = Turn.indices(r, key);
    lanes.add(getIndex());
    r.put(key, Turn.join(lanes));
  }
Пример #5
0
  /**
   * Adds the previously removed relations again to the outer way. If there are multiple
   * multipolygon relations where the joined areas were in "outer" role a new relation is created
   * instead with all members of both. This function depends on multigon relations to be valid
   * already, it won't fix them.
   *
   * @param rels List of relations with roles the (original) ways were part of
   * @param outer The newly created outer area/way
   * @param ownMultipol elements to directly add as outer
   * @param relationsToDelete set of relations to delete.
   */
  private void fixRelations(
      List<RelationRole> rels,
      Way outer,
      RelationRole ownMultipol,
      Set<Relation> relationsToDelete) {
    List<RelationRole> multiouters = new ArrayList<RelationRole>();

    if (ownMultipol != null) {
      multiouters.add(ownMultipol);
    }

    for (RelationRole r : rels) {
      if (r.rel.isMultipolygon() && r.role.equalsIgnoreCase("outer")) {
        multiouters.add(r);
        continue;
      }
      // Add it back!
      Relation newRel = new Relation(r.rel);
      newRel.addMember(new RelationMember(r.role, outer));
      cmds.add(new ChangeCommand(r.rel, newRel));
    }

    Relation newRel;
    switch (multiouters.size()) {
      case 0:
        return;
      case 1:
        // Found only one to be part of a multipolygon relation, so just add it back as well
        newRel = new Relation(multiouters.get(0).rel);
        newRel.addMember(new RelationMember(multiouters.get(0).role, outer));
        cmds.add(new ChangeCommand(multiouters.get(0).rel, newRel));
        return;
      default:
        // Create a new relation with all previous members and (Way)outer as outer.
        newRel = new Relation();
        for (RelationRole r : multiouters) {
          // Add members
          for (RelationMember rm : r.rel.getMembers())
            if (!newRel.getMembers().contains(rm)) {
              newRel.addMember(rm);
            }
          // Add tags
          for (String key : r.rel.keySet()) {
            newRel.put(key, r.rel.get(key));
          }
          // Delete old relation
          relationsToDelete.add(r.rel);
        }
        newRel.addMember(new RelationMember("outer", outer));
        cmds.add(new AddCommand(newRel));
    }
  }
Пример #6
0
  /**
   * Will add own multipolygon relation to the "previously existing" relations. Fixup is done by
   * fixRelations
   *
   * @param inner List of already closed inner ways
   * @param outer The outer way
   * @return The list of relation with roles to add own relation to
   */
  private RelationRole addOwnMultigonRelation(Collection<Way> inner, Way outer) {
    if (inner.isEmpty()) return null;
    // Create new multipolygon relation and add all inner ways to it
    Relation newRel = new Relation();
    newRel.put("type", "multipolygon");
    for (Way w : inner) {
      newRel.addMember(new RelationMember("inner", w));
    }
    cmds.add(new AddCommand(newRel));

    // We don't add outer to the relation because it will be handed to fixRelations()
    // which will then do the remaining work.
    return new RelationRole(newRel, "outer");
  }
 protected static void populateTestDataSetWithRelations(DataSet ds) {
   for (int i = 0; i < 10; i++) {
     Relation r = new Relation();
     r.put("name", "relation-" + i);
     for (int j = 0; j < 10; j++) {
       RelationMember member = new RelationMember("node-" + j, lookupNode(ds, i + j));
       r.addMember(member);
     }
     for (int j = 0; j < 5; j++) {
       RelationMember member = new RelationMember("way-" + j, lookupWay(ds, i + j));
       r.addMember(member);
     }
     if (i > 5) {
       for (int j = 0; j < 3; j++) {
         RelationMember member = new RelationMember("relation-" + j, lookupRelation(ds, j));
         logger.info(MessageFormat.format("adding relation {0} to relation {1}", j, i));
         r.addMember(member);
       }
     }
     ds.addPrimitive(r);
   }
 }
Пример #8
0
  private DataSet parse(InputStream in, ProgressMonitor instance) throws JAXBException {
    root = unmarshal(ChouettePTNetworkType.class, in);

    Relation network = createNetwork(root.getPTNetwork());

    // Parsing Stop areas
    for (StopArea sa : root.getChouetteArea().getStopArea()) {
      if (sa.getStopAreaExtension().getAreaType().equals(ChouetteAreaType.COMMERCIAL_STOP_POINT)) {
        Relation stopArea = createStopArea(sa);
        stopArea.put("name", sa.getName());
        for (String childId : sa.getContains()) {
          if (childId.contains("StopArea")) {
            StopArea child = findStopArea(childId);
            if (child == null) {
              Main.warn("Cannot find StopArea: " + childId);
            } else {
              if (child
                  .getStopAreaExtension()
                  .getAreaType()
                  .equals(ChouetteAreaType.BOARDING_POSITION)) {
                for (String grandchildId : child.getContains()) {
                  if (grandchildId.contains("StopPoint")) {
                    StopPoint grandchild = findStopPoint(grandchildId);
                    if (grandchild == null) {
                      Main.warn("Cannot find StopPoint: " + grandchildId);
                    } else {
                      if (grandchild.getLongLatType().equals(LongLatTypeType.WGS_84)) {
                        Node platform = createPlatform(grandchild);
                        stopArea.addMember(new RelationMember(OSM_PLATFORM, platform));
                      } else {
                        Main.warn("Unsupported long/lat type: " + grandchild.getLongLatType());
                      }
                    }
                  } else {
                    Main.warn("Unsupported grandchild: " + grandchildId);
                  }
                }
                String centroidId = child.getCentroidOfArea();
                AreaCentroid areaCentroid = findAreaCentroid(centroidId);
                if (areaCentroid == null) {
                  Main.warn("Cannot find AreaCentroid: " + centroidId);
                } else if (!areaCentroid.getLongLatType().equals(LongLatTypeType.WGS_84)) {
                  Main.warn("Unsupported long/lat type: " + areaCentroid.getLongLatType());
                } else {
                  for (RelationMember member : stopArea.getMembers()) {
                    // Fix stop coordinates if needed
                    if (member.getRole().equals(OSM_PLATFORM)
                        && isNullLatLon(member.getNode().getCoor())) {
                      member.getNode().setCoor(createLatLon(areaCentroid));
                    }
                  }
                }
              } else {
                Main.warn("Unsupported child type: " + child.getStopAreaExtension().getAreaType());
              }
            }

          } else if (childId.contains("StopPoint")) {
            StopPoint child = findStopPoint(childId);
            if (child == null) {
              Main.warn("Cannot find StopPoint: " + childId);
            } else {
              // TODO
              Main.info("TODO: handle StopPoint " + childId);
            }

          } else {
            Main.warn("Unsupported child: " + childId);
          }
        }
      } else if (sa.getStopAreaExtension()
          .getAreaType()
          .equals(ChouetteAreaType.BOARDING_POSITION)) {
        // Main.info("skipping StopArea with type "+sa.getStopAreaExtension().getAreaType()+":
        // "+sa.getObjectId());
      } else {
        Main.warn("Unsupported StopArea type: " + sa.getStopAreaExtension().getAreaType());
      }
    }

    Relation routeMaster = createRouteMaster(root.getChouetteLineDescription().getLine());
    network.addMember(new RelationMember(null, routeMaster));

    for (ChouetteRoute cr : root.getChouetteLineDescription().getChouetteRoute()) {
      Relation route = createRoute(cr);
      routeMaster.addMember(new RelationMember(null, route));
      for (String id : cr.getPtLinkId()) {
        PTLinkType ptlink = findPtLink(id);
        if (ptlink == null) {
          Main.warn("Cannot find PTLinkType: " + id);
        } else {
          /*StopPoint start = findStopPoint(ptlink.getStartOfLink());
          StopPoint end = findStopPoint(ptlink.getEndOfLink());*/
          OsmPrimitive start = tridentObjects.get(ptlink.getStartOfLink());
          OsmPrimitive end = tridentObjects.get(ptlink.getEndOfLink());
          if (start == null) {
            Main.warn("Cannot find start StopPoint: " + ptlink.getStartOfLink());
          } else if (start.get(OSM_PUBLIC_TRANSPORT).equals(OSM_STOP)
              || start.get(OSM_PUBLIC_TRANSPORT).equals(OSM_PLATFORM)) {
            addStopToRoute(route, start);
          }

          if (end == null) {
            Main.warn("Cannot find end StopPoint: " + ptlink.getEndOfLink());
          } else if (end.get(OSM_PUBLIC_TRANSPORT).equals(OSM_STOP)
              || end.get(OSM_PUBLIC_TRANSPORT).equals(OSM_PLATFORM)) {
            addStopToRoute(route, end);
          }
        }
      }
    }

    return ds;
  }
Пример #9
0
 protected Relation createStopArea(StopAreaType sa) {
   Relation r = createPtRelation(OSM_STOP_AREA, sa);
   r.put("name", sa.getName());
   return r;
 }
Пример #10
0
 private Relation createRoute(ChouetteRoute route) {
   Relation r = createPtRelation(OSM_ROUTE, route);
   r.put("name", route.getName());
   return r;
 }
Пример #11
0
 protected Relation createNetwork(PTNetworkType network) {
   Relation r = createRelation(OSM_NETWORK);
   linkTridentObjectToOsmPrimitive(network, r);
   r.put("name", network.getName());
   return r;
 }
Пример #12
0
 protected Relation createPtRelation(String pt, TridentObjectType object) {
   Relation r = createRelation(OSM_PUBLIC_TRANSPORT);
   r.put(OSM_PUBLIC_TRANSPORT, pt);
   linkTridentObjectToOsmPrimitive(object, r);
   return r;
 }
Пример #13
0
 protected Relation createRelation(String type) {
   Relation r = new Relation();
   r.put("type", type);
   ds.addPrimitive(r);
   return r;
 }
  /**
   * builds a large data set to be used later for testing MULTI FETCH on the server
   *
   * @return a large data set
   */
  protected static DataSet buildTestDataSet() {
    DataSet ds = new DataSet();
    ds.setVersion("0.6");

    int numNodes = 1000;
    int numWays = 1000;
    int numRelations = 1000;

    ArrayList<Node> nodes = new ArrayList<>();
    ArrayList<Way> ways = new ArrayList<>();

    // create a set of nodes
    //
    for (int i = 0; i < numNodes; i++) {
      Node n = new Node();
      n.setCoor(new LatLon(-36.6, 47.6));
      n.put("name", "node-" + i);
      ds.addPrimitive(n);
      nodes.add(n);
    }

    // create a set of ways, each with a random number of nodes
    //
    for (int i = 0; i < numWays; i++) {
      Way w = new Way();
      int numNodesInWay = 2 + (int) Math.round(Math.random() * 5);
      int start = (int) Math.round(Math.random() * numNodes);
      for (int j = 0; j < numNodesInWay; j++) {
        int idx = (start + j) % numNodes;
        Node n = nodes.get(idx);
        w.addNode(n);
      }
      w.put("name", "way-" + i);
      ds.addPrimitive(w);
      ways.add(w);
    }

    // create a set of relations each with a random number of nodes, and ways
    //
    for (int i = 0; i < numRelations; i++) {
      Relation r = new Relation();
      r.put("name", "relation-" + i);
      int numNodesInRelation = (int) Math.round(Math.random() * 10);
      int start = (int) Math.round(Math.random() * numNodes);
      for (int j = 0; j < numNodesInRelation; j++) {
        int idx = (start + j) % 500;
        Node n = nodes.get(idx);
        r.addMember(new RelationMember("role-" + j, n));
      }
      int numWaysInRelation = (int) Math.round(Math.random() * 10);
      start = (int) Math.round(Math.random() * numWays);
      for (int j = 0; j < numWaysInRelation; j++) {
        int idx = (start + j) % 500;
        Way w = ways.get(idx);
        r.addMember(new RelationMember("role-" + j, w));
      }
      ds.addPrimitive(r);
    }

    return ds;
  }