Exemple #1
0
  /** {@inheritDoc} */
  @Override
  public void modifyEntity(Node entity) {
    super.modifyEntity(entity);

    if (capabilityChecker.isWayBboxSupported()) {
      jdbcTemplate.update(SQL_UPDATE_WAY_BBOX, entity.getId());
    }

    if (capabilityChecker.isWayLinestringSupported()) {
      jdbcTemplate.update(SQL_UPDATE_WAY_LINESTRING, entity.getId());
    }
  }
Exemple #2
0
  /**
   * Compares this node to the specified node. The node comparison is based on a comparison of id,
   * version, latitude, longitude, timestamp and tags in that order.
   *
   * @param comparisonNode The node to compare to.
   * @return 0 if equal, < 0 if considered "smaller", and > 0 if considered "bigger".
   */
  public int compareTo(Node comparisonNode) {
    if (this.getId() < comparisonNode.getId()) {
      return -1;
    }

    if (this.getId() > comparisonNode.getId()) {
      return 1;
    }

    if (this.getVersion() < comparisonNode.getVersion()) {
      return -1;
    }

    if (this.getVersion() > comparisonNode.getVersion()) {
      return 1;
    }

    if (this.latitude < comparisonNode.latitude) {
      return -1;
    }

    if (this.latitude > comparisonNode.latitude) {
      return 1;
    }

    if (this.longitude < comparisonNode.longitude) {
      return -1;
    }

    if (this.longitude > comparisonNode.longitude) {
      return 1;
    }

    if (this.getTimestamp() == null && comparisonNode.getTimestamp() != null) {
      return -1;
    }
    if (this.getTimestamp() != null && comparisonNode.getTimestamp() == null) {
      return 1;
    }
    if (this.getTimestamp() != null && comparisonNode.getTimestamp() != null) {
      int result;

      result = this.getTimestamp().compareTo(comparisonNode.getTimestamp());

      if (result != 0) {
        return result;
      }
    }

    return compareTags(comparisonNode.getTags());
  }
Exemple #3
0
 /**
  * ${@inheritDoc}.
  *
  * @see
  *     org.openstreetmap.osm.data.IDataSet#containsNode(org.openstreetmap.osmosis.core.domain.v0_5.Node)
  */
 public boolean containsNode(final Node aW) {
   if (myCachingDataSet.containsNode(aW)) return true;
   Node n = myDataSource.getNodeByID(aW.getId());
   if (n == null) return false;
   cacheNode(n);
   return true;
 }
  private boolean isRequiredNode(Node node) {
    long nodeId = node.getId();

    if (requiredNodes.get(nodeId)) return true;

    return usedByTag && !isEmptyTagSet(node.getTags());
  }
Exemple #5
0
  /**
   * We have to get all ways for each node cached to get no inconsistencies when {@link
   * #getWaysForNode(long)} is called.
   *
   * @param n the node to add to {@link #myCachingDataSet}.
   */
  private void cacheNode(final Node n) {
    myCachingDataSet.addNode(n);

    Iterator<Way> ways = myDataSource.getWaysForNode(n.getId());
    if (ways != null && ways.hasNext()) {
      while (ways.hasNext()) {
        Way way = ways.next();
        myCachingDataSet.addWay(way);
      }
    }
  }
 /** ${@inheritDoc}. */
 @Override
 public boolean isAllowed(final IDataSet aMap, final Node aNode) {
   Iterator<Way> ways = aMap.getWaysForNode(aNode.getId());
   if (ways != null) {
     while (ways.hasNext()) {
       if (isAllowed(aMap, ways.next())) {
         return true;
       }
     }
   }
   return false;
 }
 protected void saveAllNodes(List<Node> nodes) {
   BulkRequestBuilder bulkRequest = client.prepareBulk();
   for (Node node : nodes) {
     try {
       ESNode esNode = ESNode.Builder.buildFromEntity(node);
       bulkRequest.add(
           client
               .prepareIndex(
                   indexName, esNode.getEntityType().getIndiceName(), esNode.getIdString())
               .setSource(esNode.toJson()));
     } catch (Exception exception) {
       LOG.warning(
           String.format(
               "Unable to add Entity %s to bulk request, cause: %s",
               node.getId(), exception.getMessage()));
     }
   }
   executeBulkRequest(bulkRequest);
 }
  private void convertToOwnRepresentation() {

    ownNodes = new ArrayList<OSMNode>(nodesById.size());
    ownWays = new ArrayList<OSMWay>(waysById.size());
    ownRelations = new ArrayList<OSMRelation>(relationsById.size());

    Map<Node, OSMNode> nodeMap = new HashMap<Node, OSMNode>();
    Map<Way, OSMWay> wayMap = new HashMap<Way, OSMWay>();
    Map<Relation, OSMRelation> relationMap = new HashMap<Relation, OSMRelation>();

    for (Node node : nodesById.values()) {

      OSMNode ownNode =
          new OSMNode(
              node.getLatitude(), node.getLongitude(), tagGroupForEntity(node), node.getId());

      ownNodes.add(ownNode);
      nodeMap.put(node, ownNode);
    }

    for (Way way : waysById.values()) {

      List<WayNode> origWayNodes = way.getWayNodes();
      List<OSMNode> wayNodes = new ArrayList<OSMNode>(origWayNodes.size());
      for (WayNode origWayNode : origWayNodes) {
        Node origNode = nodesById.get(origWayNode.getNodeId());
        if (origNode != null) {
          wayNodes.add(nodeMap.get(origNode));
        }
      }

      OSMWay ownWay = new OSMWay(tagGroupForEntity(way), way.getId(), wayNodes);

      ownWays.add(ownWay);
      wayMap.put(way, ownWay);
    }

    for (Relation relation : relationsById.values()) {

      OSMRelation ownRelation =
          new OSMRelation(
              tagGroupForEntity(relation), relation.getId(), relation.getMembers().size());

      ownRelations.add(ownRelation);
      relationMap.put(relation, ownRelation);
    }

    // add relation members
    // (needs to be done *after* creation because relations can be members
    // of other relations)

    for (Relation relation : relationMap.keySet()) {

      OSMRelation ownRelation = relationMap.get(relation);

      for (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember member :
          relation.getMembers()) {

        OSMElement memberObject = null;
        if (member.getMemberType() == EntityType.Node) {
          memberObject = nodeMap.get(nodesById.get(member.getMemberId()));
        } else if (member.getMemberType() == EntityType.Way) {
          memberObject = wayMap.get(waysById.get(member.getMemberId()));
        } else if (member.getMemberType() == EntityType.Relation) {
          memberObject = relationMap.get(relationsById.get(member.getMemberId()));
        } else {
          continue;
        }

        if (memberObject != null) {

          OSMMember ownMember = new OSMMember(member.getMemberRole(), memberObject);

          ownRelation.relationMembers.add(ownMember);
        }
      }
    }

    // give up references to original collections

    nodesById = null;
    waysById = null;
    relationsById = null;
  }