Package org.geotools.graph.structure

Examples of org.geotools.graph.structure.Node


   *
   */
  public void test_1() {
    int k = 4;
    Object[] obj = GraphTestUtil.buildPerfectBinaryTree(builder(), k);
    Node root = (Node)obj[0];
    Map id2node = (Map)obj[1];
   
    Node lc = (Node)id2node.get("0.0");
    Node rc = (Node)id2node.get("0.1");
   
    builder().removeNode(root);
   
    GraphPartitioner parter = new GraphPartitioner(builder().getGraph());
    parter.partition();
View Full Code Here


      };
      after.visitEdges(visitor);
     
      visitor = new GraphVisitor() {
        public int visit(Graphable component) {
          Node n = (Node)component;
         
          if (n.getDegree() == 1) {
            assertTrue(n.getID() == 0 || n.getID() == nnodes-1)
          }
          else {
            assertTrue(n.getDegree() == 2);
           
            Edge e0 = (Edge)n.getEdges().get(0);
            Edge e1 = (Edge)n.getEdges().get(1);
           
            assertTrue(
              (e0.getID() == n.getID()-1 && e1.getID() == n.getID()) ||
              (e1.getID() == n.getID()-1 && e0.getID() == n.getID())
            );
           
          }
         
          return(0);
View Full Code Here

   *
   */
  public void test_1() {
    final int k = 5;
    Object[] obj = GraphTestUtil.buildPerfectBinaryTree(builder(), k);
    final Node root = (Node)obj[0];
    final Map obj2node = (Map)obj[1];   
   
    try {
      File victim = File.createTempFile( "graph", null );
      victim.deleteOnExit();
      m_serializer.setProperty(SerializedReaderWriter.FILENAME, victim.getAbsolutePath() );
     
      m_serializer.write(builder().getGraph());
     
      Graph before = builder().getGraph();
      Graph after = m_serializer.read();
     
      //ensure same number of nodes and edges
      assertTrue(before.getNodes().size() == after.getNodes().size());
      assertTrue(before.getEdges().size() == after.getEdges().size());
     
      //ensure same structure
      GraphVisitor visitor = new GraphVisitor() {
        public int visit(Graphable component) {
          Node n = (Node)component;
          String id = (String)n.getObject();
         
          assertTrue(obj2node.get(id) != null);
         
          StringTokenizer st = new StringTokenizer(id, ".");
         
          if (st.countTokens() == 1) {
            //root
            assertTrue(n.getDegree() == 2);
           
            Node n0 = ((Edge)n.getEdges().get(0)).getOtherNode(n);
            Node n1 = ((Edge)n.getEdges().get(1)).getOtherNode(n);
           
            assertTrue(
              n0.getObject().equals("0.0") && n1.getObject().equals("0.1")
           || n0.getObject().equals("0.1") && n1.getObject().equals("0.0")
            );
          }
          else if (st.countTokens() == k+1) {
            //leaf
            assertTrue(n.getDegree() == 1);
           
            Node parent = ((Edge)n.getEdges().get(0)).getOtherNode(n);
            String parentid = (String)parent.getObject();
           
            assertTrue(parentid.equals(id.substring(0, id.length()-2)));  
          }
          else {
            //internal
View Full Code Here

      assertTrue(before.getNodes().size() == after.getNodes().size());
      assertTrue(before.getEdges().size() == after.getEdges().size());
     
      GraphVisitor visitor = new GraphVisitor() {
        public int visit(Graphable component) {
          Node n = (Node)component;
          if (n.getID() == 0 || n.getID() == nnodes-1)
            assertTrue(n.getDegree() == 0);
          else if (n.getID() == 1 || n.getID() == nnodes-2)
            assertTrue(n.getDegree() == 1);
          else assertTrue(n.getDegree() == 2);
          
          return(0);
        }
      };
      after.visitNodes(visitor);
View Full Code Here

    assertTrue(built.getEdges().size() == n);
    assertTrue(built.getNodes().size() == n+1);
   
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        Node node = (Node)component;
        Coordinate c = (Coordinate)node.getObject();
       
        if (node.getDegree() == 1) {
          assertTrue(node.getID() == 0 || node.getID() == n);
        }
        else {
          assertTrue(node.getDegree() == 2);
        }
       
        assertTrue(
          c.x == base.x + node.getID() && c.y == base.y + node.getID()
        );
        return(0);
      }
    };
    built.visitNodes(visitor);
View Full Code Here

        // init the distance
      double dist = 999999999;
     
      // Loops through the nodes of the graph and finds the node closest to the point of interest
      for (Object object:graph.getNodes()) {
        Node node = (Node) object;
        Point point = ((Point) node.getObject());
            //Logger.d(this.getClass().getSimpleName() + " node: " + node + ", point: " + point);
        double nodeDist = calculateDistance(destinationPoint.getX(), destinationPoint.getY(), point.getCoordinate().x,
                    point.getCoordinate().y,
                    coordinateReferenceSystem);
            //Logger.d(this.getClass().getSimpleName() + " nodeDist: " + nodeDist);
View Full Code Here

        }
        //build the graph
        networkGraph = featureGen.getGraph();

        //find the node of the graph closest to the origin point and returns the node
        Node source = nodeHelper.getNearestGraphNode(lineStringGen, networkGraph, originPoint, coordinateReferenceSystem);
        //distance between the origin location and the nearest graph node
        distanceOriginToGraph = nodeHelper.getDistanceFromGraphNode();

        //weight the edges of the graph using the distance of each linestring
        EdgeWeighter edgeWeighter = new EdgeWeighter() {
View Full Code Here

    public boolean calculateRouteFeature(Point originPoint, Point destinationPoint, int id) throws SchemaException, TransformException {
        //this calculates the route and builds a FeatureCollection of route objects, to do this the geometries of the various
        //linestrings contained within a path object (e.g. each road that makes up the route) must be merged to make one feature

        //get the graph node closest to the destination point object
        Node destination = nodeHelper.getNearestGraphNode(lineStringGen, networkGraph, destinationPoint, coordinateReferenceSystem);
        //get the path (route) from origin to destination
        Logger.d("Calc route feature, destination: " + destination);
        Path path = shortestPathFinder.getPath(destination);
        //Logger.d("Calc route feature, path: " + path);

        //this happens if the closest node is the endpoint of a disconnected line
        if (path == null) {
            Logger.w("Could not calculate the route to this destination" +
                    ". There is probably a problem with the network data set (dangles etc ...)");
            return false;
        }

        //create a vector object to store all the edges
        Vector result = new Vector();
        Node previous = null;
        Node node;

        //iterate through the path object getting each node and it's neighbour and build edge objects from them
        for (Iterator iterator = path.riterator(); iterator.hasNext();) {
            node = (Node) iterator.next();
            if (previous != null) {
                // Adds the resulting edge into the vector
                result.add(node.getEdge(previous));
            }
            previous = node;
        }

        //create an array to store the geometry of each Edge linestring that will need to be merged into one Route object
View Full Code Here

        return DataUtilities.source(routeFeatures);
    }

    public void calculateCostArrayList(Point originPoint, Point destinationPoint) throws SchemaException, TransformException {
        //calculates the cost between an origin and destination point
        Node destination = nodeHelper.getNearestGraphNode(lineStringGen, networkGraph, destinationPoint, coordinateReferenceSystem);
        Costs.add(shortestPathFinder.getCost(destination));
    }
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.