コード例 #1
0
  private boolean isRequiredNode(Node node) {
    long nodeId = node.getId();

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

    return usedByTag && !isEmptyTagSet(node.getTags());
  }
コード例 #2
0
  /**
   * @param nodeA the node to compure the distance for
   * @return the distance
   */
  private double getMetric(final Node nodeA) {
    double dist =
        Coordinate.distance(
            nodeA.getLatitude(), nodeA.getLongitude(),
            this.targetNode.getLatitude(), this.targetNode.getLongitude());

    return dist;
  }
コード例 #3
0
ファイル: NodeDao.java プロジェクト: junwuwei/osmosis
  /** {@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());
    }
  }
コード例 #4
0
ファイル: LoadingDataSet.java プロジェクト: tfreese/misc
 /**
  * ${@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;
 }
コード例 #5
0
ファイル: Node.java プロジェクト: junwuwei/osmosis
  /**
   * 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());
  }
コード例 #6
0
 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);
 }
コード例 #7
0
ファイル: LoadingDataSet.java プロジェクト: tfreese/misc
  /**
   * 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);
      }
    }
  }
コード例 #8
0
 /** ${@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;
 }
コード例 #9
0
  /**
   * Determines if a way lies within the bounding box.
   *
   * @param boundingBox The bounding box.
   * @param nodes The ordered nodes of the way in order.
   * @return True if the way is at least partially within the box.
   */
  private boolean isWayInsideBox(Rectangle2D boundingBox, List<Node> nodes) {
    // If at least one node lies within the box, the way is inside the box.
    for (Node node : nodes) {
      if (isNodeInsideBox(boundingBox, node)) {
        return true;
      }
    }

    // Now we need to check if any of the segments cross the box.
    for (int i = 0; i < nodes.size() - 1; i++) {
      Node nodeA;
      Node nodeB;

      nodeA = nodes.get(i);
      nodeB = nodes.get(i + 1);

      if (boundingBox.intersectsLine(
          nodeA.getLongitude(), nodeA.getLatitude(), nodeB.getLongitude(), nodeB.getLatitude())) {
        return true;
      }
    }

    return false;
  }
コード例 #10
0
 /**
  * Determines if a node lies within the bounding box.
  *
  * @param boundingBox The bounding box.
  * @param node The node to be checked.
  * @return True if the node lies within the box.
  */
 private boolean isNodeInsideBox(Rectangle2D boundingBox, Node node) {
   return boundingBox.contains(node.getLongitude(), node.getLatitude());
 }
コード例 #11
0
ファイル: OsmosisReader.java プロジェクト: tordanik/OSM2World
  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;
  }