Package org.geotools.graph.structure

Examples of org.geotools.graph.structure.Node


        ViewportGraphics graphics = context.getGraphics();
        graphics.setColor( Color.BLACK);
        graphics.setLineWidth(4);
        for( Edge edge : path ){
            Object obj = edge.getObject();
            Node start = edge.getNodeA();
            Node end = edge.getNodeB();
       
            Point startPoint = (Point) start.getObject();
            Point endPoint = (Point) end.getObject();           
            java.awt.Point startPixel = context.worldToPixel( startPoint.getCoordinate() );
            java.awt.Point endPixel = context.worldToPixel( endPoint.getCoordinate() );

            graphics.drawLine(startPixel.x, startPixel.y, endPixel.x, endPixel.y);           
        }
        graphics.setColor( Color.YELLOW );
        graphics.setLineWidth(2);
        for( Edge edge : path ){
            Object obj = edge.getObject();
            Node start = edge.getNodeA();
            Node end = edge.getNodeB();
       
            Point startPoint = (Point) start.getObject();
            Point endPoint = (Point) end.getObject();           
            java.awt.Point startPixel = context.worldToPixel( startPoint.getCoordinate() );
            java.awt.Point endPixel = context.worldToPixel( endPoint.getCoordinate() );

            graphics.drawLine(startPixel.x, startPixel.y, endPixel.x, endPixel.y);           
        }
View Full Code Here


        super( targets );
    }

    @SuppressWarnings("unchecked")
    private Node findClosest( Coordinate coord ) {
        Node closest = null;
        double minDist = 0.0;

        IBlackboard mapboard = context.getMap().getBlackboard();
        if ( !mapboard.contains( "graph" ) ) {
            return null;
View Full Code Here

        return dx * dx + dy * dy;
    }

    public void onMousePressed( MapMouseEvent e ) {
        Coordinate clickPt = getContext().pixelToWorld( e.x, e.y );
        final Node n = findClosest( clickPt );
        if ( n != null ) {
            IBlackboard mapboard = context.getMap().getBlackboard();
            if ( !mapboard.contains( "waypoints" ) ) {
                mapboard.put( "waypoints", new ArrayList<Node>() );
            }
            ArrayList<Node> list = (ArrayList<Node> ) mapboard.get( "waypoints" );
            list.add( n );
            final int len = list.size();

            getContext().getSelectedLayer().refresh( null );

            final IStatusLineManager statusBar = getContext().getActionBars().getStatusLineManager();
            if ( statusBar == null ) {
                return; // shouldn't happen if the tool is being used.
            }
            getContext().updateUI( new Runnable() {
                public void run() {
                    statusBar.setErrorMessage( null );
                    statusBar.setMessage( Long.toString( len ) + ". waypoint added, node=" + n.toString() );
                }
            } );
        }
    }
View Full Code Here

            Object obj = edge.getObject();
            if( path.contains(edge)){
                graphics.setColor( Color.BLACK );
                graphics.setLineWidth(3);
            }
            Node start = edge.getNodeA();
            Node end = edge.getNodeB();
       
            Point startPoint = (Point) start.getObject();
            Point endPoint = (Point) end.getObject();           
            java.awt.Point startPixel = context.worldToPixel( startPoint.getCoordinate() );
            java.awt.Point endPixel = context.worldToPixel( endPoint.getCoordinate() );
           
            graphics.drawLine(startPixel.x, startPixel.y, endPixel.x, endPixel.y);           
            double angle = Angle.angle(startPoint.getCoordinate(), endPoint.getCoordinate());
View Full Code Here

 
  protected List buildEdges() {
    List edges = super.buildEdges();
   
    //get the edge between the first and last nodes
    Node first = (Node)get(0);
    Node last = (Node)get(size()-1);
   
    Edge e = first.getEdge(last);
    if (e != null) {
      edges.add(e);
      return(edges);
View Full Code Here

   
    for (
      Iterator itr = builder().getGraph().getNodes().iterator();
      itr.hasNext();
    ) {
      Node node = (Node)itr.next();
      if (node.getID() == 0 && node.getCount() != 0) {
        flip = true;
        break;
      }
    }
   
    for (
      Iterator itr = builder().getGraph().getNodes().iterator();
      itr.hasNext();
    ) {
      Node node = (Node)itr.next();
      if (flip) assertTrue(node.getCount() == 100-1-node.getID());
      else assertTrue(node.getCount() == node.getID());   
    }
  }
View Full Code Here

        public int visit(Graphable component) {
          if (component.getID() == 50) return(Graph.PASS_AND_CONTINUE);
          return(Graph.FAIL_QUERY)
        }
     };
     Node source = (Node)builder().getGraph().queryNodes(visitor).get(0);
    
     CountingWalker walker = new CountingWalker();
     NoBifurcationIterator iterator = createIterator();
     iterator.setSource(source);
    
View Full Code Here

  public void testAdd() {
    Polygon p1 = createPolygon("0 0,1 1,2 2,0 0");
    Polygon p2 = createPolygon("3 3,4 4,5 5,3 3");
    Polygon p3 = createPolygon("6 6,7 7,8 8,6 6");
   
    Node n1 = (Node) gg.add(p1);
    Node n2 = (Node) gg.add(p2);
    Node n3 = (Node) gg.add(p3);

    assertNotNull(n1);
    assertEquals(n1.getObject(),p1);

    assertNotNull(n2);
    assertEquals(n2.getObject(),p2);
   
    assertNotNull(n3);
    assertEquals(n3.getObject(),p3);
   
    Graph g = gg.getGraph();
    assertEquals(3,g.getNodes().size());
    assertEquals(0,g.getEdges().size());
  }
View Full Code Here

  public void testRelationships() {
    Polygon p1 = createPolygon("0 0,5 0,5 5,0 5,0 0");
    Polygon p2 = createPolygon("4 4,9 4,9 9,4 9,4 4");
    Polygon p3 = createPolygon("2 2,7 2,7 -3,2 -3,2 2");
   
    Node n1 = (Node) gg.add(p1);
    Node n2 = (Node) gg.add(p2);
    Node n3 = (Node) gg.add(p3);

    assertNotNull(n1.getEdge(n2));
    assertNotNull(n2.getEdge(n1));
    assertNotNull(n1.getEdge(n3));
    assertNotNull(n2.getEdge(n1));
View Full Code Here

     *     
     */
    public void test_3() {
      int k = 4;
      Object[] obj = GraphTestUtil.buildPerfectBinaryTree(builder(), k);
      final Node root = (Node)obj[0];
      final HashMap map = (HashMap) obj[1];
      HashMap rmap = new HashMap();
      Map.Entry[] set = new Map.Entry[map.size()];
      map.entrySet().toArray(set);
      for (int i = 0; i < set.length; i++) {
        rmap.put(set[i].getValue(), set[i].getKey());
      }
      final HashMap hashmap = rmap;
     
      class Factory {
        public AStarIterator.AStarFunctions createFunctions(Node target) {
          return
          (
            new AStarIterator.AStarFunctions(target) {
              public double cost(AStarNode n1, AStarNode n2){
                return 1;
              }
              public double h(Node n){
                String dest = hashmap.get(this.getDest()).toString()
                String current = hashmap.get(n).toString();
                if (dest.startsWith(current)) {
                  // n under dest
                  dest=dest.replaceAll("\\D", "");
                  current = current.replaceAll("\\D", "");
                  return dest.length()-current.length();
                } else {
                  return Double.POSITIVE_INFINITY;
                }
               
              }
                 }
          );
        }
    }
      Factory f = new Factory();
     
      AStarShortestPathFinder walker =
          new AStarShortestPathFinder(builder().getGraph(),root,((Node) map.get("0.1.0.1")),
                                  f.createFunctions(((Node) map.get("0.1.0.1"))));
     
      walker.calculate();
      MyVisitor visitor = new MyVisitor();
      builder().getGraph().visitNodes(visitor);
      //#1
      assertTrue(visitor.count > 0);
      assertTrue(visitor.count < map.size() + 1);
      Path p = null;
    try {
      p = walker.getPath();
    } catch (Exception e) {
      e.printStackTrace();
    }
      p.getEdges();
      assertTrue(p.size() == 4);
      // #2
      for (int j = 0; j < p.size() - 1; j++) {
        Node n = (Node) p.get(j);
        Node parent = (Node) p.get(j + 1);
        String n_id = rmap.get(n).toString();
        String parent_id = rmap.get(parent).toString();
        assertTrue(n_id.startsWith(parent_id));
      }
    }
View Full Code Here

TOP

Related Classes of org.geotools.graph.structure.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.