@Test
  public void testBackrefrenceForWay_Full() throws OsmTransferException {
    Way w = lookupWay(ds, 1);
    assertNotNull(w);
    // way with name "way-1" is referred to by two relations
    //

    OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(w);
    reader.setReadFull(true);
    DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
    assertEquals(6, referers.getWays().size()); // 6 ways referred by two relations
    for (Way w1 : referers.getWays()) {
      assertEquals(false, w1.isIncomplete());
    }
    assertEquals(2, referers.getRelations().size()); // two relations referring to
    Set<Long> expectedNodeIds = new HashSet<Long>();
    for (Way way : referers.getWays()) {
      Way orig = (Way) ds.getPrimitiveById(way);
      for (Node n : orig.getNodes()) {
        expectedNodeIds.add(n.getId());
      }
    }
    assertEquals(expectedNodeIds.size(), referers.getNodes().size());
    for (Node n : referers.getNodes()) {
      assertEquals(true, expectedNodeIds.contains(n.getId()));
    }

    Relation r = lookupRelation(referers, 0);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    r = lookupRelation(referers, 1);
    assertEquals(false, r.isIncomplete());
  }
Esempio n. 2
0
  public void visit(Way w) {
    if (w.isIncomplete() || w.getNodesCount() < 2) return;
    c.setStrokeStyle(w.isSelected() ? "#ff0000" : "#000000");
    c.beginPath();

    Iterator<Node> it = w.getNodes().iterator();
    if (it.hasNext()) {
      Point lastP = nc.getPoint(it.next());
      c.moveTo(lastP.x, lastP.y);

      for (int orderNumber = 1; it.hasNext(); orderNumber++) {
        Point p = nc.getPoint(it.next());
        c.lineTo(p.x, p.y);
        lastP = p;
      }
      c.stroke();
    }
  }
  @Test
  public void testBackrefrenceForNode() throws OsmTransferException {
    Node n = lookupNode(ds, 0);
    assertNotNull(n);
    Way w = lookupWay(ds, 0);
    assertNotNull(w);

    OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(n);
    reader.setReadFull(false);
    DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
    assertEquals(10, referers.getNodes().size());
    assertEquals(1, referers.getWays().size());
    assertEquals(0, referers.getRelations().size());
    for (Way way : referers.getWays()) {
      assertEquals(w.getId(), way.getId());
      assertEquals(false, way.isIncomplete());
    }
  }
Esempio n. 4
0
 protected void checkDistance(OsmPrimitive house, Collection<Way> street) {
   EastNorth centroid;
   if (house instanceof Node) {
     centroid = ((Node) house).getEastNorth();
   } else if (house instanceof Way) {
     List<Node> nodes = ((Way) house).getNodes();
     if (house.hasKey(ADDR_INTERPOLATION)) {
       for (Node n : nodes) {
         if (n.hasKey(ADDR_HOUSE_NUMBER)) {
           checkDistance(n, street);
         }
       }
       return;
     }
     centroid = Geometry.getCentroid(nodes);
   } else {
     return; // TODO handle multipolygon houses ?
   }
   if (centroid == null) return; // fix #8305
   double maxDistance = Main.pref.getDouble("validator.addresses.max_street_distance", 200.0);
   boolean hasIncompleteWays = false;
   for (Way streetPart : street) {
     for (Pair<Node, Node> chunk : streetPart.getNodePairs(false)) {
       EastNorth closest =
           Geometry.closestPointToSegment(
               chunk.a.getEastNorth(), chunk.b.getEastNorth(), centroid);
       if (closest.distance(centroid) <= maxDistance) {
         return;
       }
     }
     if (!hasIncompleteWays && streetPart.isIncomplete()) {
       hasIncompleteWays = true;
     }
   }
   // No street segment found near this house, report error on if the relation does not contain
   // incomplete street ways (fix #8314)
   if (hasIncompleteWays) return;
   List<OsmPrimitive> errorList = new ArrayList<OsmPrimitive>(street);
   errorList.add(0, house);
   errors.add(
       new AddressError(HOUSE_NUMBER_TOO_FAR, errorList, tr("House number too far from street")));
 }
  @Test
  public void testBackrefrenceForWay() throws OsmTransferException {
    Way w = lookupWay(ds, 1);
    assertNotNull(w);
    // way with name "way-1" is referred to by two relations
    //

    OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(w);
    reader.setReadFull(false);
    DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
    assertEquals(0, referers.getNodes().size()); // no nodes loaded
    assertEquals(6, referers.getWays().size()); // 6 ways referred by two relations
    for (Way w1 : referers.getWays()) {
      assertEquals(true, w1.isIncomplete());
    }
    assertEquals(2, referers.getRelations().size()); // two relations referring to w

    Relation r = lookupRelation(referers, 0);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    r = lookupRelation(referers, 1);
    assertEquals(false, r.isIncomplete());
  }
Esempio n. 6
0
  /**
   * Merge an incomplete way with two incomplete nodes into an empty dataset.
   *
   * <p>Use case: a way loaded with a multiget, i.e. GET /api/0.6/ways?ids=123456
   */
  @Test
  public void newIncompleteWay() {

    Node n1 = new Node(1);
    their.addPrimitive(n1);

    Node n2 = new Node(2);
    their.addPrimitive(n2);

    Way w3 = new Way(3);
    w3.setNodes(Arrays.asList(n1, n2));
    their.addPrimitive(w3);
    assertTrue(w3.isIncomplete());

    DataSetMerger visitor = new DataSetMerger(my, their);
    visitor.merge();

    assertEquals(0, visitor.getConflicts().size());

    OsmPrimitive p = my.getPrimitiveById(1, OsmPrimitiveType.NODE);
    assertNotNull(p);
    assertTrue(p.isIncomplete());
    p = my.getPrimitiveById(2, OsmPrimitiveType.NODE);
    assertNotNull(p);
    assertTrue(p.isIncomplete());
    p = my.getPrimitiveById(3, OsmPrimitiveType.WAY);
    assertNotNull(p);
    assertTrue(p.isIncomplete());

    Way w = (Way) my.getPrimitiveById(3, OsmPrimitiveType.WAY);
    assertNotNull(w);
    assertTrue(p.isIncomplete());
    assertEquals(2, w.getNodesCount());
    assertTrue(w.getNode(0).isIncomplete());
    assertTrue(w.getNode(1).isIncomplete());
  }
  @Test
  public void testBackrefrenceForRelation_Full() throws OsmTransferException {
    Relation r = lookupRelation(ds, 1);
    assertNotNull(r);
    // way with name "relation-1" is referred to by four relations:
    //    relation-6, relation-7, relation-8, relation-9
    //

    OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(r);
    reader.setReadFull(true);
    DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);

    Set<Long> referringRelationsIds = new HashSet<Long>();
    r = lookupRelation(referers, 6);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 7);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 8);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 9);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());

    // all relations are fully loaded
    //
    for (Relation r1 : referers.getRelations()) {
      assertEquals(false, r1.isIncomplete());
    }

    // make sure we read all ways referred to by parent relations. These
    // ways are completely read after reading the relations
    //
    Set<Long> expectedWayIds = new HashSet<Long>();
    for (RelationMember m : lookupRelation(ds, 6).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 7).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 8).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 9).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (long id : expectedWayIds) {
      Way w = (Way) referers.getPrimitiveById(id, OsmPrimitiveType.WAY);
      assertNotNull(w);
      assertEquals(false, w.isIncomplete());
    }

    Set<Long> expectedNodeIds = new HashSet<Long>();
    for (int i = 6; i < 10; i++) {
      Relation r1 = lookupRelation(ds, i);
      expectedNodeIds.addAll(getNodeIdsInRelation(r1));
    }

    assertEquals(expectedNodeIds.size(), referers.getNodes().size());
    for (Node n : referers.getNodes()) {
      assertEquals(true, expectedNodeIds.contains(n.getId()));
    }
  }
  @Test
  public void testBackrefrenceForRelation() throws OsmTransferException {
    Relation r = lookupRelation(ds, 1);
    assertNotNull(r);
    // way with name "relation-1" is referred to by four relations:
    //    relation-6, relation-7, relation-8, relation-9
    //

    OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(r);
    reader.setReadFull(false);
    DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);

    Set<Long> referringRelationsIds = new HashSet<Long>();
    r = lookupRelation(referers, 6);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 7);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 8);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 9);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());

    for (Relation r1 : referers.getRelations()) {
      if (!referringRelationsIds.contains(r1.getId())) {
        assertEquals(true, r1.isIncomplete());
      }
    }

    // make sure we read all ways referred to by parent relations. These
    // ways are incomplete after reading.
    //
    Set<Long> expectedWayIds = new HashSet<Long>();
    for (RelationMember m : lookupRelation(ds, 6).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 7).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 8).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 9).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }

    assertEquals(expectedWayIds.size(), referers.getWays().size());
    for (Way w1 : referers.getWays()) {
      assertEquals(true, expectedWayIds.contains(w1.getId()));
      assertEquals(true, w1.isIncomplete());
    }

    // make sure we didn't read any nodes
    //
    assertEquals(0, referers.getNodes().size());
  }
Esempio n. 9
0
  /**
   * Formats a name for a way
   *
   * @param way the way
   * @return the name
   */
  @Override
  public String format(Way way) {
    StringBuilder name = new StringBuilder();
    if (way.isIncomplete()) {
      name.append(tr("incomplete"));
    } else {
      TaggingPreset preset = TaggingPresetNameTemplateList.getInstance().findPresetTemplate(way);
      if (preset == null) {
        String n;
        if (Main.pref.getBoolean("osm-primitives.localize-name", true)) {
          n = way.getLocalName();
        } else {
          n = way.getName();
        }
        if (n == null) {
          n = way.get("ref");
        }
        if (n == null) {
          n =
              (way.get("highway") != null)
                  ? tr("highway")
                  : (way.get("railway") != null)
                      ? tr("railway")
                      : (way.get("waterway") != null)
                          ? tr("waterway")
                          : (way.get("landuse") != null) ? tr("landuse") : null;
        }
        if (n == null) {
          String s;
          if ((s = way.get("addr:housename")) != null) {
            /* I18n: name of house as parameter */
            n = tr("House {0}", s);
          }
          if (n == null && (s = way.get("addr:housenumber")) != null) {
            String t = way.get("addr:street");
            if (t != null) {
              /* I18n: house number, street as parameter, number should remain
              before street for better visibility */
              n = tr("House number {0} at {1}", s, t);
            } else {
              /* I18n: house number as parameter */
              n = tr("House number {0}", s);
            }
          }
        }
        if (n == null && way.get("building") != null) n = tr("building");
        if (n == null || n.length() == 0) {
          n = String.valueOf(way.getId());
        }

        name.append(n);
      } else {
        preset.nameTemplate.appendText(name, way);
      }

      int nodesNo = way.getRealNodesCount();
      /* note: length == 0 should no longer happen, but leave the bracket code
      nevertheless, who knows what future brings */
      /* I18n: count of nodes as parameter */
      String nodes = trn("{0} node", "{0} nodes", nodesNo, nodesNo);
      name.append(" (").append(nodes).append(")");
    }
    decorateNameWithId(name, way);

    String result = name.toString();
    for (NameFormatterHook hook : formatHooks) {
      String hookResult = hook.checkFormat(way, result);
      if (hookResult != null) return hookResult;
    }

    return result;
  }