9 Replies Latest reply: Nov 28, 2007 2:32 AM by 321596 RSS

    Spatial Network constraints

    321596
      Hi,
      Who has some experience in writing spatial network constraints. I have a roads network, but not on all the nodes it is allowed to turn left (or right). I need some practical examples.

      With regards,
      Wijnand
        • 1. Re: Spatial Network constraints
          Luc Van Linden
          Wijnand

          the sample code of the otn spatial page has a simple example at the top:

          http://www.oracle.com/technology/sample_code/products/spatial/index.html

          I've used a network constraint on a 10gR1 tool to create dynamic segmentation on the last link of an network analysis (flood-like) to have an exact path result. Let me know if you need more on this, then I can start digging it up somewhere.

          regards

          Luc
          • 2. Re: Spatial Network constraints
            321596
            If I understand it correctly (in short)
            - The networkconstraint is defined in java
            - the compiled java-class is put in the database
            - the networkconstraint with name is registered in the user_sdo_network_constraints view
            - in my pl/sql code I call this constraint with a parameter

            In the prohibitedturn example all the link-id's are hard coded and not very dynamic If this is what you mean with your 'dynamic' then; yes, i would like to have some more information.

            With regards,
            Wijnand
            • 3. Re: Spatial Network constraints
              Luc Van Linden
              Wijnand

              I only used the network constraints on 10gR1, the pl/sql support is only available since 10gR2.

              By dynamic, I only meant the a dynamic segmentation of the last link in a network. fe. if you have a within cost 534 meter criteria and you have a link of 600 meter, the dynamic segmentation would cut the link dynamically and in-memory only, so that the path would fit the specific distance criteria.

              For this, I needed a network constraint since that offers the ability to evaluate the links and nodes (even the next-to-traverse ones) during a network analysis.

              Regards

              Luc
              • 4. Re: Spatial Network constraints
                Luc Van Linden
                Wijnand

                I had some time to look up the implementation of networkconstraint in the context previously described.
                As said, it had nothing to do with turn restrictions but maybe it can help you as example on how to use the analysis info (accessing previous and next link and nodes) when returning true for the requiresPathLinks() method.

                Please read this knowing that I'm not a java programmer as such ;-)

                Hoping it can help you.

                Luc
                public interface TypedNetworkConstraint extends NetworkConstraint
                {
                public void setStopType(String StopNodeType);

                public void setNetworkConstraintType(NetworkConstraintType type );

                public void setMakeStubbles (boolean makeStubbles);

                public boolean getMakeStubbles ();

                public void setMaxCost(double cost);

                }



                public class NodeTypeNetworkConstraint implements  TypedNetworkConstraint
                                                      
                {
                private  String myType = "";
                private  boolean mymakeStubbles = false;
                public  Vector stubblePaths;
                private  double myMaxCost = 0;
                private NetworkConstraintType networkConstraintType;

                // Methods to be implemented by user for interface NetworkConstraint
                   
                    public boolean requiresPathLinks()
                      {
                      return mymakeStubbles ;
                      }

                    public boolean isSatisfied(AnalysisInfo info)
                      {
                      Path myPath;
                     
                      boolean isSatisfiedvalue;
                      String NodeType = info.getCurrentNode().getType();
                      double deltacost = 0;
                          
                      if ( info.getCurrentNode() == info.getStartNode() )
                        isSatisfiedvalue = true; // start node, current link == null;
                        else
                            if ( NodeType.equals( myType))
                                  isSatisfiedvalue = false;
                            else
                                  {
                                  int testid = info.getCurrentNode().getID();
                                  isSatisfiedvalue = true;
                                  if (mymakeStubbles)
                                      {
                                   
                                     deltacost = info.getCurrentCost()  - myMaxCost;
                                    
                                     //System.out.println("CurrentCost : " + info.getCurrentCost());
                                     //System.out.println("NextLinkCost : " + info.getNextLink().getCost());
                                     //System.out.println("DeltaCost : " + deltacost);
                                     if (deltacost > 0)
                                        {
                                        if (!info.getPathLinkVec().contains(info.getNextLink()))
                                        {
                                        Stubble mystubble = new Stubble(info.getCurrentNode().getNetwork(),
                                                                    info.getNextLink().getID(),
                                                                    deltacost,
                                                                    info.getCurrentNode().getID());
                                       
                                        if (mystubble.isReversed())
                                        myPath = NetworkFactory.createPath(info.getStartNode(), mystubble.getStubble().getStartNode() );
                                        else
                                        myPath = NetworkFactory.createPath(info.getStartNode(), mystubble.getStubble().getEndNode() );
                                       
                                        myPath.setPathLinks(info.getPathLinkVec());
                                        myPath.appendLink(mystubble.getStubble());
                                        stubblePaths.add(myPath);
                                        }
                                        }
                                       
                                      }                       
                                 
                                  }
                           
                            return isSatisfiedvalue;
                           
                      }


                private static void PrintInfo(AnalysisInfo info)
                {
                  String myline;
                  String sep = "  ";
                  myline = "cC  " + info.getCurrentCost() + sep +
                           "cN  " + info.getCurrentNode().getID() + sep +
                           "nN   " + info.getNextNode().getID() + sep +
                           "cL  " + info.getCurrentLink().getID() + sep +
                           "cLc  " + info.getCurrentLink().getCost() + sep +
                           "cLs  " + info.getCurrentLink().getStartNode().getID() + sep +
                           "cLe  " + info.getCurrentLink().getEndNode().getID() + sep +
                           "nL  " + info.getNextLink().getID() + sep +
                           "nLc  " + info.getNextLink().getCost() + sep +
                           "nLs  " + info.getNextLink().getStartNode().getID() + sep +
                           "nLe  " + info.getNextLink().getEndNode().getID();
                 
                  System.out.println(myline);
                }

                public void setNetworkConstraintType(NetworkConstraintType type)
                {
                  networkConstraintType = type;
                }
                public NetworkConstraintType getNetworkConstraintType(NetworkConstraint networkConstraint)
                {
                  return networkConstraintType;
                }

                public Path[] getStubblePaths()
                {
                   
                  Path[] pathArray = new Path[stubblePaths.size()];
                  return (Path[])stubblePaths.toArray(pathArray);
                }

                public void setStopType(String StopNodeType)
                {
                  myType = StopNodeType;
                }
                public void setMakeStubbles (boolean makeStubbles)
                {
                  mymakeStubbles = makeStubbles;
                  if (makeStubbles)
                  stubblePaths = new Vector();
                 
                }
                public boolean getMakeStubbles()
                {
                  return mymakeStubbles;
                }

                public void setMaxCost(double cost)
                {
                  myMaxCost = cost;
                }

                  public NodeTypeNetworkConstraint()
                  {
                   
                  }
                 
                  public NodeTypeNetworkConstraint(String StopNodeType)
                  {
                    myType = StopNodeType;
                  }
                 
                 
                }
                • 5. Re: Spatial Network constraints
                  321596
                  Luc,
                  Thanks for your reply. I will look to this code with a colleague, because my java knowledge is not my forte also.
                  I have my doubts about my network-data model. I've created it using topology-tables. In those tables on every crossing line there is a node, but in my networkmodel (roads) there are a lot of lines which cross, but don't touch each other (e.g. flyovers). I don't want the nodes on top of the flyover. How did you create your network and realize real crossing lines?

                  With regards
                  Wijnand
                  • 6. Re: Spatial Network constraints
                    Luc Van Linden
                    Hi Wijnand

                    The topology was managed via the Network topology model sdo_nm only.
                    The nodes and links was Tele Atlas data.
                    Data loaded into the Network model via some scripts (Re: Massive Routing analysis

                    Do not hesitate to come back, should you need more info.

                    Good luck.

                    Luc
                    • 7. Re: Spatial Network constraints
                      321596
                      Hi Luc,
                      You've had the luck of having nodes and links tables. I only have a microstation designer file with linestring data. No connections or relations between the nodes and links are stored in the database.
                      I've to go back to the drawing-table. Maybe we can do something with FME (topology-builder). Thanks anyway for the link with the scripts.

                      With regards,
                      Wijnand
                      • 8. Re: Spatial Network constraints
                        Luc Van Linden
                        Hi Wijnand

                        Yes indeed, although that kind of luck has a price label ;-)

                        I collected some bits and pieces and placed it into this so called script.
                        This is tested on a relative small network. It should give you an idea and maybe some help to do it in OS. May it also need some tuning but it should work.

                        Give it a try.

                        Luc
                        --
                        -- Script to generate node_topo table and link_topo table from a sdo_geometry table
                        -- this table is called link_table and needs to have a link_id(number) and a geometry field
                        -- containing only 2d simple linestrings. Assumed the data is (network) topologically clean 
                        --
                        -- the result will be two tables: node_topo and link_topo
                        -- node_topo (nodeid number, node sdo_geometry)
                        -- link_topo (link_id number, start_node_id number, end_node_id number)
                        --
                        -- replace link_table with your_table_name and link_id with your_table_name's unique_id_name
                        --
                        -- on the insert into user_sdo_geom_metadata
                        -- adjust with appropriate metadata values for srid, upper and lowebounds and tolerance of your dataset


                        CREATE SEQUENCE SEQ_TOPO;

                        commit;

                        create table temp_nodes
                        as
                        select a.link_id, sdo_lrs.geom_segment_start_pt(a.geometry) node, SEQ_TOPO.nextval node_id, 'S' AS STEND
                        from link_table a;

                        commit;

                        insert into temp_nodes
                        select a.link_id, sdo_lrs.geom_segment_end_pt(a.geometry) node, SEQ_TOPO.nextval node_id, 'E' AS STEND
                        from link_table a;

                        commit;

                        -- insert user_sdo_geom_metadata and have index created for temp_nodes
                        -- adjust with appropriate metadata values for srid, upper and lowebounds and tolerance of your dataset

                        INSERT INTO user_sdo_geom_metadata VALUES ('temp_nodes','NODE',SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', 0, 1000000, 0.000005),SDO_DIM_ELEMENT('Y', 0, 100000, 0.000005)),NULL);

                        CREATE INDEX node_sx ON temp_nodes(node) INDEXTYPE IS MDSYS.SPATIAL_INDEX;

                        commit;

                        create table node_topo
                        as
                        select nodeid, node
                        from
                        (
                        select  min(node_id) nodeid, X, Y
                        from
                        (
                        SELECT c.node_id, t.X, t.Y
                           FROM temp_nodes c,
                           TABLE(SDO_UTIL.GETVERTICES(c.node)) t
                           ORDER BY c.node_id
                          )
                           group by X, Y
                        ) a inner join
                        temp_nodes t
                        on (a.nodeid = t.node_id);

                        commit;

                        create table link_topo
                        as
                        select link_id, max(st_ID) START_NODE_ID, max(en_ID) END_NODE_ID
                        from
                        (
                        select link_id, case when t.stend = 'S' THEN r.nodeid else 0 end st_ID,
                        case when t.stend = 'E' THEN r.nodeid else 0 end en_ID
                        from  node_topo r, temp_nodes t
                        where sdo_relate(t.NODE, r.NODE, 'mask=ANYINTERACT') = 'TRUE'
                        )
                        group by link_id;

                        commit;

                        drop table temp_nodes cascade constraints;

                        delete from user_sdo_geom_metadata where table_name = 'TEMP_NODES';

                        commit;

                        drop sequence seq_topo;

                        commit;
                        • 9. Re: Spatial Network constraints
                          321596
                          Hi Luc,
                          Thanks for your effort. I see that you use LRS-methods. I thought of that, but have no experience with it. I will give it a try.

                          With regards,
                          Wijnand