Oracle® Spatial Topology and Network Data Models Developer's Guide 11g Release 2 (11.2) Part Number E11831-01 |
|
|
View PDF |
This chapter explains the concepts and operations related to the Oracle Spatial network data model. It assumes that you are familiar with the main Oracle Spatial concepts, data types, and operations, as documented in Oracle Spatial Developer's Guide:
Although this chapter discusses some network-related terms as they relate to Oracle Spatial, it assumes that you are familiar with basic network data modeling concepts.
This chapter contains the following major sections:
Section 5.8, "Network Editing and Analysis Using the In-Memory Approach"
Section 5.11, "Network Data Model Application Programming Interface"
Section 5.14, "Network Data Model Documentation and Demo Files"
Section 5.15, "README File for Spatial and Related Features"
In many applications, capabilities or objects are modeled as nodes and links in a network. The network model contains logical information such as connectivity relationships among nodes and links, directions of links, and costs of nodes and links. With logical network information, you can analyze a network and answer questions, many of them related to path computing and tracing. For example, for a biochemical pathway, you can find all possible reaction paths between two chemical compounds; or for a road network, you can find the following information:
What is the shortest (distance) or fastest (travel time) path between two cities?
What is the closest hotel to a specific airport, and how can I get there?
In additional to logical network information, spatial information such as node locations and link geometries can be associated with the network. This information can help you to model the logical information (such as the cost of a route, because its physical length can be directly computed from its spatial representation).
The Spatial network data model can be used for large, complex networks. For example, Figure 5-1 shows New York City nodes and links, which have been defined using the network data model, displayed using the Network Editor demo tool (described in Section 5.14).
The generic data model and network analysis capability can model and analyze many kinds of network applications in addition to traditional geographical information systems (GIS). For example, in biochemistry, applications may need to model reaction pathway networks for living organisms; and in the pharmaceutical industry, applications that model the drug discovery process may need to model protein-protein interaction.
The network modeling capabilities of Spatial include schema objects and an application programming interface (API). The schema objects include metadata and network tables. The API includes a server-side PL/SQL API (the SDO_NET and SDO_NET_MEM packages) for creating, managing, editing, and analyzing networks in the database, and a middle-tier (or client-side) Java API for network editing and analysis.
This section summarizes the main steps for working with the network data model in Oracle Spatial. It refers to important concepts, structures, and operations that are described in detail in other sections.
There are two basic approaches to creating a network:
Let Spatial perform most operations, using procedures with names in the form CREATE_<network-type>_NETWORK. (See Section 5.2.1.)
Perform the operations yourself: create the necessary network tables and update the network metadata. (See Section 5.2.2.)
With each approach, you must insert the network data into the network tables. You can then use the network data model PL/SQL and Java application programming interfaces (APIs) to update the network and perform other operations. (The PL/SQL and Java APIs are described in Section 5.11.)
To create a network by letting Spatial perform most of the necessary operations, follow these steps:
Create the network using a procedure with a name in the form CREATE_<network-type>_NETWORK, where <network-type> reflects the type of network that you want to create:
SDO_NET.CREATE_SDO_NETWORK for a spatial network with non-LRS SDO_GEOMETRY objects
SDO_NET.CREATE_LRS_NETWORK for a spatial network with LRS SDO_GEOMETRY objects
SDO_NET.CREATE_TOPO_NETWORK for a spatial network with topology geometry (SDO_TOPO_GEOMETRY) objects
SDO_NET.CREATE_LOGICAL_NETWORK for a logical network that does not contain spatial information
Each of these procedures creates the necessary network data model tables (described in Section 5.9) and inserts a row with the appropriate network metadata information into the xxx_SDO_NETWORK_METADATA views (described in Section 5.10.1).
Each procedure has two formats: one format creates all network data model tables using default names for the tables and certain columns, and other format lets you specify names for the tables and certain columns. The default names for the network data model tables are <network-name>_NODE$, <network-name>_LINK$, <network-name>_PATH$, and <network-name>_PLINK$. The default name for cost columns in the network data model tables is COST, and the default name for geometry columns is GEOMETRY.
Insert data into the node and link tables, and if necessary into the path and path-link tables. (The node, link, path, and path-link tables are described in Section 5.9.)
Validate the network, using the SDO_NET.VALIDATE_NETWORK function.
For a spatial (SDO or LRS) network, insert the appropriate information into the USER_SDO_GEOM_METADATA view, and create spatial indexes on the geometry columns.
If you plan to use a view as a node, link, or path table, you must specify the view name for the TABLE_NAME column value when you insert information about the node, link, or path table in the USER_SDO_GEOM_METADATA view.
To create a network by performing the necessary operations yourself, follow these steps:
Create the node table, using the SDO_NET.CREATE_NODE_TABLE procedure. (The node table is described in Section 5.9.1.)
Insert data into the node table.
Create the link table, using the SDO_NET.CREATE_LINK_TABLE procedure. (The link table is described in Section 5.9.2).
Insert data into the link table.
Optionally, create the path table, using the SDO_NET.CREATE_PATH_TABLE procedure. (The path table is described in Section 5.9.3).
If you created the path table, create the path-link table, using the SDO_NET.CREATE_PATH_LINK_TABLE procedure. (The path-link table is described in Section 5.9.4).
If you created the path table and if you want to create paths, insert data into the table.
If you inserted data into the path table, insert the appropriate rows into the path-link table.
Insert a row into the USER_SDO_NETWORK_METADATA view with information about the network. (The USER_SDO_NETWORK_METADATA view is described in Section 5.10.1.)
If you plan to use a view as a node, link, path, or path-link table, you must specify the view name for the relevant columns when you insert information about the network in the USER_SDO_NETWORK_METADATA view.
For a spatial (SDO or LRS) network, insert the appropriate information into the USER_SDO_GEOM_METADATA view, and create spatial indexes on the geometry columns.
If you plan to use a view as a node, link, or path table, you must specify the view name for the TABLE_NAME column value when you insert information about the node, link, or path table in the USER_SDO_GEOM_METADATA view.
Validate the network, using the SDO_NET.VALIDATE_NETWORK function.
You can change the sequence of some of these steps. For example, you can create both the node and link tables first, and then insert data into each one; and you can insert the row into the USER_SDO_NETWORK_METADATA view before you create the node and link tables.
A network is a type of mathematical graph that captures relationships between objects using connectivity. The connectivity may or may not be based on spatial proximity. For example, if two towns are on opposite sides of a lake, the shortest path based on spatial proximity (a straight line across the middle of the lake) is not relevant if you want to drive from one town to the other. Instead, to find the shortest driving distance, you need connectivity information about roads and intersections and about the "cost" of individual links.
A network consists of a set of nodes and links. Each link (sometimes also called an edge or a segment) specifies two nodes.
A network can be directed (that is, by default, the start and end nodes determine link direction) or undirected (that is, links can be traversed in either direction).
The following are some key terms related to the network data model:
A node represents an object of interest. An isolated node is a node that is not included in any links. (A non-isolated node will become isolated if all links that include that node are deleted.)
A link represents a relationship between two nodes. Within a directed network, any link can be undirected (that is, able to be traversed either from the start node to the end node or from the end node to the start node) or directed (that is, able to be traversed only from the start node to the end node). Within an undirected network, all links are undirected.
A path is an alternating sequence of nodes and links, beginning and ending with nodes, and usually with no nodes and links appearing more than once. (Repeating nodes and links within a path are permitted, but are rare in most network applications.)
A subpath is partial path along a path, created either as a result of a network analysis operation or explicitly by a user. Subpaths are explained and illustrated in Section 5.3.1.
A logical network contains connectivity information but no geometric information. This is the model used for network analysis. A logical network can be treated as a directed graph or undirected graph, depending on the application.
A spatial network contains both connectivity information and geometric information. In a spatial network, the nodes and links are SDO_GEOMETRY geometry objects without LRS information (an SDO network) or with LRS information (an LRS network), or SDO_TOPO_GEOMETRY objects (a topology geometry network).
In an LRS network, each node includes a geometry ID value and a measure value, and each link includes a geometry ID value and start and end measure values; and the geometry ID value in each case refers to an SDO_GEOMETRY object with LRS information. A spatial network can be directed or undirected, depending on the application.
A feature is an object of interest in a network application that is associated with a node or link. For example, in a transportation network, features include exits and intersections (mapped to nodes), and highways and streets (mapped to links).
Cost is a non-negative numeric attribute that can be associated with links or nodes for computing the minimum cost path, which is the path that has the minimum total cost from a start node to an end node. You can specify a single cost factor, such as driving time or driving distance for links, in the network metadata, and network analytical functions that examine cost will use this specified cost factor.
Duration is a non-negative numeric attribute that can be associated with links or nodes to specify a duration value for the link or node. The duration value can indicate a number of minutes or any other user-determined significance. You can specify a single duration factor, such as driving time for links, in the network metadata; however, if you use duration instead of cost to indicate elapsed time, network analytical functions that examine cost will not consider the specified duration factor.
State is a string attribute, either ACTIVE
or INACTIVE
, that is associated with links or nodes to specify whether or not a link or node will be considered by network analysis functions. For example, if the state of a node is INACTIVE
, any links from or to that node are ignored in the computation of the shortest path between two nodes. The state is ACTIVE
by default when a link or node is created, but you can set the state INACTIVE
.
Type is a string attribute that can be associated with links or nodes to specify a user-defined value for the type of a link or a node.
Temporary links, nodes, and paths exist only in a network memory object, and are not written to the database when the network memory object is written. For example, during a network analysis and editing session you might create temporary nodes to represent street addresses for shortest-path computations, but not save these temporary nodes when you save the results of editing operations.
Reachable nodes are all nodes that can be reached from a given node. Reaching nodes are all nodes that can reach a given node.
The degree of a node is the number of links to (that is, incident upon) the node. The in-degree is the number of inbound links, and the out-degree is the number of outbound links.
A connected component is a group of network nodes that are directly or indirectly connected. If node A can reach node B, they must belong to the same connected component. If two nodes are not connected, it is concluded that there is no possible path between them. This information can be used as a filter to avoid unnecessary path computations.
A spanning tree of a connected graph is a tree (that is, a graph with no cycles) that connects all nodes of the graph. (The directions of links are ignored in a spanning tree.) The minimum cost spanning tree is the spanning tree that connects all nodes and has the minimum total cost.
A partitioned network is a network that contains multiple partitions. Partitioning a large network enables only the necessary partitions to be loaded on demand into memory, thus providing better overall performance.
Network partitions are sub-networks, each covering a subset of nodes and links of the entire network. Network partitions are the basic processing units for load on demand analysis. They are created by assigning every node in the network to only one partition ID. Network partition information is stored in a partition table.
Load on demand (load on demand analysis) is an approach that divides large networks into manageable partitions and only loads needed partitions during analysis, thus removing memory limitation as a consideration and providing better overall performance.
Partition BLOBs are binary representations for network partitions. They provide faster partition loading time. They are stored in a partition BLOB table.
The load on demand partition cache is an in-memory placeholder for network partitions loaded into memory during network analysis. You can configure the partition cache.
User-defined data is the information (not related to connectivity) that users want to associate with a network representation. User-defined data can be defined at the node, link, path, and subpath level, and is stored in columns in the node, link, path, and subpath tables.
A subpath is partial path along a path, created either as a result of a network analysis operation or explicitly by a user. The start and end points of a subpath are defined as link indexes and the percentage of the distance from the previous node in the path, as shown in Figure 5-2.
A subpath refers to an existing path (the reference path) using the following parameters:
Reference path ID: the path ID of the reference path.
Start link index: the start link index on the reference path. (Link index 0 refers to the link between the first and second nodes on the path.) In Figure 5-2, link index 0 is the start link index.
Start percentage: the percentage of the distance along the start link for the start node of the subpath. In Figure 5-2, the subpath starts at 65 percent of the distance between the start and end of link index 0.
End link index: the end link index on the reference path. In Figure 5-2, link index 6 is the end link index.
End percentage: the percentage of the distance along the end link for the end node of the subpath. In Figure 5-2, the subpath ends at 50 percent of the distance between the start and end of link index 6.
Networks are used in applications to find how different objects are connected to each other. The connectivity is often expressed in terms of adjacency and path relationships. Two nodes are adjacent if they are connected by a link. There are often several paths between any two given nodes, and you may want to find the path with the minimum cost.
This section describes some typical examples of different kinds of network applications.
In a typical road network, the intersections of roads are nodes and the road segments between two intersections are links. The spatial representation of a road is not inherently related to the nodes and links in the network. For example, a shape point in the spatial representation of a road (reflecting a sharp turn in the road) is not a node in the network if that shape point is not associated with an intersection; and a single spatial object may make up several links in a network (such as a straight segment intersected by three crossing roads). An important operation with a road network is to find the path from a start point to an end point, minimizing either the travel time or distance. There may be additional constraints on the path computation, such as having the path go through a particular landmark or avoid a particular intersection.
The subway network of any major city is probably best modeled as a logical network, assuming that precise spatial representation of the stops and track lines is unimportant. In such a network, all stops on the system constitute the nodes of the network, and a link is the connection between two stops if a train travels directly between these two stops. Important operations with a train network include finding all stations that can be reached from a specified station, finding the number of stops between two specified stations, and finding the travel time between two stations.
Utility networks, such as power line or cable networks, must often be configured to minimize the cost. An important operation with a utility network is to determine the connections among nodes, using minimum cost spanning tree algorithms, to provide the required quality of service at the minimum cost. Another important operation is reachability analysis, so that, for example, if a station in a water network is shut down, you know which areas will be affected.
Biochemical processes can be modeled as biochemical networks to represent reactions and regulations in living organisms. For example, metabolic pathways are networks involved in enzymatic reactions, while regulatory pathways represent protein-protein interactions. In this example, a pathway is a network; genes, proteins, and chemical compounds are nodes; and reactions among nodes are links. Important operations for a biochemical network include computing paths and the degrees of nodes.
Some network applications require representations at different levels of abstraction. For example, two major processes might be represented as nodes with a link between them at the highest level of abstraction, and each major process might have several subordinate processes that are represented as nodes and links at the next level down.
A network hierarchy enables you to represent a network with multiple levels of abstraction by assigning a hierarchy level to each node. (Links are not assigned a hierarchy level, and links can be between nodes in the same hierarchy level or in different levels.) The lowest (most detailed) level in the hierarchy is level 1, and successive higher levels are numbered 2, 3, and so on.
Nodes at adjacent levels of a network hierarchy have parent-child relationships. Each node at the higher level can be the parent node for one or more nodes at the lower level. Each node at the lower level can be a child node of one node at the higher level. Sibling nodes are nodes that have the same parent node.
Links can also have parent-child relationships. However, because links are not assigned to a hierarchy level, there is not necessarily a relationship between link parent-child relationships and network hierarchy levels. Sibling links are links that have the same parent link.
Figure 5-3 shows a simple hierarchical network, in which there are two levels.
As shown in Figure 5-3:
The top level (level 2) contains two nodes. Each node is the parent node of several nodes in the bottom level. The link between the nodes in the top level is the parent link of two links between nodes in the bottom level.
The bottom level (level 1) shows the nodes that make up each node in the top level. It also shows the links between nodes that are child nodes of each parent node in the top level, and two links between nodes that have different parent nodes.
The links between nodes in the bottom level that have different parent nodes are shown with dark connecting lines. These links are child links of the single link between the nodes in the top level in the hierarchy. (However, these two links in the bottom level could also be defined as not being child links of any parent link between nodes in a higher level.)
The parent-child relationships between each parent node and link and its child nodes and links are shown with dashed lines with arrowheads at both ends.
Although it is not shown in Figure 5-3, links can cross hierarchy levels. For example, a link could be defined between a node in the top level and any node in the bottom level. In this case, there would not be a parent-child relationship between the links.
Network constraints are restrictions defined on network analysis computations. For example, a network constraint might list a series of prohibited turns in a roads network due to one-way streets and "No Left Turn" signs, with each prohibited turn represented as a pair of links (a start link and an end link onto which a turn cannot be made from the start link). As another example, a network constraint might require that driving routes must not include toll roads or must not include expressways.
To create a network constraint, you must create a Java class that implements the constraint, and you must register the constraint by using the SDO_NET.REGISTER_CONSTRAINT procedure. To apply a network constraint to a network analysis operation, specify the constraint using the constraint
parameter with the appropriate SDO_NET_MEM subprogram.
Examples of Java classes to implement network constraints are provided in the network data model demo files, which are described in Section 5.14. For example, the ProhibitedTurns.java
file creates a network constraint that defines a series of prohibited turns, and it then returns the shortest path between two nodes, first without applying the constraint and then applying the constraint.
Load on demand means that during network analysis, a network partition is not loaded into memory until the analysis has reached this partition while exploring the network. With load on demand, Oracle Spatial performs most partitioning and loading operations automatically, and this usually results in more efficient memory utilization with very large networks.
Load on demand analysis involves the following major steps: network creation, network partition, partition cache configuration, and network analysis.
Create the network, using one of the approaches described in Section 5.2.
Partition the network using the SDO_NET.SPATIAL_PARTITION procedure, as explained in Section 5.7.1.
Optionally, generate partition BLOBs, as explained in Section 5.7.2.
Configure the load on demand environment, including the partition cache, as explained in Section 5.7.3.
Analyze the network, as explained in Section 5.7.4.
Note:
Load on demand analysis also works with nonpartitioned networks by treating the entire network as one partition. For a small network, there may be no performance benefit in partitioning it, in which case you can skip the partitioning but still use load on demand APIs.For examples of performing load on demand network analysis and configuring the partition cache, see Section 5.13.5.
Additional examples of partitioning and load on demand analysis are included on the Oracle Database Examples media (see Oracle Database Examples Installation Guide). For more information about network data model example and demo files, see Section 5.14.
You can partition a network using the SDO_NET.SPATIAL_PARTITION procedure, specifying the maximum number of nodes in each partition. The partition result is stored in a partition table, which is automatically generated, and partition metadata information is inserted into the network metadata. (As an alternative to using the procedure, you can partition a network by creating and populating a partition table.) You can use other SDO_NET subprograms to query the partitioning metadata.
A good partition strategy is to minimize the number of links between partitions, which reduces the number of partitions that need to be loaded and the probable number of times that the same partitions need to be reloaded. Moreover, partitions that are too small require excessive loading and unloading of partitions during analysis.
The recommended maximum number of nodes per partition, assuming 1 GB of memory, is between 5,000 and 10,000. You can tune the number and see what is best for your applications, considering the available memory, type of analysis, and network size. You should also consider configuring the partition caching size.
To enhance the performance of network loading, you can optionally store partitions as BLOBs in a network partition BLOB table. This information needs to be stored in the network metadata view in order to take advantage of faster partition loading time. Note that if a network or partition information is updated, the partition BLOBs need to be regenerated as well.
A partition BLOB is a binary stream of data containing the network partition information, such as number of nodes, number of links, properties of each node, properties of each link, and so on. If a partition BLOB exists, Spatial uses it to read information during the load operation, rather than performing time-consuming database queries.
To generate partition BLOBs, use the SDO_NET.GENERATE_PARTITION_BLOBS procedure. The partition BLOBs and their metadata are stored in the partition BLOB table, which is described in Section 5.9.7.
Before you perform network analysis, you can configure the network partition cache to optimize performance, by modifying an XML configuration file to override the default configuration. You can specify the following:
Cache size: the maximum number of nodes in partition cache
Partitions source: from network tables or partition BLOBs
Resident partitions: IDs of partitions that will not be flushed out of the cache, but will stay in memory once they are loaded
Cache flushing policy: class name of the CachingHandler
implementation
The default caching policy is LeastRecentlyUsed
, which flushes out the oldest partition out of memory when the cache is full. You can specify other caching policies by implementing the CachingHandler
interface.
A copy of the default load on demand configuration file is included in the supplementary documentation, described in Section 5.14.
After you have created and partitioned the network, and optionally configured the partition cache, you can issue analysis queries. Analysis results are returned in Java representation or XML responses, depending on whether you used the Java or XML API. For details, see the load on demand (LOD) Javadoc and XML schemas (the latter described in Section 5.14).
You can write the analysis results to the database using the load on demand Java API.
Although the load on demand approach reduces the effect of memory limitations in analyzing large networks, analysis operations still can sometimes be very slow. For example, shortest path analysis of two nodes diagonally across the entire network is likely to require traversing almost every link in the network, and this will take a significant amount of time for a network with more than, for example, two million nodes.
To further reduce network analysis time, you can perform analysis on different link levels. Link level is a positive integer assigned to a link indicating the level of preference of this link. The higher the link level, the higher the preference. For example, a road network may consist of two link levels, level 1 for local roads and level 2 for highways. During network analysis, highways are preferred to local roads, and the minimum link level is 1. (If no link level is assigned to a link, the default link level of 1 is used for the link.)
Link levels have an implicit inheritance property, which means that a network at higher link levels must be a subnetwork of a network at a lower link level. That is, link level 2 is a subnetwork of link level 1, link level 3 is a subnetwork of link level 2, and so on.
You can specify a link level when you load a network or a partition, which causes links at that level and higher levels to be loaded. Using the road network example, with link level 1 for local roads and link level 2 for highways, specifying link level 1 on a load operation loads links at link levels 1 and 2 (that is, local roads and highways), but specifying link level 2 on a load operation loads only the highways links. If you wanted to perform analysis using only highways links, you could optimize the performance by specifying link level 2 for the load operation.
Some analysis operations, such as connected component analysis, can be time consuming. To improve run-time performance, you can call the SDO_NET.FIND_CONNECTED_COMPONENTS procedure, which computes the connected components in the network and stores the results in the connected component table, which is described Section 5.9.8.
At run time, before calling shortest path analysis or reachability analysis, you can check whether the nodes of interest belong to the same connected component by querying the connected component table. If precomputed component information does not exist, it may take a long time for shortest path and reachability analysis to discover that two nodes are, in fact, not connected.
Note:
The in-memory approach will be deprecated in the next release of Spatial, and future development will enhance the load on demand approach, which is described in Section 5.7. You are encouraged use the load on demand approach whenever possible.This section describes how to perform network editing and analysis operations using a network memory object, which is a cache in virtual memory. You can load a network or a hierarchy level in a network into a network memory object, perform operations on network objects in the memory object, and then either discard any changes or write the changes to the network in the database.
Multiple network memory objects can exist at a time for a specified network, but only one can be updatable; any others must be read-only. For better performance, if you plan to use the network memory object only to retrieve information or to perform network analysis operations, make the network memory object read-only (that is, specify allow_updates=>'FALSE'
with the SDO_NET_MEM.NETWORK_MANAGER.READ_NETWORK procedure).
To work with a network memory object, you can use either the PL/SQL API (specifically, the SDO_NET_MEM package) or the Java API. Both APIs are introduced in Section 5.11.
In the network data model PL/SQL API, the subprograms in the SDO_NET package operate on the network in the database, and the subprograms in the SDO_NET_MEM package operate on the network memory object in the cache. For some network editing operations (such as adding a node, link, or path), you can use either an SDO_NET or SDO_NET_MEM procedure; however, if you are performing a large number of editing operations, using the cache (SDO_NET_MEM procedures) offers better performance. Most network operations, though, can be performed only by a subprogram in the SDO_NET or SDO_NET_MEM package, and in these cases your decision about whether to use a network memory object depends on your specific needs.
Example 5-1 uses a network memory object to add a new node and a new link to an existing network, perform a shortest path analysis, print the analysis results, and save the changes and analysis results in the database. These steps assume that a logical network named XYZ_NETWORK has already been created and populated using the statements shown in Example 5-5 in Section 5.13.4.
Example 5-1 Using a Network Memory Object for Editing and Analysis (PL/SQL)
DECLARE path_id NUMBER; res_numeric NUMBER; res_array SDO_NUMBER_ARRAY; indx NUMBER; BEGIN -- Create a network memory object in the user session for the -- logical network named XYZ_NETWORK. This creates a network -- object and reads all metadata, nodes, links, and paths in -- the network, and it allows for updates to be performed. sdo_net_mem.network_manager.read_network(net_mem=>'XYZ_NETWORK', allow_updates=>'TRUE'); -- Add a node with ID=901, and set its name to N901 and cost to 5. sdo_net_mem.network.add_node(net_mem=>'XYZ_NETWORK', node_id=>901, node_name=>'N901', external_network_id=>0, external_node_id=>0); sdo_net_mem.node.set_cost(net_mem=>'XYZ_NETWORK', node_id=>901, cost=>5); -- Add a link with ID=9901, name=N901N1, cost=20 from node N901 to node N1. sdo_net_mem.network.add_link(net_mem=>'XYZ_NETWORK', link_id=>9901, link_name=>'N901N1', start_node_id=>901, end_node_id=>101, cost=>20); -- Perform a shortest path analysis from node N1 to node N5. path_id := sdo_net_mem.network_manager.shortest_path('XYZ_NETWORK', 101, 105); DBMS_OUTPUT.PUT_LINE('The ID of the shortest path from N1 to N5 is: ' || path_id); -- List the properties of the path: cost, nodes, and links. res_numeric := sdo_net_mem.path.get_cost('XYZ_NETWORK', path_id); DBMS_OUTPUT.PUT_LINE('The cost of this path is: ' || res_numeric); res_array:= sdo_net_mem.path.get_node_ids('XYZ_NETWORK', path_id); DBMS_OUTPUT.PUT('This path has the following nodes: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array:= sdo_net_mem.path.get_link_ids('XYZ_NETWORK', path_id); DBMS_OUTPUT.PUT('This path has the following links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- Add the path to the network memory object. sdo_net_mem.network.add_path(net_mem=>'XYZ_NETWORK', path_id=>path_id); -- Write changes to the database and commit changes. sdo_net_mem.network_manager.write_network(net_mem=>'XYZ_NETWORK'); -- Drop the network memory object. sdo_net_mem.network_manager.drop_network(net_mem=>'XYZ_NETWORK'); END; / The ID of the shortest path from N1 to N5 is: 1 The cost of this path is: 50 This path has the following nodes: 101 103 104 105 This path has the following links: 1102 1104 1105
The connectivity information for a spatial network is stored in two tables: a node table and a link table. In addition, path information can be stored in a path table and a path-link table. You can have Spatial create these tables automatically when you create the network using a CREATE_<network-type>_NETWORK procedure; or you can create these tables using the SDO_NET.CREATE_NODE_TABLE, SDO_NET.CREATE_LINK_TABLE, SDO_NET.CREATE_PATH_TABLE, and SDO_NET.CREATE_PATH_LINK_TABLE procedures.
These tables contain columns with predefined names, and you must not change any of the predefined column names; however, you can add columns to the tables by using the ALTER TABLE statement with the ADD COLUMN clause. For example, although each link and path table is created with a single COST column, you can create additional columns and associate them with other comparable attributes. Thus, to assign a driving time, scenic appeal rating, and a danger rating to each link, you could use the COST column for driving time, add columns for SCENIC_APPEAL and DANGER to the link table, and populate all three columns with values to be interpreted by applications.
The following considerations apply to schema, table, and column names that are stored in any Oracle Spatial metadata views. For example, these considerations apply to the names of node, link, path, and path-link tables, and to the names of any columns in these tables that are stored in the network metadata views described in Section 5.10.
The name must contain only letters, numbers, and underscores. For example, the name cannot contain a space ( ), an apostrophe ('
), a quotation mark ("
), or a comma (,
).
All letters in the names are converted to uppercase before the names are stored in metadata views or before the tables are accessed. This conversion also applies to any schema name specified with the table name.
Each network has a node table that can contain the columns described in Table 5-1. (The specific columns depend on the network type and whether the network is hierarchical or not.)
Table 5-1 Node Table Columns
Column Name | Data Type | Description |
---|---|---|
NODE_ID |
NUMBER |
ID number that uniquely identifies this node within the network |
NODE_NAME |
VARCHAR2(32) |
Name of the node |
NODE_TYPE |
VARCHAR2(24) |
User-defined string to identify the node type |
VARCHAR2(1) |
Contains |
|
PARTITION_ID |
NUMBER |
(Not used. Instead, node and partition relationships are stored in the partition table, which is described in Section 5.9.6.) |
<node_geometry_column>, or GEOM_ID and MEASURE |
SDO_GEOMETRY, or SDO_TOPO_GEOMETRY, or NUMBER |
For a spatial (SDO, non-LRS) network, the SDO_GEOMETRY object associated with the node For a spatial topology network, the SDO_TOPO_GEOMETRY object associated with the node For a spatial LRS network, GEOM_ID and MEASURE column values (both of type NUMBER) for the geometry objects associated with the node For a logical network, this column is not used. For a spatial SDO or topology network, the actual column name is either a default name or what you specified as the |
<node_cost_column> |
NUMBER |
Cost value to be associated with the node, for use by applications that use the network. The actual column name is either a default name or what you specified as the |
HIERARCHY_LEVEL |
NUMBER |
For hierarchical networks only: number indicating the level in the network hierarchy for this node. (Section 5.5 explains network hierarchy.) |
PARENT_NODE_ID |
NUMBER |
For hierarchical networks only: node ID of the parent node of this node. (Section 5.5 explains network hierarchy.) |
Each network has a link table that contains the columns described in Table 5-2.
Table 5-2 Link Table Columns
Column Name | Data Type | Description |
---|---|---|
LINK_ID |
NUMBER |
ID number that uniquely identifies this link within the network |
LINK_NAME |
VARCHAR2(32) |
Name of the link |
START_NODE_ID |
NUMBER |
Node ID of the node that starts the link |
END_NODE_ID |
NUMBER |
Node ID of the node that ends the link |
LINK_TYPE |
VARCHAR2(24) |
User-defined string to identify the link type |
VARCHAR2(1) |
Contains |
|
LINK_LEVEL |
NUMBER |
Priority level for the link; used for network analysis, so that links with higher priority levels can be considered first in computing a path |
<link_geometry_column>; or GEOM_ID, START_MEASURE, and END_MEASURE |
SDO_GEOMETRY, or SDO_TOPO_GEOMETRY, or NUMBER |
For a spatial (SDO, non-LRS) network, the SDO_GEOMETRY object associated with the link For a spatial topology network, the SDO_TOPO_GEOMETRY object associated with the link For a spatial LRS network, GEOM_ID, START_MEASURE, and END_MEASURE column values (all of type NUMBER) for the geometry objects associated with the link For a logical network, this column is not used. For a spatial SDO or topology network, the actual column name is either a default name or what you specified as the |
<link_cost_column> |
NUMBER |
Cost value to be associated with the link, for use by applications that use the network. The actual column name is either a default name or what you specified as the |
PARENT_LINK_ID |
NUMBER |
For hierarchical networks only: link ID of the parent link of this link. (Section 5.5 explains parent-child relationships in a network hierarchy.) |
BIDIRECTED |
VARCHAR2(1) |
For directed networks only: contains |
Each network can have a path table. A path is an ordered sequence of links, and is usually created as a result of network analysis. A path table provides a way to store the result of this analysis. For each path table, you must create an associated path-link table (described in Section 5.9.4). Each path table contains the columns described in Table 5-3.
Table 5-3 Path Table Columns
Column Name | Data Type | Description |
---|---|---|
PATH_ID |
NUMBER |
ID number that uniquely identifies this path within the network |
PATH_NAME |
VARCHAR2(32) |
Name of the path |
PATH_TYPE |
VARCHAR2(24) |
User-defined string to identify the path type |
START_NODE_ID |
NUMBER |
Node ID of the node that starts the first link in the path |
END_NODE_ID |
NUMBER |
Node ID of the node that ends the last link in the path |
COST |
NUMBER |
Cost value to be associated with the path, for use by applications that use the network. The cost value can represent anything you want, for example, the estimated driving time for the path. |
SIMPLE |
VARCHAR2(1) |
Contains |
<path_geometry_column> |
SDO_GEOMETRY |
For all network types except logical, the geometry object associated with the path. The actual column name is either a default name or what you specified as the For a logical network, this column is not used. |
For each path table (described in Section 5.9.3), you must create a path-link table. Each row in the path-link table uniquely identifies a link within a path in a network; that is, each combination of PATH_ID, LINK_ID, and SEQ_NO values must be unique within the network. The order of rows in the path-link table is not significant. Each path-link table contains the columns described in Table 5-4.
Table 5-4 Path-Link Table Columns
Column Name | Data Type | Description |
---|---|---|
PATH_ID |
NUMBER |
ID number of the path in the network |
LINK_ID |
NUMBER |
ID number of the link in the network |
SEQ_NO |
NUMBER |
Unique sequence number of the link in the path. (The sequence numbers start at 1.) Sequence numbers allow paths to contain repeating nodes and links. |
Each path can have one or more associated subpaths, and information about all subpaths in a network is stored in the subpath table. A subpath is a partial path along a path, as explained in Section 5.3. The subpath table contains the columns described in Table 5-5.
Table 5-5 Subpath Table Columns
Column Name | Data Type | Description |
---|---|---|
SUBPATH_ID |
NUMBER |
ID number that uniquely identifies this subpath within the reference path |
SUBPATH_NAME |
VARCHAR2(32) |
Name of the subpath |
SUBPATH_TYPE |
VARCHAR2(24) |
User-defined string to identify the subpath type |
REFERENCE_PATH_ID |
NUMBER |
Path ID number of the path that contains this subpath |
START_LINK_INDEX |
NUMBER |
Link ID of the link used to define the start of the subpath. For example, in Figure 5-2 in Section 5.3, the START_LINK_INDEX is 0, and the START_PERCENTAGE is 65. |
END_LINK_INDEX |
NUMBER |
Link ID of the link used to define the end of the subpath. For example, in Figure 5-2 in Section 5.3, the END_LINK_INDEX is 6, and the END_PERCENTAGE is 50. |
START_PERCENTAGE |
NUMBER |
Percentage of the distance between START_LINK_INDEX and the next link in the path, representing the start point of the subpath. Can be a positive or negative number. For example, in Figure 5-2 in Section 5.3, the START_LINK_INDEX is 0, and the START_PERCENTAGE is 65. |
END_PERCENTAGE |
NUMBER |
Percentage of the distance between END_LINK_INDEX and the next link in the path, representing the end point of the subpath. Can be a positive or negative number. For example, in Figure 5-2 in Section 5.3, the END_LINK_INDEX is 6, and the END_PERCENTAGE is 50. |
COST |
NUMBER |
Cost value to be associated with the subpath, for use by applications that use the network. The cost value can represent anything you want, for example, the estimated driving time for the path. |
GEOM |
SDO_GEOMETRY |
For all network types except logical, the geometry object associated with the subpath. The actual column name is either a default name or what you specified as the For a logical network, this column is not used. |
Each partitioned network has a partition table. For information about partitioned networks, see Section 5.7. Each partition table contains the columns described in Table 5-6.
Table 5-6 Partition Table Columns
Column Name | Data Type | Description |
---|---|---|
NODE_ID |
NUMBER |
ID number of the node |
PARTITION_ID |
NUMBER |
ID number of the partition. Must be unique within the network. |
LINK_LEVEL |
NUMBER |
Link level (Link level reflects the priority level for the link, and is used for network analysis, so that links with higher priority levels can be considered first in computing a path.) |
Each partitioned network can have a partition BLOB table, which stores binary large object (BLOB) representations for each combination of link level and partition ID in the network. Having BLOB representations of partitions enables better performance for network load on demand analysis operations. To create the partition BLOB table, use the SDO_NET.GENERATE_PARTITION_BLOBS procedure, where you specify the partition BLOB table name as one of the parameters. For information about partitioned networks, see Section 5.7.
Note:
You should never directly modify the partition BLOB table. This table is automatically updated as a result of calls to the SDO_NET.GENERATE_PARTITION_BLOBS and SDO_NET.GENERATE_PARTITION_BLOB procedures.Each partition table contains the columns described in Table 5-7.
Table 5-7 Partition BLOB Table Columns
Column Name | Data Type | Description |
---|---|---|
LINK_LEVEL |
VARCHAR2(32) |
Link level (Link level reflects the priority level for the link, and is used for network analysis, so that links with higher priority levels can be considered first in computing a path.) |
PARTITION_ID |
NUMBER |
ID number of the partition |
BLOB |
BLOB |
Binary large object (BLOB) representing the specified link level within the specified partition |
NUM_INODES |
NUMBER |
Number of internal nodes in the BLOB (that is, total number of nodes in the BLOB) |
NUM_ENODES |
NUMBER |
Number of external nodes. An external node is a node that is outside the BLOB, but is one end of a link in which the other node is inside the BLOB. |
NUM_ILINKS |
NUMBER |
Number of internal links in the BLOB (that is, links completely inside the BLOB) |
NUM_ELINKS |
NUMBER |
Number of external links. An external link is a link in which one node is internal (inside the BLOB) and one node is external (outside the BLOB). |
NUM_INLINKS |
NUMBER |
Number of incoming links. An incoming link is an external link in which the start node is outside the BLOB and the end node is inside the BLOB. |
NUM_OUTLINKS |
NUMBER |
Number of outgoing links. An outgoing link is an external link in which the start node is inside the BLOB and the end node is outside the BLOB. |
USER_DATA_INCLUDED |
VARCHAR2(1) |
Contains |
Each network can have a connected component table, which stores the component ID for each node. Nodes of the same connected component have the same component ID. Having this information in the table enables better performance for many network analysis operations. To create the connected component table, and to update the contents of the table at any time afterwards, use the SDO_NET.FIND_CONNECTED_COMPONENTS procedure, where you specify the connected component table name as one of the parameters. For more information about using the precomputed information about connected components, see Section 5.7.6.
Each connected component table contains the columns described in Table 5-8.
Table 5-8 Connected Component Table Columns
Column Name | Data Type | Description |
---|---|---|
LINK_LEVEL |
NUMBER |
Link level of the component assignment. (Link level reflects the priority level for the link, and is used for network analysis, so that links with higher priority levels can be considered first in computing a path.) |
NODE_ID |
NUMBER |
ID number of the node from which to compute all other components that are reachable. |
COMPONENT_ID |
NUMBER |
ID number of a component that is reachable from the specified node. |
There is a set of network metadata views for each schema (user): xxx_SDO_NETWORK_METADATA, where xxx can be USER or ALL. These views are created by Spatial.
The following views contain information about networks:
USER_SDO_NETWORK_METADATA contains information about all networks owned by the user.
ALL_SDO_NETWORK_METADATA contains information about all networks on which the user has SELECT permission.
If you create a network using one of the CREATE_<network-type>_NETWORK procedures, the information in these views is automatically updated to reflect the new network; otherwise, you must insert information about the network into the USER_SDO_NETWORK_METADATA view.
The USER_SDO_NETWORK_METADATA and ALL_SDO_NETWORK_METADATA views contain the same columns, as shown Table 5-9, except that the USER_SDO_NETWORK_METADATA view does not contain the OWNER column. (The columns are listed in their order in the view definition.)
Table 5-9 Columns in the xxx_SDO_NETWORK_METADATA Views
Column Name | Data Type | Purpose |
---|---|---|
OWNER |
VARCHAR2(32) |
Owner of the network (ALL_SDO_NETWORK_METADATA view only) |
NETWORK |
VARCHAR2(24) |
Name of the network |
NETWORK_ID |
NUMBER |
ID number of the network; assigned by Spatial |
NETWORK_CATEGORY |
VARCHAR2(12) |
Contains |
GEOMETRY_TYPE |
VARCHAR2(24) |
If |
NETWORK_TYPE |
VARCHAR2(24) |
User-defined string to identify the network type. |
NO_OF_HIERARCHY_LEVELS |
NUMBER |
Number of levels in the network hierarchy. Contains 1 if there is no hierarchy. (See Section 5.5 for information about network hierarchy.) |
NO_OF_PARTITIONS |
NUMBER |
(Not currently used) |
LRS_TABLE_NAME |
VARCHAR2(32) |
If |
LRS_GEOM_COLUMN |
VARCHAR2(32) |
If |
NODE_TABLE_NAME |
VARCHAR2(32) |
If |
NODE_GEOM_COLUMN |
VARCHAR2(32) |
If |
VARCHAR2(1024) |
If |
|
NODE_PARTITION_COLUMN |
VARCHAR2(32) |
(Not currently used). |
VARCHAR2(32) |
If |
|
LINK_TABLE_NAME |
VARCHAR2(32) |
If |
LINK_GEOM_COLUMN |
VARCHAR2(32) |
If |
LINK_DIRECTION |
VARCHAR2(12) |
Contains a value indicating the type for all links in the network: |
VARCHAR2(1024) |
If |
|
LINK_PARTITION_COLUMN |
VARCHAR2(32) |
(Not currently used) |
VARCHAR2(32) |
If |
|
PATH_TABLE_NAME |
VARCHAR2(32) |
Contains the name of an optional table containing information about paths. (The path table is described in Section 5.9.3.) |
PATH_GEOM_COLUMN |
VARCHAR2(32) |
If |
PATH_LINK_TABLE_NAME |
VARCHAR2(32) |
Contains the name of an optional table containing information about links for each path. (The path-link table is described in Section 5.9.4.) |
SUBPATH_TABLE_NAME |
VARCHAR2(32) |
Contains the name of an optional table containing information about subpaths. (The subpath table is described in Section 5.9.5.) |
SUBPATH_GEOM_COLUMN |
VARCHAR2(32) |
If |
PARTITION_TABLE_NAME |
VARCHAR2(32) |
For a partitioned network: the name of the partition table. (The partition table is described in Section 5.9.6. |
PARTITION_BLOB_TABLE_NAME |
VARCHAR2(32) |
For a partitioned network for which any partition BLOBs have been generated: the name of the partition BLOB table. (The partition BLOB table is described in Section 5.9.7. |
COMPONENT_TABLE_NAME |
VARCHAR2(32) |
The name of the table containing information about precomputed connected components, as explained in Section 5.7.6. (The connected component table is described in Section 5.9.8.) |
NODE_LEVEL_TABLE_NAME |
VARCHAR2(32) |
The name of the table containing information about node levels in a hierarchical network. Specify this table as the |
TOPOLOGY |
VARCHAR2(32) |
For a spatial network containing SDO_TOPO_GEOMETRY objects (creating using the SDO_NET.CREATE_TOPO_NETWORK procedure), contains the name of the topology. |
USER_DEFINED_DATA |
VARCHAR2(1) |
Contains Y if the network contains user-defined data; contains N if the network does not contain user-defined data. |
EXTERNAL_REFERENCES |
VARCHAR2(1) |
(Not currently used) |
The following views contain information about network constraints (described in Section 5.6):
USER_SDO_NETWORK_CONSTRAINTS contains information about all network constraints owned by the user.
ALL_SDO_NETWORK_CONSTRAINTS contains information about all network constraints on which the user has SELECT permission.
These views are automatically maintained by the SDO_NET.REGISTER_CONSTRAINT and SDO_NET.DEREGISTER_CONSTRAINT procedures. You should not directly modify the contents of these views.
The USER_SDO_NETWORK_CONSTRAINTS and ALL_SDO_NETWORK_CONSTRAINTS views contain the same columns, as shown Table 5-10, except that the USER_SDO_NETWORK_CONSTRAINTS view does not contain the OWNER column. (The columns are listed in their order in the view definition.)
Table 5-10 Columns in the xxx_SDO_NETWORK_CONSTRAINTS Views
Column Name | Data Type | Purpose |
---|---|---|
OWNER |
VARCHAR2(32) |
Owner of the network constraint (ALL_SDO_NETWORK_CONSTRAINTS view only) |
CONSTRAINT |
VARCHAR2(32) |
Name of the network constraint |
DESCRIPTION |
VARCHAR2(200) |
Descriptive information about the network constraint, such as its purpose and any usage notes |
CLASS_NAME |
VARCHAR2(4000) |
Name of the Java class that implements the network constraint |
CLASS |
BINARY FILE LOB |
The Java class that implements the network constraint |
The following views contain information about network user-defined data, which is the information (not related to connectivity) that users want to associate with a network representation:
USER_SDO_NETWORK_USER_DATA contains information about all network user-defined data owned by the user.
ALL_SDO_NETWORK_USER_DATA contains information about all network user-defined data on which the user has SELECT permission.
The USER_SDO_NETWORK_USER_DATA and ALL_SDO_NETWORK_USER_DATA views contain the same columns, as shown Table 5-10, except that the USER_SDO_NETWORK_USER_DATA view does not contain the OWNER column. (The columns are listed in their order in the view definition.)
Table 5-11 Columns in the xxx_SDO_NETWORK_USER_DATA Views
Column Name | Data Type | Purpose |
---|---|---|
OWNER |
VARCHAR2(32) |
Owner of the network constraint (ALL_SDO_NETWORK_CONSTRAINTS view only) |
NETWORK |
VARCHAR2(32) |
Name of the network |
TABLE_TYPE |
VARCHAR2(12) |
Type of the table containing the user-defined data: |
DATA_NAME |
VARCHAR2(32) |
Name of column containing the user-defined data |
DATA_TYPE |
VARCHAR2(12) |
Data type of the user-defined data: |
DATA_LENGTH |
NUMBER(38) |
If DATA_TYPE is |
For an example of using user-defined data, see Section 5.13.6.
The Oracle Spatial network data model includes two client application programming interfaces (APIs): a PL/SQL interface provided by the SDO_NET and SDO_NET_MEM packages and a Java interface. Both interfaces let you create and update network data, and perform network analysis. It is recommended that you use only PL/SQL or SQL to populate network tables and to create indexes, and that you use either PL/SQL or Java for application development.
The following performance considerations apply to the PL/SQL and Java APIs:
If you plan to analyze or edit only nonspatial aspects of a spatial network, you can get better performance by setting the NETWORK_CATEGORY column value to LOGICAL
in the USER_SDO_NETWORK_METADATA view (described in Section 5.10.1) before performing the analysis or editing, and then changing the value back to SPATIAL
afterward.
For example, you could use this technique when finding the shortest path between two nodes, because the shortest-path computation considers cost values. However, you could not use this technique when setting the spatial geometry object or the end measure value for a link.
If you do not plan to modify any network objects (that is, if you plan to perform only network analysis operations or to retrieve network information), you can get better performance by creating the network memory object as read-only (that is, by specifying that updates are not allowed).
The SDO_NET package provides subprograms for creating, accessing, and managing networks on a database server. The SDO_NET_MEM package, which implements capabilities available through the Java API, provides subprograms for editing network objects and performing network analysis using a cache object called a network memory object. Example 5-4 in Section 5.13 shows the use of SDO_NET functions and procedures. Section 5.8 explains how to use a network memory object, and it contains Example 5-1, which uses SDO_NET_MEM functions and procedures.
The SDO_NET subprograms can be grouped into the following logical categories:
Creating networks:
Copying and deleting networks:
Creating network tables:
Validating network objects:
Retrieving information (getting information about the network, checking for a characteristic):
For reference information about each SDO_NET function and procedure, see Chapter 6.
The SDO_NET_MEM subprograms are grouped according to their associated object-related class in the oracle.spatial.network interface or class. You must specify a prefix after SDO_NET_MEM for each program, depending on its associated class (for example, SDO_NET_MEM.NETWORK_MANAGER.CREATE_LOGICAL_NETWORK, SDO_NET_MEM.NETWORK.ADD_NODE, and SDO_NET_MEM.NODE.GET_COST).
Note:
Although this manual refers to "the SDO_NET_MEM package," all subprograms except one are actually implemented as methods of several object types. Thus, they are not listed by the statementDESCRIBE SDO_NET_MEM
. Instead, you can use the DESCRIBE statements listed in Table 7-1 in Chapter 7 to see the subprograms in each grouping; however, because they are member functions and procedures in an object type, the subprograms in each grouping will not be listed in alphabetical order in the DESCRIBE statement output.The SDO_NET_MEM subprogram groupings are as follows:
SDO_NET_MEM.NETWORK_MANAGER subprograms are related to the oracle.spatial.network.NetworkManager
Java class. They enable you to create and drop network memory objects and to perform network analysis.
SDO_NET_MEM.NETWORK subprograms are related to the oracle.spatial.network.Network
Java interface. They enable you to add and delete nodes, links, and paths.
SDO_NET_MEM.NODE subprograms are related to the oracle.spatial.network.Node
Java interface. They enable you to get and set attributes for nodes.
SDO_NET_MEM.LINK subprograms are related to the oracle.spatial.network.Link
Java interface. They enable you to get and set attributes for links.
SDO_NET_MEM.PATH subprograms are related to the oracle.spatial.network.Path
Java interface. They enable you to get and set attributes for paths.
The associations between SDO_NET_MEM subprograms and methods of the Java API are not necessarily exact. In some cases, a PL/SQL subprogram may combine operations and options from several methods. In addition, some Java methods do not have PL/SQL counterparts. Thus, the Usage Notes for subprograms state only that the function or procedure is analogous to a specific Java method, to indicate a logical relationship between the two. For detailed information about a specific Java method and others that may be related, see the Javadoc-generated API documentation (briefly explained in Section 5.11.2).
For reference information about each SDO_NET_MEM function and procedure, see Chapter 7.
The network data model Java interface includes the in-memory interface and the load on demand interface. Complete reference information about these interfaces is provided in Oracle Spatial Java API Reference. The classes of the in-memory Java interface are in the oracle.spatial.network package
. The classes of the load on demand Java interface are in the oracle.spatial.network.lod
package and its subpackages.
You can use the Java API to perform network metadata and data management operations such as the following:
Insert, delete, and modify node and link data
Load a network from a database
Store a network in a database
Store network metadata in a database
Modify network metadata attributes
You can use the oracle.spatial.network.NetworkManager
class to perform network analysis operations, such as the following, using the in-memory approach:
Shortest path: typical transitive closure problems in graph theory. Given a start and an end node, find the shortest path.
Minimum cost spanning tree: Given an undirected graph, find the minimum cost tree that connects all nodes.
Reachability: Given a node, find all nodes that can reach that node, or find all nodes that can be reached by that node.
Within-cost analysis: Given a target node and a cost, find all nodes that can be reached by the target node within the given cost.
Nearest-neighbors analysis: Given a target node and number of neighbors, find the neighbor nodes and their costs to go to the given target node.
All paths between two nodes: Given two nodes, find all possible paths between them.
"Traveling salesman problem" (TSP) analysis: Given a set of nodes, find the most efficient (lowest-cost or shortest distance) path that visits all nodes, and optionally require that the start and end nodes be the same.
You can use the oracle.spatial.network.lod.NetworkAnalyst
class to perform network analysis operations, such as the following, using the load on demand approach:
Shortest path: typical transitive closure problems in graph theory. Given a start and an end node, find the shortest path.
Reachability: Given a node, find all nodes that can reach that node, or find all nodes that can be reached by that node.
Within-cost analysis: Given a target node and a cost, find all nodes that can be reached by the target node within the given cost.
Nearest-neighbors analysis: Given a target node and number of neighbors, find the neighbor nodes and their costs to go to the given target node.
Dynamic data input: Create and use a NetworkUpdate
object with network update information.
User-defined link and node cost calculators: Define the method for computing the cost of a link or a node.
If database users other than the network owner need to read a network into memory, you need to do one of the following:
For each non-owner user, qualify the network tables with the schema of the network owner in the USER_SDO_NETWORK_METADATA view, as explained in Section 5.12.1.
For each non-owner user, create views on the network data model tables and update the USER_SDO_NETWORK_METADATA view, as explained in Section 5.12.2.
The second approach requires the extra step of creating views, but the views provide you with flexibility in controlling the parts of the network that are accessible. Each view can provide access to all of the network, or it can use a WHERE clause to provide access to just one or more parts (for example, WHERE STATE_CODE='NY'
to restrict the view users to rows for New York) .
Consider the following example scenario:
User1 creates (and thus owns) Network1.
User2 attempts to call the SDO_NET_MEM.NETWORK_MANAGER.READ_NETWORK procedure to read Network1, but receives an error. The error occurs even though User2 has the appropriate privileges on the network data model tables for Network1.
To work around this problem, you must use the approach in either Section 5.12.1, "Cross-Schema Access by Specifying Owner in Network Metadata" or Section 5.12.2, "Cross-Schema Access by Using Views".
To enable a non-owner user (with suitable privileges) to access a network, you can specify the network owner in the network metadata. For each non-owner user that will be permitted to access the network, follow these steps:
Ensure that the user has SELECT access to the necessary network data model tables. If the user does not have this access, connect as the network owner and grant it. For example, connect as User1 and execute the following statements:
GRANT select ON network1_node$ TO user2; GRANT select ON network1_link$ TO user2; GRANT select ON network1_path$ TO user2; GRANT select ON network1_plink$ TO user2;
Connect as the non-owner user. For example, connect as User2.
Use the schema name of the network owner to qualify the network data model tables for the network in the USER_SDO_NETWORK_METADATA view (explained in Section 5.10.1). For example, if the network is not already defined in this view, enter the following while connected as User2:
INSERT INTO user_sdo_network_metadata (network, network_category, geometry_type, node_table_name,node_geom_column, link_table_name, link_geom_column, link_direction, path_table_name, path_geom_column, path_link_table_name) VALUES ('NETWORK1','SPATIAL', 'SDO_GEOMETRY', 'USER1.NETWORK1_NODE$', 'GEOMETRY', 'USER1.NETWORK1_LINK$', 'GEOMETRY', 'DIRECTED', 'USER1.NETWORK1_PATH$', 'GEOMETRY', 'USER1.NETWORK1_PLINK$');
If the network is already defined in this view, update the definition to qualify each table name with the schema name. For example:
UPDATE USER_SDO_NETWORK_METADATA SET node_table_name = 'USER1.NETWORK1_NODE$', link_table_name = 'USER1.NETWORK1_LINK$', path_table_name = 'USER1.NETWORK1_PATH$', path_link_table_name = 'USER1.NETWORK1_PLINK$' WHERE network = 'NETWORK1';
In this scenario, User2 can now read NETWORK1 into memory.
To enable a non-owner user (with suitable privileges) to access a network, or specific parts of a network, you can create views. For each non-owner user that will be permitted to access the network, follow these steps:
Ensure that the user has SELECT access to the necessary network data model tables. If the user does not have this access, connect as the network owner and grant it. For example, connect as User1 and execute the following statements:
GRANT select ON network1_node$ TO user2; GRANT select ON network1_link$ TO user2; GRANT select ON network1_path$ TO user2; GRANT select ON network1_plink$ TO user2;
Connect as the non-owner user. For example, connect as User2.
Create a view on each of the necessary network data model nodes, with each view selecting all columns in the associated table. Qualify the table name with the schema name of the network owner. For example, while connected as User2:
CREATE VIEW network1_node$ AS select * from user1.network1_node$; CREATE VIEW network1_link$ AS select * from user1.network1_link$; CREATE VIEW network1_path$ AS select * from user1.network1_path$; CREATE VIEW network1_plink$ AS select * from user1.network1_plink$;
Note:
Although this example shows views that include all data in the underlying tables, you can restrict the parts of the network that are available by using a WHERE clause in each view definition (for example,WHERE STATE_CODE='NY'
).Add a row specifying the newly created views to the USER_SDO_NETWORK_METADATA view (explained in Section 5.10.1). For example, while connected as User2:
INSERT INTO user_sdo_network_metadata (network, network_category, geometry_type, node_table_name,node_geom_column, link_table_name, link_geom_column, link_direction, path_table_name, path_geom_column, path_link_table_name) VALUES ('NETWORK1','SPATIAL', 'SDO_GEOMETRY', 'NETWORK1_NODE$', 'GEOMETRY', 'NETWORK1_LINK$', 'GEOMETRY', 'DIRECTED', 'NETWORK1_PATH$', 'GEOMETRY', 'NETWORK1_PLINK$');
In this scenario, User2 can now read into memory those parts of NETWORK1 that are available through the views that were created.
This section presents several network data model examples. Most are simplified examples. All examples use the PL/SQL API, and some also use other APIs. This section includes the following subsections:
Section 5.13.1, "Simple Spatial (SDO) Network Example (PL/SQL)"
Section 5.13.4, "Logical Hierarchical Network Example (PL/SQL)"
Section 5.13.5, "Partitioning and Load on Demand Analysis Examples (PL/SQL, XML, and Java)"
Section 5.13.6, "User-Defined Data Example (PL/SQL and Java)"
The examples refer to concepts that are explained in this chapter, and they use PL/SQL functions and procedures documented in Chapter 6.
This section presents an example of a very simple spatial (SDO, not LRS) network that contains three nodes and a link between each node. The network is illustrated in Figure 5-4.
As shown in Figure 5-4, node N1
is at point 1,1, node N2
is at point 15,1, and node N3
is at point 9,4. Link L1
is a straight line connecting nodes N1
and N2
, link L2
is a straight line connecting nodes N2
and N3
, and link L3
is a straight line connecting nodes N3
and N1
. There are no other nodes or shape points on any of the links.
Example 5-2 does the following:
In a call to the SDO_NET.CREATE_SDO_NETWORK procedure, creates the SDO_NET1
directed network; creates the SDO_NET1_NODE$, SDO_NET1_LINK$, SDO_NET1_PATH$, and SDO_NET1_PLINK$ tables; and updates the xxx_SDO_NETWORK_METADATA views. All geometry columns are named GEOMETRY. Both the node and link tables contain a cost column named COST.
Populates the node, link, path, and path-link tables. It inserts three rows into the node table, three rows into the link table, two rows into the path table, and four rows into the path-link table.
Updates the Oracle Spatial metadata, and creates spatial indexes on the GEOMETRY columns of the node and link tables. (These actions are not specifically related to network management, but that are necessary if applications are to benefit from spatial indexing on these geometry columns.)
Example 5-2 does not show the use of many SDO_NET functions and procedures; these are included in Example 5-4 in Section 5.13.3.
Example 5-2 Simple Spatial (SDO) Network Example (PL/SQL)
-- Create the SDO_NET1 directed network. Also creates the SDO_NET1_NODE$, -- SDO_NET1_LINK$, SDO_NET1_PATH$, SDO_NET1_PLINK$ tables, and updates -- USER_SDO_NETWORK_METADATA. All geometry columns are named GEOMETRY. -- Both the node and link tables contain a cost column named COST. EXECUTE SDO_NET.CREATE_SDO_NETWORK('SDO_NET1', 1, TRUE, TRUE); -- Populate the SDO_NET1_NODE$ table. -- N1 INSERT INTO sdo_net1_node$ (node_id, node_name, active, geometry, cost) VALUES(1, 'N1', 'Y', SDO_GEOMETRY(2001, NULL, SDO_POINT_TYPE(1,1,NULL), NULL, NULL), 5); -- N2 INSERT INTO sdo_net1_node$ (node_id, node_name, active, geometry, cost) VALUES(2, 'N2', 'Y', SDO_GEOMETRY(2001, NULL, SDO_POINT_TYPE(15,1,NULL), NULL, NULL), 8); -- N3 INSERT INTO sdo_net1_node$ (node_id, node_name, active, geometry, cost) VALUES(3, 'N3', 'Y', SDO_GEOMETRY(2001, NULL, SDO_POINT_TYPE(9,4,NULL), NULL, NULL), 4); -- Populate the SDO_NET1_LINK$ table. -- L1 INSERT INTO sdo_net1_link$ (link_id, link_name, start_node_id, end_node_id, active, geometry, cost, bidirected) VALUES(1, 'L1', 1, 2, 'Y', SDO_GEOMETRY(2002, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,2,1), SDO_ORDINATE_ARRAY(1,1, 15,1)), 14, 'Y'); -- L2 INSERT INTO sdo_net1_link$ (link_id, link_name, start_node_id, end_node_id, active, geometry, cost, bidirected) VALUES(2, 'L2', 2, 3, 'Y', SDO_GEOMETRY(2002, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,2,1), SDO_ORDINATE_ARRAY(15,1, 9,4)), 10, 'Y'); -- L3 INSERT INTO sdo_net1_link$ (link_id, link_name, start_node_id, end_node_id, active, geometry, cost, bidirected) VALUES(3, 'L3', 3, 1, 'Y', SDO_GEOMETRY(2002, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,2,1), SDO_ORDINATE_ARRAY(9,4, 1,1)), 10, 'Y'); -- Do not populate the SDO_NET1_PATH$ and SDO_NET1_PLINK$ tables now. -- Do this only when you need to create any paths. --------------------------------------------------------------------------- -- REMAINING STEPS NEEDED TO USE SPATIAL INDEXES -- --------------------------------------------------------------------------- -- Update the USER_SDO_GEOM_METADATA view. This is required before the -- spatial index can be created. Do this only once for each layer -- (that is, table-column combination). INSERT INTO user_sdo_geom_metadata (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES ( 'SDO_NET1_NODE$', 'GEOMETRY', SDO_DIM_ARRAY( -- 20X20 grid SDO_DIM_ELEMENT('X', 0, 20, 0.005), SDO_DIM_ELEMENT('Y', 0, 20, 0.005) ), NULL -- SRID (spatial reference system, also called coordinate system) ); INSERT INTO user_sdo_geom_metadata (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES ( 'SDO_NET1_LINK$', 'GEOMETRY', SDO_DIM_ARRAY( -- 20X20 grid SDO_DIM_ELEMENT('X', 0, 20, 0.005), SDO_DIM_ELEMENT('Y', 0, 20, 0.005) ), NULL -- SRID (spatial reference system, also called coordinate system) ); -- Create the spatial indexes CREATE INDEX sdo_net1_nodes_idx ON sdo_net1_node$(geometry) INDEXTYPE IS MDSYS.SPATIAL_INDEX; CREATE INDEX sdo_net1_links_idx ON sdo_net1_link$(geometry) INDEXTYPE IS MDSYS.SPATIAL_INDEX;
This section presents an example of a very simple logical network that contains three nodes and a link between the nodes. The network is illustrated in Figure 5-5.
As shown in Figure 5-5, link L1
is a straight line connecting nodes N1
and N2
, link L2
is a straight line connecting nodes N2
and N3
, and link L3
is a straight line connecting nodes N3
and N1
. There are no other nodes on any of the links.
Example 5-3 calls the SDO_NET.CREATE_LOGICAL_NETWORK procedure, which does the following: creates the LOG_NET1
directed network; creates the LOG_NET1_NODE$, LOG_NET1_LINK$, LOG_NET1_PATH$, and LOG_NET1_PLINK$ tables; and updates the xxx_SDO_NETWORK_METADATA views. Both the node and link tables contain a cost column named COST. (Because this is a logical network, there are no geometry columns.) The example also populates the node and link tables.
Example 5-3 does not show the use of many SDO_NET functions and procedures; these are included in the logical hierarchical network example (Example 5-5) in Section 5.13.4.
Example 5-3 Simple Logical Network Example (PL/SQL)
-- Creates the LOG_NET1 directed logical network. Also creates the -- LOG_NET1_NODE$, LOG_NET1_LINK$, LOG_NET1_PATH$, -- and LOG_NET1_PLINK$ tables, and updates USER_SDO_NETWORK_METADATA. -- Both the node and link tables contain a cost column named COST. EXECUTE SDO_NET.CREATE_LOGICAL_NETWORK('LOG_NET1', 1, TRUE, TRUE); -- Populate the LOG_NET1_NODE$ table. -- N1 INSERT INTO log_net1_node$ (node_id, node_name, active, cost) VALUES (1, 'N1', 'Y', 2); -- N2 INSERT INTO log_net1_node$ (node_id, node_name, active, cost) VALUES (2, 'N2', 'Y', 3); -- N3 INSERT INTO log_net1_node$ (node_id, node_name, active, cost) VALUES (3, 'N3', 'Y', 2); -- Populate the LOG_NET1_LINK$ table. -- L1 INSERT INTO log_net1_link$ (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1, 'L1', 1, 2, 'Y', 1, 10); -- L2 INSERT INTO log_net1_link$ (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (2, 'L2', 2, 3, 'Y', 1, 7); -- L3 INSERT INTO log_net1_link$ (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (3, 'L3', 3, 1, 'Y', 1, 8); -- Do not populate the LOG_NET1_PATH$ and LOG_NET1_PLINK$ tables now. -- Do this only when you need to create any paths.
This section presents an example of a spatial (LRS) network that uses the roads (routes) illustrated in Figure 5-6. Each road is built from individual line segments (associated with links) taken from one or more road segment geometries, which are also shown in the figure.
Figure 5-6 Roads and Road Segments for Spatial (LRS) Network Example
As shown in Figure 5-6:
Route1
starts at point 2,2 and ends at point 5,14. It has the following nodes: N1
, N2
, N3
, N4
, N5
, N6
, and N7
. It has the following links: R1L1
, R1L2
, R1L3
, R1L4
, R1L5
, and R1L6
.
Route2
starts at point 8,4 and ends at point 8,13. It has the following nodes: N3
, N6
, and N8
. It has the following links: R2L1
and R2L2
.
Route3
starts at point 12,10 and ends at point 5,14. It has the following nodes: N5
, N8
, and N7
. It has the following links: R3L1
and R3L2
.
The four road segment geometries are shown individually on the right side of the figure. (The points on each segment are labeled with their associated node names, to clarify how each segment geometry fits into the illustration on the left side.)
Example 5-4 does the following:
Creates a table to hold the road segment geometries.
Inserts four road segment geometries into the table.
Inserts the spatial metadata into the USER_SDO_GEOM_METADATA view.
Creates a spatial index on the geometry column in the ROAD_SEGMENTS table.
Creates and populates the node table.
Creates and populates the link table.
Creates and populates the path table and path-link table, for possible future use. (Before an application can use paths, you must populate these two tables.)
Inserts network metadata into the USER_SDO_NETWORK_METADATA view.
Uses various SDO_NET and SDO_NET_MEM functions and procedures.
Example 5-4 Spatial (LRS) Network Example (PL/SQL)
--------------------------------------------------------------------------- -- CREATE AND POPULATE TABLE -- --------------------------------------------------------------------------- -- Create a table for road segments. Use LRS. CREATE TABLE road_segments ( segment_id NUMBER PRIMARY KEY, segment_name VARCHAR2(32), segment_geom SDO_GEOMETRY, geom_id NUMBER); -- Populate the table with road segments. INSERT INTO road_segments VALUES( 1, 'Segment1', SDO_GEOMETRY( 3302, -- line string, 3 dimensions (X,Y,M), 3rd is measure dimension NULL, NULL, SDO_ELEM_INFO_ARRAY(1,2,1), -- one line string, straight segments SDO_ORDINATE_ARRAY( 2,2,0, -- Starting point - Node1; 0 is measure from start. 2,4,2, -- Node2; 2 is measure from start. 8,4,8, -- Node3; 8 is measure from start. 12,4,12) -- Node4; 12 is measure from start. ), 1001 ); INSERT INTO road_segments VALUES( 2, 'Segment2', SDO_GEOMETRY( 3302, -- line string, 3 dimensions (X,Y,M), 3rd is measure dimension NULL, NULL, SDO_ELEM_INFO_ARRAY(1,2,1), -- one line string, straight segments SDO_ORDINATE_ARRAY( 8,4,0, -- Node3; 0 is measure from start. 8,10,6, -- Node6; 6 is measure from start. 8,13,9) -- Ending point - Node8; 9 is measure from start. ), 1002 ); INSERT INTO road_segments VALUES( 3, 'Segment3', SDO_GEOMETRY( 3302, -- line string, 3 dimensions (X,Y,M), 3rd is measure dimension NULL, NULL, SDO_ELEM_INFO_ARRAY(1,2,1), -- one line string, straight segments SDO_ORDINATE_ARRAY( 12,4,0, -- Node4; 0 is measure from start. 12,10,6, -- Node5; 6 is measure from start. 8,13,11, -- Node8; 11 is measure from start. 5,14,14.16) -- Ending point - Node7; 14.16 is measure from start. ), 1003 ); INSERT INTO road_segments VALUES( 4, 'Segment4', SDO_GEOMETRY( 3302, -- line string, 3 dimensions (X,Y,M), 3rd is measure dimension NULL, NULL, SDO_ELEM_INFO_ARRAY(1,2,1), -- one line string, straight segments SDO_ORDINATE_ARRAY( 12,10,0, -- Node5; 0 is measure from start. 8,10,4, -- Node6; 4 is measure from start. 5,14,9) -- Ending point - Node7; 9 is measure from start. ), 1004 ); --------------------------------------------------------------------------- -- UPDATE THE SPATIAL METADATA -- --------------------------------------------------------------------------- -- Update the USER_SDO_GEOM_METADATA view. This is required before the -- spatial index can be created. Do this only once for each layer -- (that is, table-column combination; here: road_segment and segment_geom). INSERT INTO user_sdo_geom_metadata (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES ( 'ROAD_SEGMENTS', 'SEGMENT_GEOM', SDO_DIM_ARRAY( -- 20X20 grid SDO_DIM_ELEMENT('X', 0, 20, 0.005), SDO_DIM_ELEMENT('Y', 0, 20, 0.005), SDO_DIM_ELEMENT('M', 0, 20, 0.005) -- Measure dimension ), NULL -- SRID (spatial reference system, also called coordinate system) ); ------------------------------------------------------------------- -- CREATE THE SPATIAL INDEX -- ------------------------------------------------------------------- CREATE INDEX road_segments_idx ON road_segments(segment_geom) INDEXTYPE IS MDSYS.SPATIAL_INDEX; -------------------------------- -- USE SDO_NET SUBPROGRAMS -------------------------------- -- This procedure does not use the CREATE_LRS_NETWORK procedure. Instead, -- the user creates the network tables and populates the network metadata view. -- Basic steps: -- 1. Create and populate the node table. -- 2. Create and populate the link table. -- 3. Create the path table and paths and links table (for possible -- future use, before which they will need to be populated). -- 4. Populate the network metadata (USER_SDO_NETWORK_METADATA). -- Note: Can be done before or after Steps 1-3. -- 5. Use various SDO_NET functions and procedures. -- 6. Use SDO_NET_MEM functions and procedures for analysis and editing. -- 1. Create and populate the node table. EXECUTE SDO_NET.CREATE_NODE_TABLE('ROADS_NODES', 'LRS_GEOMETRY', 'NODE_GEOMETRY', 'COST', 1); -- Populate the node table. -- N1 INSERT INTO roads_nodes (node_id, node_name, active, geom_id, measure) VALUES (1, 'N1', 'Y', 1001, 0); -- N2 INSERT INTO roads_nodes (node_id, node_name, active, geom_id, measure) VALUES (2, 'N2', 'Y', 1001, 2); -- N3 INSERT INTO roads_nodes (node_id, node_name, active, geom_id, measure) VALUES (3, 'N3', 'Y', 1001, 8); -- N4 INSERT INTO roads_nodes (node_id, node_name, active, geom_id, measure) VALUES (4, 'N4', 'Y', 1001, 12); -- N5 INSERT INTO roads_nodes (node_id, node_name, active, geom_id, measure) VALUES (5, 'N5', 'Y', 1004, 0); -- N6 INSERT INTO roads_nodes (node_id, node_name, active, geom_id, measure) VALUES (6, 'N6', 'Y', 1002, 6); -- N7 INSERT INTO roads_nodes (node_id, node_name, active, geom_id, measure) VALUES (7, 'N7', 'Y', 1004, 9); -- N8 INSERT INTO roads_nodes (node_id, node_name, active, geom_id, measure) VALUES (8, 'N8', 'Y', 1002, 9); -- 2. Create and populate the link table. EXECUTE SDO_NET.CREATE_LINK_TABLE('ROADS_LINKS', 'LRS_GEOMETRY', 'LINK_GEOMETRY', 'COST', 1); -- Populate the link table. -- Route1, Link1 INSERT INTO roads_links (link_id, link_name, start_node_id, end_node_id, active, cost, geom_id, start_measure, end_measure) VALUES (101, 'R1L1', 1, 2, 'Y', 3, 1001, 0, 2); -- Route1, Link2 INSERT INTO roads_links (link_id, link_name, start_node_id, end_node_id, active, cost, geom_id, start_measure, end_measure) VALUES (102, 'R1L2', 2, 3, 'Y', 15, 1001, 2, 8); -- Route1, Link3 INSERT INTO roads_links (link_id, link_name, start_node_id, end_node_id, active, cost, geom_id, start_measure, end_measure) VALUES (103, 'R1L3', 3, 4, 'Y', 10, 1001, 8, 12); -- Route1, Link4 INSERT INTO roads_links (link_id, link_name, start_node_id, end_node_id, active, cost, geom_id, start_measure, end_measure) VALUES (104, 'R1L4', 4, 5, 'Y', 15, 1003, 0, 6); -- Route1, Link5 INSERT INTO roads_links (link_id, link_name, start_node_id, end_node_id, active, cost, geom_id, start_measure, end_measure) VALUES (105, 'R1L5', 5, 6, 'Y', 10, 1004, 0, 4); -- Route1, Link6 INSERT INTO roads_links (link_id, link_name, start_node_id, end_node_id, active, cost, geom_id, start_measure, end_measure) VALUES (106, 'R1L6', 6, 7, 'Y', 7, 1004, 4, 9); -- Route2, Link1 (cost = 30, a slow drive) INSERT INTO roads_links (link_id, link_name, start_node_id, end_node_id, active, cost, geom_id, start_measure, end_measure) VALUES (201, 'R2L1', 3, 6, 'Y', 30, 1002, 0, 6); -- Route2, Link2 INSERT INTO roads_links (link_id, link_name, start_node_id, end_node_id, active, cost, geom_id, start_measure, end_measure) VALUES (202, 'R2L2', 6, 8, 'Y', 5, 1002, 6, 9); -- Route3, Link1 INSERT INTO roads_links (link_id, link_name, start_node_id, end_node_id, active, cost, geom_id, start_measure, end_measure) VALUES (301, 'R3L1', 5, 8, 'Y', 5, 1003, 6, 11); -- Route3, Link2 INSERT INTO roads_links (link_id, link_name, start_node_id, end_node_id, active, cost, geom_id, start_measure, end_measure) VALUES (302, 'R3L2', 8, 7, 'Y', 5, 1003, 11, 14.16); -- 3. Create the path table (to store created paths) and the path-link -- table (to store links for each path) for possible future use, -- before which they will need to be populated. EXECUTE SDO_NET.CREATE_PATH_TABLE('ROADS_PATHS', 'PATH_GEOMETRY'); EXECUTE SDO_NET.CREATE_PATH_LINK_TABLE('ROADS_PATHS_LINKS'); -- 4. Populate the network metadata (USER_SDO_NETWORK_METADATA). INSERT INTO user_sdo_network_metadata (NETWORK, NETWORK_CATEGORY, GEOMETRY_TYPE, NETWORK_TYPE, NO_OF_HIERARCHY_LEVELS, NO_OF_PARTITIONS, LRS_TABLE_NAME, LRS_GEOM_COLUMN, NODE_TABLE_NAME, NODE_GEOM_COLUMN, NODE_COST_COLUMN, LINK_TABLE_NAME, LINK_GEOM_COLUMN, LINK_DIRECTION, LINK_COST_COLUMN, PATH_TABLE_NAME, PATH_GEOM_COLUMN, PATH_LINK_TABLE_NAME) VALUES ( 'ROADS_NETWORK', -- Network name 'SPATIAL', -- Network category 'LRS_GEOMETRY', -- Geometry type 'Roadways', -- Network type (user-defined) 1, -- No. of levels in hierarchy 1, -- No. of partitions 'ROAD_SEGMENTS', -- LRS table name 'SEGMENT_GEOM' , -- LRS geometry column 'ROADS_NODES', -- Node table name 'NODE_GEOMETRY', -- Node geometry column 'COST', -- Node cost column 'ROADS_LINKS', -- Link table name 'LINK_GEOMETRY', -- Link geometry column 'DIRECTED', -- Link direction 'COST', -- Link cost column 'ROADS_PATHS', -- Path table name 'PATH_GEOMETRY', -- Path geometry column 'ROADS_PATHS_LINKS' -- Paths and links table ); -- 5. Use various SDO_NET functions and procedures. -- Validate the network. SELECT SDO_NET.VALIDATE_NETWORK('ROADS_NETWORK') FROM DUAL; -- Validate parts or aspects of the network. SELECT SDO_NET.VALIDATE_LINK_SCHEMA('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.VALIDATE_LRS_SCHEMA('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.VALIDATE_NODE_SCHEMA('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.VALIDATE_PATH_SCHEMA('ROADS_NETWORK') FROM DUAL; -- Retrieve various information (GET_xxx and some other functions). SELECT SDO_NET.GET_CHILD_LINKS('ROADS_NETWORK', 101) FROM DUAL; SELECT SDO_NET.GET_CHILD_NODES('ROADS_NETWORK', 1) FROM DUAL; SELECT SDO_NET.GET_GEOMETRY_TYPE('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_IN_LINKS('ROADS_NETWORK', 3) FROM DUAL; SELECT SDO_NET.GET_INVALID_LINKS('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_INVALID_NODES('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_INVALID_PATHS('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_ISOLATED_NODES('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_LINK_COST_COLUMN('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_LINK_DIRECTION('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_LINK_GEOM_COLUMN('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_LINK_GEOMETRY('ROADS_NETWORK', 103) FROM DUAL; SELECT SDO_NET.GET_LINK_TABLE_NAME('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_LRS_GEOM_COLUMN('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_LRS_LINK_GEOMETRY('ROADS_NETWORK', 103) FROM DUAL; SELECT SDO_NET.GET_LRS_NODE_GEOMETRY('ROADS_NETWORK', 3) FROM DUAL; SELECT SDO_NET.GET_LRS_TABLE_NAME('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NETWORK_CATEGORY('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NETWORK_ID('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NETWORK_NAME(3) FROM DUAL; SELECT SDO_NET.GET_NETWORK_TYPE('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NO_OF_HIERARCHY_LEVELS('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NO_OF_LINKS('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NO_OF_NODES('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NODE_DEGREE('ROADS_NETWORK', 3) FROM DUAL; SELECT SDO_NET.GET_NODE_GEOM_COLUMN('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NODE_GEOMETRY('ROADS_NETWORK', 3) FROM DUAL; SELECT SDO_NET.GET_NODE_IN_DEGREE('ROADS_NETWORK', 3) FROM DUAL; SELECT SDO_NET.GET_NODE_OUT_DEGREE('ROADS_NETWORK', 3) FROM DUAL; SELECT SDO_NET.GET_NODE_TABLE_NAME('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NODE_COST_COLUMN('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NODE_HIERARCHY_LEVEL('ROADS_NETWORK', 3) FROM DUAL; SELECT SDO_NET.GET_OUT_LINKS('ROADS_NETWORK', 3) FROM DUAL; SELECT SDO_NET.GET_PATH_GEOM_COLUMN('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.GET_PATH_TABLE_NAME('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.IS_COMPLEX('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.IS_HIERARCHICAL('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.IS_LOGICAL('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.IS_SIMPLE('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.IS_SPATIAL('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.LRS_GEOMETRY_NETWORK('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.NETWORK_EXISTS('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.SDO_GEOMETRY_NETWORK('ROADS_NETWORK') FROM DUAL; SELECT SDO_NET.TOPO_GEOMETRY_NETWORK('ROADS_NETWORK') FROM DUAL; -- Copy a network. EXECUTE SDO_NET.COPY_NETWORK('ROADS_NETWORK', 'ROADS_NETWORK2'); -- Create a trigger. EXECUTE SDO_NET.CREATE_DELETE_TRIGGER('ROADS_NETWORK'); -- 6. Use SDO_NET_MEM functions and procedures for analysis and editing. -- Network analysis and other operations (SDO_NET_MEM.NETWORK_MANAGER) DECLARE net_mem VARCHAR2(100); res_string VARCHAR2(1000); cost NUMBER; res_numeric NUMBER; res_array SDO_NUMBER_ARRAY; indx NUMBER; indx1 NUMBER; var1_numeric NUMBER; var1_array SDO_NUMBER_ARRAY; BEGIN net_mem := 'ROADS_NETWORK'; -- Read in the network. SDO_NET_MEM.NETWORK_MANAGER.READ_NETWORK(net_mem, 'TRUE'); -- Validate the network. res_string := SDO_NET_MEM.NETWORK_MANAGER.VALIDATE_NETWORK_SCHEMA(net_mem); DBMS_OUTPUT.PUT_LINE('Is network ' || net_mem || ' valid? ' || res_string); res_string := SDO_NET_MEM.NETWORK_MANAGER.LIST_NETWORKS; DBMS_OUTPUT.PUT_LINE('The current in-memory network(s) is/are: ' || res_string); res_numeric := SDO_NET_MEM.NETWORK_MANAGER.FIND_CONNECTED_COMPONENTS(net_mem); DBMS_OUTPUT.PUT_LINE('The number of connected components is: ' || res_numeric); res_array := SDO_NET_MEM.NETWORK_MANAGER.MCST_LINK(net_mem); DBMS_OUTPUT.PUT('Network ' || net_mem || ' has the following MCST links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.NETWORK_MANAGER.FIND_REACHABLE_NODES(net_mem,1); DBMS_OUTPUT.PUT_LINE('Reachable nodes from 1: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT(res_numeric || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.NETWORK_MANAGER.NEAREST_NEIGHBORS(net_mem,6,3); DBMS_OUTPUT.PUT_LINE('Path IDs to the nearest 3 neighbors of node 6 are: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT(res_numeric || ', which contains links: '); var1_array := SDO_NET_MEM.PATH.GET_LINK_IDS(net_mem, res_numeric); FOR indx1 IN var1_array.FIRST..var1_array.LAST LOOP var1_numeric := var1_array(indx1); DBMS_OUTPUT.PUT(var1_numeric || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.NETWORK_MANAGER.NEAREST_NEIGHBORS(net_mem,6,3); DBMS_OUTPUT.PUT_LINE('Path IDs to the nearest 3 neighbors of node 6 are: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT(res_numeric || ', whose end node is: '); var1_numeric := SDO_NET_MEM.PATH.GET_END_NODE_ID(net_mem, res_numeric); DBMS_OUTPUT.PUT(var1_numeric); DBMS_OUTPUT.PUT_LINE(' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_string := SDO_NET_MEM.NETWORK_MANAGER.IS_REACHABLE(net_mem,1,5); DBMS_OUTPUT.PUT_LINE('Can node 1 reach node 5? ' || res_string); res_array := SDO_NET_MEM.NETWORK_MANAGER.ALL_PATHS(net_mem,1,5,10,200,5); DBMS_OUTPUT.PUT_LINE('For each path from node 1 to node 5: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT_LINE('Path ' || res_numeric || ' has the following properties: '); cost := SDO_NET_MEM.PATH.GET_COST(net_mem, res_numeric); DBMS_OUTPUT.PUT_LINE('Path ' || res_numeric || ' cost: ' || cost); res_string := SDO_NET_MEM.PATH.IS_CLOSED(net_mem, res_array(indx)); DBMS_OUTPUT.PUT_LINE('Is path ' || res_numeric || ' closed? ' || res_string); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_numeric := SDO_NET_MEM.NETWORK_MANAGER.SHORTEST_PATH(net_mem,1,5); DBMS_OUTPUT.PUT_LINE('The shortest path from node 1 to node 5 is path ID: ' || res_numeric); DBMS_OUTPUT.PUT_LINE('The following are characteristics of this shortest path: '); cost := SDO_NET_MEM.PATH.GET_COST(net_mem, res_numeric); DBMS_OUTPUT.PUT_LINE('Path ' || res_numeric || ' has cost: ' || cost); res_string := SDO_NET_MEM.PATH.IS_CLOSED(net_mem, res_numeric); DBMS_OUTPUT.PUT_LINE('Is path ' || res_numeric || ' closed? ' || res_string); DBMS_OUTPUT.PUT_LINE(' '); res_numeric := SDO_NET_MEM.NETWORK_MANAGER.SHORTEST_PATH_DIJKSTRA(net_mem,1,5); DBMS_OUTPUT.PUT_LINE('The shortest Dijkstra path from node 1 to node 5 is ' || res_numeric); DBMS_OUTPUT.PUT_LINE('The following are characteristics of this shortest path: '); cost := SDO_NET_MEM.PATH.GET_COST(net_mem, res_numeric); DBMS_OUTPUT.PUT_LINE('Path ' || res_numeric || ' cost: ' || cost); res_string := SDO_NET_MEM.PATH.IS_CLOSED(net_mem, res_numeric); DBMS_OUTPUT.PUT_LINE('Is path ' || res_numeric || ' closed? ' || res_string); res_array := SDO_NET_MEM.PATH.GET_LINK_IDS(net_mem, res_numeric); DBMS_OUTPUT.PUT('Path ' || res_numeric || ' has links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.PATH.GET_NODE_IDS(net_mem, res_numeric); DBMS_OUTPUT.PUT('Path ' || res_numeric || ' has nodes: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.NETWORK_MANAGER.WITHIN_COST(net_mem,2,20); DBMS_OUTPUT.PUT('Path IDs to nodes within cost of 40 from node 2: '); DBMS_OUTPUT.PUT_LINE(' '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT(res_numeric || ', whose end node is: '); var1_numeric := SDO_NET_MEM.PATH.GET_END_NODE_ID(net_mem, res_numeric); DBMS_OUTPUT.PUT(var1_numeric); DBMS_OUTPUT.PUT_LINE(' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); END; / -- Link editing (SDO_NET_MEM.LINK) DECLARE net_mem VARCHAR2(32); res_string VARCHAR2(100); res_numeric NUMBER; res_geom SDO_GEOMETRY; res_array SDO_NUMBER_ARRAY; indx NUMBER; BEGIN net_mem := 'ROADS_NETWORK'; -- GET_COST res_numeric := SDO_NET_MEM.LINK.GET_COST(net_mem, 104); DBMS_OUTPUT.PUT_LINE('The cost of link 104 is: ' || res_numeric); -- GET_END_MEASURE res_numeric := SDO_NET_MEM.LINK.GET_END_MEASURE(net_mem, 104); DBMS_OUTPUT.PUT_LINE('The end measure of link 104 is: ' || res_numeric); -- GET_END_NODE_ID res_numeric := SDO_NET_MEM.LINK.GET_END_NODE_ID(net_mem, 104); DBMS_OUTPUT.PUT_LINE('The end node of link 104 is: ' || res_numeric); -- GET_GEOM_ID res_numeric := SDO_NET_MEM.LINK.GET_GEOM_ID(net_mem, 104); DBMS_OUTPUT.PUT_LINE('The geometry ID of link 104 is: ' || res_numeric); -- GET_GEOMETRY res_geom := SDO_NET_MEM.LINK.GET_GEOMETRY(net_mem, 104); -- GET_NAME res_string := SDO_NET_MEM.LINK.GET_NAME(net_mem, 104); DBMS_OUTPUT.PUT_LINE('The name of link 104 is: ' || res_string); -- GET_START_MEASURE res_numeric := SDO_NET_MEM.LINK.GET_START_MEASURE(net_mem, 104); DBMS_OUTPUT.PUT_LINE('The start measure of link 104 is: ' || res_numeric); -- GET_START_NODE_ID res_numeric := SDO_NET_MEM.LINK.GET_START_NODE_ID(net_mem, 104); DBMS_OUTPUT.PUT_LINE('The start node of link 104 is: ' || res_numeric); -- GET_STATE res_string := SDO_NET_MEM.LINK.GET_STATE(net_mem, 104); DBMS_OUTPUT.PUT_LINE('The state of link 104 is: ' || res_string); -- IS_ACTIVE res_string := SDO_NET_MEM.LINK.IS_ACTIVE(net_mem, 104); DBMS_OUTPUT.PUT_LINE('Is link 104 active?: ' || res_string); -- IS_LOGICAL res_string := SDO_NET_MEM.LINK.IS_LOGICAL(net_mem, 104); DBMS_OUTPUT.PUT_LINE('Is link 104 a logical link?: ' || res_string); -- IS_TEMPORARY res_string := SDO_NET_MEM.LINK.IS_TEMPORARY(net_mem, 104); DBMS_OUTPUT.PUT_LINE('Is link 104 temporary?: ' || res_string); -- SET_COST -- Set the cost of link 302 to 6. SDO_NET_MEM.LINK.SET_COST(net_mem, 302, 6); -- SET_MEASURE -- Set the measure value of link 302 as from 111 to 114.16. SDO_NET_MEM.LINK.SET_MEASURE(net_mem, 302, 111, 114.16); -- SET_NAME -- Set the name of link 302 to 'My favorite link'. SDO_NET_MEM.LINK.SET_NAME(net_mem, 302, 'My favorite link'); -- SET_STATE -- Set the state of link 302 to 'INACTIVE'. SDO_NET_MEM.LINK.SET_STATE(net_mem, 302, 'INACTIVE'); -- GET_STATE res_string := SDO_NET_MEM.LINK.GET_STATE(net_mem, 302); DBMS_OUTPUT.PUT_LINE('The state of link 302 is: ' || res_string); -- SET_TYPE -- Set the type of link 302 to 'Normal street'. SDO_NET_MEM.LINK.SET_TYPE(net_mem, 302, 'Normal street'); -- GET_TYPE res_string := SDO_NET_MEM.LINK.GET_TYPE(net_mem, 302); DBMS_OUTPUT.PUT_LINE('The type of link 302 is: ' || res_string); END; / -- Node editing (SDO_NET_MEM.NODE) DECLARE net_mem VARCHAR2(32); res_string VARCHAR2(100); res_numeric NUMBER; res_geom SDO_GEOMETRY; res_array SDO_NUMBER_ARRAY; indx NUMBER; BEGIN net_mem := 'ROADS_NETWORK'; -- GET_COMPONENT_NO res_numeric := SDO_NET_MEM.NODE.GET_COMPONENT_NO(net_mem, 3); DBMS_OUTPUT.PUT_LINE('The component number of node 3 is: ' || res_numeric); -- GET_COST res_numeric := SDO_NET_MEM.NODE.GET_COST(net_mem, 3); DBMS_OUTPUT.PUT_LINE('The cost of node 3 is: ' || res_numeric); -- GET_GEOM_ID res_numeric := SDO_NET_MEM.NODE.GET_GEOM_ID(net_mem, 3); DBMS_OUTPUT.PUT_LINE('The geometry ID of node 3 is: ' || res_numeric); -- GET_GEOMETRY res_geom := SDO_NET_MEM.NODE.GET_GEOMETRY(net_mem, 3); -- GET_IN_LINK_IDS res_array := SDO_NET_MEM.NODE.GET_IN_LINK_IDS(net_mem, 3); DBMS_OUTPUT.PUT('Node 3 has the following inbound links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_INCIDENT_LINK_IDS res_array := SDO_NET_MEM.NODE.GET_INCIDENT_LINK_IDS(net_mem, 3); DBMS_OUTPUT.PUT('Node 3 has the following incident links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_MEASURE res_numeric := SDO_NET_MEM.NODE.GET_MEASURE(net_mem, 3); DBMS_OUTPUT.PUT_LINE('The measure value of node 3 is: ' || res_numeric); -- GET_NAME res_string := SDO_NET_MEM.NODE.GET_NAME(net_mem, 3); DBMS_OUTPUT.PUT_LINE('The name of node 3 is: ' || res_string); -- GET_OUT_LINK_IDS res_array := SDO_NET_MEM.NODE.GET_OUT_LINK_IDS(net_mem, 3); DBMS_OUTPUT.PUT('Node 3 has the following outbound links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_STATE res_string := SDO_NET_MEM.NODE.GET_STATE(net_mem, 3); DBMS_OUTPUT.PUT_LINE('The state of node 3 is: ' || res_string); -- IS_ACTIVE res_string := SDO_NET_MEM.NODE.IS_ACTIVE(net_mem, 3); DBMS_OUTPUT.PUT_LINE('Is node 3 active?: ' || res_string); -- IS_LOGICAL res_string := SDO_NET_MEM.NODE.IS_LOGICAL(net_mem, 3); DBMS_OUTPUT.PUT_LINE('Is node 3 a logical node?: ' || res_string); -- IS_TEMPORARY res_string := SDO_NET_MEM.NODE.IS_TEMPORARY(net_mem, 3); DBMS_OUTPUT.PUT_LINE('Is node 3 temporary?: ' || res_string); -- LINK_EXISTS res_string := SDO_NET_MEM.NODE.LINK_EXISTS(net_mem, 3, 4); DBMS_OUTPUT.PUT_LINE('Does a link exist between nodes 3 and 4?: ' || res_string); -- MAKE_TEMPORARY -- Make node 7 temporary. SDO_NET_MEM.NODE.MAKE_TEMPORARY(net_mem, 7); -- SET_COMPONENT_NO -- Set the component number of node 7 to 987. SDO_NET_MEM.NODE.SET_COMPONENT_NO(net_mem, 7, 987); -- SET_COST -- Set the cost of node 7 to 40. SDO_NET_MEM.NODE.SET_COST(net_mem, 7, 40); -- SET_GEOM_ID -- Set the geometry ID of node 7 to 99. SDO_NET_MEM.NODE.SET_GEOM_ID(net_mem, 7, 99); -- SET_MEASURE -- Set the measure value of node 7 to 30. SDO_NET_MEM.NODE.SET_MEASURE(net_mem, 7, 30); -- SET_NAME -- Set the name of node 7 to 'My favorite node'. SDO_NET_MEM.NODE.SET_NAME(net_mem, 7, 'My favorite node'); -- GET_NAME res_string := SDO_NET_MEM.NODE.GET_NAME(net_mem, 7); DBMS_OUTPUT.PUT_LINE('The name of node 7 is: ' || res_string); -- SET_STATE -- Set the state of node 7 to 'INACTIVE'. SDO_NET_MEM.NODE.SET_STATE(net_mem, 7, 'INACTIVE'); -- GET_STATE res_string := SDO_NET_MEM.NODE.GET_STATE(net_mem, 7); DBMS_OUTPUT.PUT_LINE('The state of node 7 is: ' || res_string); -- SET_TYPE -- Set the type of node 7 to 'Historic site'. SDO_NET_MEM.NODE.SET_TYPE(net_mem, 7, 'Historic site'); -- GET_TYPE res_string := SDO_NET_MEM.NODE.GET_TYPE(net_mem, 7); DBMS_OUTPUT.PUT_LINE('The type of node 7 is: ' || res_string); END; / -- Path editing (SDO_NET_MEM.PATH) DECLARE net_mem VARCHAR2(32); res_string VARCHAR2(100); res_numeric NUMBER; res_geom SDO_GEOMETRY; path_id NUMBER; res_array SDO_NUMBER_ARRAY; indx NUMBER; BEGIN net_mem := 'ROADS_NETWORK'; -- Create a path for use with subsequent statements. Here, it is -- the shortest path between nodes 1 (N1) and 5 (N5). path_id := SDO_NET_MEM.NETWORK_MANAGER.SHORTEST_PATH(net_mem,1,5); DBMS_OUTPUT.PUT_LINE('The shortest path between nodes 1 and 5 is: ' || path_id); -- GET_LINK_IDS res_array := SDO_NET_MEM.PATH.GET_LINK_IDS(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Path ' || path_id || ' has the following links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_COST res_numeric := SDO_NET_MEM.PATH.GET_COST(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The cost of path ' || path_id || ' is: ' || res_numeric); -- GET_END_NODE_ID res_numeric := SDO_NET_MEM.PATH.GET_END_NODE_ID(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The end node ID of path ' || path_id || ' is: ' || res_numeric); -- GET_GEOMETRY res_geom := SDO_NET_MEM.PATH.GET_GEOMETRY(net_mem, path_id); -- doesn't work DBMS_OUTPUT.PUT_LINE('The geometry of path ' || path_id || ' is: ' || res_geom); -- GET_LINK_IDS res_array := SDO_NET_MEM.PATH.GET_LINK_IDS(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Path ' || path_id || ' has the following links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_NAME res_string := SDO_NET_MEM.PATH.GET_NAME(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The name of path ' || path_id || ' is: ' || res_string); -- GET_NO_OF_LINKS res_numeric := SDO_NET_MEM.PATH.GET_NO_OF_LINKS(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The number of links in path ' || path_id || ' is: ' || res_numeric); -- GET_NODE_IDS res_array := SDO_NET_MEM.PATH.GET_NODE_IDS(net_mem, path_id); DBMS_OUTPUT.PUT('Path ' || path_id || ' has the following nodes: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_START_NODE_ID res_numeric := SDO_NET_MEM.PATH.GET_START_NODE_ID(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The start node ID of path ' || path_id || ' is: ' || res_numeric); -- IS_ACTIVE res_string := SDO_NET_MEM.PATH.IS_ACTIVE(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' active?: ' || res_string); -- IS_CLOSED res_string := SDO_NET_MEM.PATH.IS_CLOSED(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' closed?: ' || res_string); -- IS_CONNECTED res_string := SDO_NET_MEM.PATH.IS_CONNECTED(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' connected?: ' || res_string); -- IS_LOGICAL res_string := SDO_NET_MEM.PATH.IS_LOGICAL(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' a logical path?: ' || res_string); -- IS_SIMPLE res_string := SDO_NET_MEM.PATH.IS_SIMPLE(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' a simple path?: ' || res_string); -- IS_TEMPORARY res_string := SDO_NET_MEM.PATH.IS_TEMPORARY(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' temporary?: ' || res_string); -- SET_NAME -- Set the name of path to 'My favorite path'. SDO_NET_MEM.PATH.SET_NAME(net_mem, path_id, 'My favorite path'); -- GET_NAME res_string := SDO_NET_MEM.PATH.GET_NAME(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The name of path ' || path_id || ' is: ' || res_string); -- SET_TYPE -- Set the type of the path to 'Scenic'. SDO_NET_MEM.PATH.SET_TYPE(net_mem, path_id, 'Scenic'); -- GET_TYPE res_string := SDO_NET_MEM.PATH.GET_TYPE(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The type of path ' || path_id || ' is: ' || res_string); -- SET_PATH_ID -- Set (change) the path ID of the path to 6789. SDO_NET_MEM.PATH.SET_PATH_ID(net_mem, path_id, 6789); END; /
This section presents an example of a logical network that contains the nodes and links illustrated in Figure 5-7. Because it is a logical network, there are no spatial geometries associated with it. (Figure 5-7 is essentially the same as Figure 5-3 in Section 5.5, but with the nodes and links labeled.)
Figure 5-7 Nodes and Links for Logical Network Example
As shown in Figure 5-7:
The network is hierarchical, with two levels. The top level (level 2) consists of two nodes (HN1
and HN2
), and the remaining nodes and links are in the bottom level (level 1) of the hierarchy.
Each node in level 1 is a child node of one of the nodes in level 2. Node HN1
has the following child nodes: N1
, N2
, N3
, N4
, N5
, and N6
. Node HN2
has the following child nodes: N7
, N8
, N9
, N10
, N11
, N12
, N13
, and N14
.
One link (HN1HN2
) links nodes HN1
and HN2
, and two links (N5N8
and N6N7
) are child links of parent link HN1HN2
. Note, however, that links are not associated with a specific network hierarchy level.
Example 5-5 does the following:
Creates and populates the node table.
Creates and populates the link table.
Creates and populates the path table and path-link table, for possible future use. (Before an application can use paths, you must populate these two tables.)
Inserts network metadata into the USER_SDO_NETWORK_METADATA view.
Uses various SDO_NET functions and procedures.
Uses SDO_NET_MEM functions and procedures for analysis and editing.
Example 5-5 Logical Network Example (PL/SQL)
-- Basic steps: -- 1. Create and populate the node table. -- 2. Create and populate the link table. -- 3. Create the path table and paths and links table (for possible -- future use, before which they will need to be populated). -- 4. Populate the network metadata (USER_SDO_NETWORK_METADATA). -- Note: Can be done before or after Steps 1-3. -- 5. Use various SDO_NET functions and procedures. -- 6. Use SDO_NET_MEM functions and procedures for analysis and editing. -- 1. Create and populate the node table. EXECUTE SDO_NET.CREATE_NODE_TABLE('XYZ_NODES', NULL, NULL, NULL, 2); -- Populate the node table, starting with the highest level in the hierarchy. -- HN1 (Hierarchy level=2, highest in this network) INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level) VALUES (1, 'HN1', 'Y', 2); -- HN2 (Hierarchy level=2, highest in this network) INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level) VALUES (2, 'HN2', 'Y', 2); -- N1 (Hierarchy level 1, parent node ID = 1 for N1 through N6) INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (101, 'N1', 'Y', 1, 1); -- N2 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (102, 'N2', 'Y', 1, 1); -- N3 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (103, 'N3', 'Y', 1, 1); -- N4 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (104, 'N4', 'Y', 1, 1); -- N5 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (105, 'N5', 'Y', 1, 1); -- N6 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (106, 'N6', 'Y', 1, 1); -- N7 (Hierarchy level 1, parent node ID = 2 for N7 through N14) INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (107, 'N7', 'Y', 1, 2); -- N8 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (108, 'N8', 'Y', 1, 2); -- N9 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (109, 'N9', 'Y', 1, 2); -- N10 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (110, 'N10', 'Y', 1, 2); -- N11 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (111, 'N11', 'Y', 1, 2); -- N12 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (112, 'N12', 'Y', 1, 2); -- N13 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (113, 'N13', 'Y', 1, 2); -- N14 INSERT INTO xyz_nodes (node_id, node_name, active, hierarchy_level, parent_node_id) VALUES (114, 'N14', 'Y', 1, 2); -- 2. Create and populate the link table. EXECUTE SDO_NET.CREATE_LINK_TABLE('XYZ_LINKS', NULL, NULL, 'COST', 2); -- Populate the link table. -- HN1HN2 (single link in highest hierarchy level: link level = 2) INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level) VALUES (1001, 'HN1HN2', 1, 2, 'Y', 2); -- For remaining links, link level = 1 and cost (10, 20, or 30) varies among links. -- N1N2 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1101, 'N1N2', 101, 102, 'Y', 1, 10); -- N1N3 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1102, 'N1N3', 101, 103, 'Y', 1, 20); -- N2N3 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1103, 'N2N3', 102, 103, 'Y', 1, 30); -- N3N4 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1104, 'N3N4', 103, 104, 'Y', 1, 10); -- N4N5 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1105, 'N4N5', 104, 105, 'Y', 1, 20); -- N4N6 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1106, 'N4N6', 104, 106, 'Y', 1, 30); -- N5N6 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1107, 'N5N6', 105, 106, 'Y', 1, 10); -- N5N8 (child of the higher-level link: parent ID = 1001) INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost, parent_link_id) VALUES (1108, 'N5N8', 105, 108, 'Y', 1, 20, 1001); -- N6N7 (child of the higher-level link: parent ID = 1001) INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost, parent_link_id) VALUES (1109, 'N6N7', 106, 107, 'Y', 1, 30, 1001); -- N7N8 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1110, 'N7N8', 107, 108, 'Y', 1, 10); -- N7N9 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1111, 'N7N9', 107, 109, 'Y', 1, 20); -- N8N9 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1112, 'N8N9', 108, 109, 'Y', 1, 30); -- N9N10 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1113, 'N9N10', 109, 110, 'Y', 1, 30); -- N9N13 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1114, 'N9N13', 109, 113, 'Y', 1, 10); -- N10N11 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1115, 'N10N11', 110, 111, 'Y', 1, 20); -- N11N12 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1116, 'N11N12', 111, 112, 'Y', 1, 30); -- N12N13 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1117, 'N12N13', 112, 113, 'Y', 1, 10); -- N12N14 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1118, 'N12N14', 112, 114, 'Y', 1, 20); -- N13N14 INSERT INTO xyz_links (link_id, link_name, start_node_id, end_node_id, active, link_level, cost) VALUES (1119, 'N13N14', 113, 114, 'Y', 1, 30); -- 3. Create the path table (to store created paths) and the path-link -- table (to store links for each path) for possible future use, -- before which they will need to be populated. EXECUTE SDO_NET.CREATE_PATH_TABLE('XYZ_PATHS', NULL); EXECUTE SDO_NET.CREATE_PATH_LINK_TABLE('XYZ_PATHS_LINKS'); -- 4. Populate the network metadata (USER_SDO_NETWORK_METADATA). INSERT INTO user_sdo_network_metadata (NETWORK, NETWORK_CATEGORY, NO_OF_HIERARCHY_LEVELS, NO_OF_PARTITIONS, NODE_TABLE_NAME, LINK_TABLE_NAME, LINK_DIRECTION, LINK_COST_COLUMN, PATH_TABLE_NAME, PATH_LINK_TABLE_NAME) VALUES ( 'XYZ_NETWORK', -- Network name 'LOGICAL', -- Network category 2, -- No. of levels in hierarchy 1, -- No. of partitions 'XYZ_NODES', -- Node table name 'XYZ_LINKS', -- Link table name 'BIDIRECTED', -- Link direction 'COST', -- Link cost column 'XYZ_PATHS', -- Path table name 'XYZ_PATHS_LINKS' -- Path-link table name ); -- 5. Use various SDO_NET functions and procedures. -- Validate the network. SELECT SDO_NET.VALIDATE_NETWORK('XYZ_NETWORK') FROM DUAL; -- Validate parts or aspects of the network. SELECT SDO_NET.VALIDATE_LINK_SCHEMA('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.VALIDATE_LRS_SCHEMA('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.VALIDATE_NODE_SCHEMA('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.VALIDATE_PATH_SCHEMA('XYZ_NETWORK') FROM DUAL; -- Retrieve various information (GET_xxx and some other functions). SELECT SDO_NET.GET_CHILD_LINKS('XYZ_NETWORK', 1001) FROM DUAL; SELECT SDO_NET.GET_CHILD_NODES('XYZ_NETWORK', 1) FROM DUAL; SELECT SDO_NET.GET_CHILD_NODES('XYZ_NETWORK', 2) FROM DUAL; SELECT SDO_NET.GET_IN_LINKS('XYZ_NETWORK', 104) FROM DUAL; SELECT SDO_NET.GET_LINK_COST_COLUMN('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.GET_LINK_DIRECTION('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.GET_LINK_TABLE_NAME('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NETWORK_TYPE('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NO_OF_HIERARCHY_LEVELS('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NO_OF_LINKS('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NO_OF_NODES('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.GET_NODE_DEGREE('XYZ_NETWORK', 104) FROM DUAL; SELECT SDO_NET.GET_NODE_IN_DEGREE('XYZ_NETWORK', 104) FROM DUAL; SELECT SDO_NET.GET_NODE_OUT_DEGREE('XYZ_NETWORK', 104) FROM DUAL; SELECT SDO_NET.GET_OUT_LINKS('XYZ_NETWORK', 104) FROM DUAL; SELECT SDO_NET.GET_PATH_TABLE_NAME('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.IS_HIERARCHICAL('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.IS_LOGICAL('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.IS_SPATIAL('XYZ_NETWORK') FROM DUAL; SELECT SDO_NET.NETWORK_EXISTS('XYZ_NETWORK') FROM DUAL; -- Copy a network. EXECUTE SDO_NET.COPY_NETWORK('XYZ_NETWORK', 'XYZ_NETWORK2'); -- Create a trigger. EXECUTE SDO_NET.CREATE_DELETE_TRIGGER('XYZ_NETWORK'); -- 6. Use SDO_NET_MEM functions and procedures for analysis and editing. -- Network analysis and other operations (SDO_NET_MEM.NETWORK_MANAGER) DECLARE net_mem VARCHAR2(100); res_string VARCHAR2(1000); cost NUMBER; res_numeric NUMBER; res_array SDO_NUMBER_ARRAY; indx NUMBER; indx1 NUMBER; var1_numeric NUMBER; var1_array SDO_NUMBER_ARRAY; BEGIN net_mem := 'XYZ_NETWORK'; -- Read in the network. SDO_NET_MEM.NETWORK_MANAGER.READ_NETWORK(net_mem, 'TRUE'); -- Validate the network. res_string := SDO_NET_MEM.NETWORK_MANAGER.VALIDATE_NETWORK_SCHEMA(net_mem); DBMS_OUTPUT.PUT_LINE('Is network ' || net_mem || ' valid? ' || res_string); res_string := SDO_NET_MEM.NETWORK_MANAGER.LIST_NETWORKS; DBMS_OUTPUT.PUT_LINE('The current in-memory network(s) is/are: ' || res_string); res_numeric := SDO_NET_MEM.NETWORK_MANAGER.FIND_CONNECTED_COMPONENTS(net_mem); DBMS_OUTPUT.PUT_LINE('The number of connected components is: ' || res_numeric); res_array := SDO_NET_MEM.NETWORK_MANAGER.MCST_LINK(net_mem); DBMS_OUTPUT.PUT('Network ' || net_mem || ' has the following MCST links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.NETWORK_MANAGER.FIND_REACHABLE_NODES(net_mem,101); DBMS_OUTPUT.PUT_LINE('Reachable nodes from 101: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT(res_numeric || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.NETWORK_MANAGER.FIND_REACHING_NODES(net_mem,101); DBMS_OUTPUT.PUT_LINE('Nodes from which 101 can be reached: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT(res_numeric || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.NETWORK_MANAGER.NEAREST_NEIGHBORS(net_mem,101,3); DBMS_OUTPUT.PUT_LINE('Path IDs to the nearest 3 neighbors of node 101 are: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT(res_numeric || ', which contains links: '); var1_array := SDO_NET_MEM.PATH.GET_LINK_IDS(net_mem, res_numeric); FOR indx1 IN var1_array.FIRST..var1_array.LAST LOOP var1_numeric := var1_array(indx1); DBMS_OUTPUT.PUT(var1_numeric || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.NETWORK_MANAGER.NEAREST_NEIGHBORS(net_mem,101,3); DBMS_OUTPUT.PUT_LINE('Path IDs to the nearest 3 neighbors of node 101 are: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT(res_numeric || ', whose end node is: '); var1_numeric := SDO_NET_MEM.PATH.GET_END_NODE_ID(net_mem, res_numeric); DBMS_OUTPUT.PUT(var1_numeric); DBMS_OUTPUT.PUT_LINE(' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_string := SDO_NET_MEM.NETWORK_MANAGER.IS_REACHABLE(net_mem,101,105); DBMS_OUTPUT.PUT_LINE('Can node 101 reach node 105? ' || res_string); res_array := SDO_NET_MEM.NETWORK_MANAGER.ALL_PATHS(net_mem,101,105,10,200,5); DBMS_OUTPUT.PUT_LINE('For each path from node 101 to node 105: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT_LINE('Path ' || res_numeric || ' has the following properties: '); cost := SDO_NET_MEM.PATH.GET_COST(net_mem, res_numeric); DBMS_OUTPUT.PUT_LINE('Path ' || res_numeric || ' cost: ' || cost); res_string := SDO_NET_MEM.PATH.IS_CLOSED(net_mem, res_array(indx)); DBMS_OUTPUT.PUT_LINE('Is path ' || res_numeric || ' closed? ' || res_string); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_numeric := SDO_NET_MEM.NETWORK_MANAGER.SHORTEST_PATH(net_mem,101,105); DBMS_OUTPUT.PUT_LINE('The shortest path from node 101 to node 105 is path ID: ' || res_numeric); DBMS_OUTPUT.PUT_LINE('The following are characteristics of this shortest path: '); cost := SDO_NET_MEM.PATH.GET_COST(net_mem, res_numeric); DBMS_OUTPUT.PUT_LINE('Path ' || res_numeric || ' has cost: ' || cost); res_string := SDO_NET_MEM.PATH.IS_CLOSED(net_mem, res_numeric); DBMS_OUTPUT.PUT_LINE('Is path ' || res_numeric || ' closed? ' || res_string); res_array := SDO_NET_MEM.PATH.GET_LINK_IDS(net_mem, res_numeric); DBMS_OUTPUT.PUT('Path ' || res_numeric || ' has links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); DBMS_OUTPUT.PUT_LINE(' '); res_numeric := SDO_NET_MEM.NETWORK_MANAGER.SHORTEST_PATH_DIJKSTRA(net_mem,101,105); DBMS_OUTPUT.PUT_LINE('The shortest Dijkstra path from node 101 to node 105 is ' || res_numeric); DBMS_OUTPUT.PUT_LINE('The following are characteristics of this shortest path: '); cost := SDO_NET_MEM.PATH.GET_COST(net_mem, res_numeric); DBMS_OUTPUT.PUT_LINE('Path ' || res_numeric || ' cost: ' || cost); res_string := SDO_NET_MEM.PATH.IS_CLOSED(net_mem, res_numeric); DBMS_OUTPUT.PUT_LINE('Is path ' || res_numeric || ' closed? ' || res_string); res_array := SDO_NET_MEM.PATH.GET_LINK_IDS(net_mem, res_numeric); DBMS_OUTPUT.PUT('Path ' || res_numeric || ' has links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.PATH.GET_NODE_IDS(net_mem, res_numeric); DBMS_OUTPUT.PUT('Path ' || res_numeric || ' has nodes: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); res_array := SDO_NET_MEM.NETWORK_MANAGER.WITHIN_COST(net_mem,102,100); DBMS_OUTPUT.PUT('Shortest path IDs to nodes within cost of 100 from node 102: '); DBMS_OUTPUT.PUT_LINE(' '); FOR indx IN res_array.FIRST..res_array.LAST LOOP res_numeric := res_array(indx); DBMS_OUTPUT.PUT(res_numeric || ', whose end node is: '); var1_numeric := SDO_NET_MEM.PATH.GET_END_NODE_ID(net_mem, res_numeric); DBMS_OUTPUT.PUT(var1_numeric); DBMS_OUTPUT.PUT_LINE(' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); END; / -- Link editing (SDO_NET_MEM.LINK) DECLARE net_mem VARCHAR2(32); res_string VARCHAR2(100); res_numeric NUMBER; res_array SDO_NUMBER_ARRAY; indx NUMBER; BEGIN net_mem := 'XYZ_NETWORK'; -- Read in the network. -- SDO_NET_MEM.NETWORK_MANAGER.READ_NETWORK(net_mem, 'TRUE'); -- GET_CHILD_LINKS res_array := SDO_NET_MEM.LINK.GET_CHILD_LINKS(net_mem, 1001); DBMS_OUTPUT.PUT('Link 1001 has the following child links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_COST res_numeric := SDO_NET_MEM.LINK.GET_COST(net_mem, 1104); DBMS_OUTPUT.PUT_LINE('The cost of link 1104 is: ' || res_numeric); -- GET_END_NODE_ID res_numeric := SDO_NET_MEM.LINK.GET_END_NODE_ID(net_mem, 1104); DBMS_OUTPUT.PUT_LINE('The end node of link 1104 is: ' || res_numeric); -- GET_LEVEL res_numeric := SDO_NET_MEM.LINK.GET_LEVEL(net_mem, 1001); DBMS_OUTPUT.PUT_LINE('The hierarchy level of link 1001 is: ' || res_numeric); -- GET_NAME res_string := SDO_NET_MEM.LINK.GET_NAME(net_mem, 1104); DBMS_OUTPUT.PUT_LINE('The name of link 1104 is: ' || res_string); -- GET_PARENT_LINK_ID res_numeric := SDO_NET_MEM.LINK.GET_PARENT_LINK_ID(net_mem, 1108); DBMS_OUTPUT.PUT_LINE('The parent link of link 1108 is: ' || res_numeric); -- GET_SIBLING_LINK_IDS res_array := SDO_NET_MEM.LINK.GET_SIBLING_LINK_IDS(net_mem, 1108); DBMS_OUTPUT.PUT('Link 1108 has the following sibling links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_START_NODE_ID res_numeric := SDO_NET_MEM.LINK.GET_START_NODE_ID(net_mem, 1104); DBMS_OUTPUT.PUT_LINE('The start node of link 1104 is: ' || res_numeric); -- GET_STATE res_string := SDO_NET_MEM.LINK.GET_STATE(net_mem, 1104); DBMS_OUTPUT.PUT_LINE('The state of link 1104 is: ' || res_string); -- IS_ACTIVE res_string := SDO_NET_MEM.LINK.IS_ACTIVE(net_mem, 1104); DBMS_OUTPUT.PUT_LINE('Is link 1104 active?: ' || res_string); -- IS_LOGICAL res_string := SDO_NET_MEM.LINK.IS_LOGICAL(net_mem, 1104); DBMS_OUTPUT.PUT_LINE('Is link 1104 a logical link?: ' || res_string); -- IS_TEMPORARY res_string := SDO_NET_MEM.LINK.IS_TEMPORARY(net_mem, 1104); DBMS_OUTPUT.PUT_LINE('Is link 1104 temporary?: ' || res_string); -- SET_COST -- Set the cost of link 1119 to 40. SDO_NET_MEM.LINK.SET_COST(net_mem, 1119, 40); -- SET_END_NODE -- Set the end node of link 1119 to 109 (N9). SDO_NET_MEM.LINK.SET_END_NODE(net_mem, 1119, 109); -- SET_LEVEL -- Set the hierarchy level of link 1119 to 2. SDO_NET_MEM.LINK.SET_LEVEL(net_mem, 1119, 2); -- SET_NAME -- Set the name of link 1119 to 'My favorite link'. SDO_NET_MEM.LINK.SET_NAME(net_mem, 1119, 'My favorite link'); -- SET_PARENT_LINK -- Make link 1001 the parent of link 1119. SDO_NET_MEM.LINK.SET_PARENT_LINK(net_mem, 1119, 1001); -- SET_START_NODE -- Set the start node of link 1119 to 110 (N10). SDO_NET_MEM.LINK.SET_START_NODE(net_mem, 1119, 110); -- SET_STATE -- Set the state of link 1119 to 'INACTIVE'. SDO_NET_MEM.LINK.SET_STATE(net_mem, 1119, 'INACTIVE'); -- GET_STATE res_string := SDO_NET_MEM.LINK.GET_STATE(net_mem, 1119); DBMS_OUTPUT.PUT_LINE('The state of link 1119 is: ' || res_string); -- SET_TYPE -- Set the type of link 1119 to 'Associative'. SDO_NET_MEM.LINK.SET_TYPE(net_mem, 1119, 'Associative'); -- GET_TYPE res_string := SDO_NET_MEM.LINK.GET_TYPE(net_mem, 1119); DBMS_OUTPUT.PUT_LINE('The type of link 1119 is: ' || res_string); END; / -- Node editing (SDO_NET_MEM.NODE) DECLARE net_mem VARCHAR2(32); res_string VARCHAR2(100); res_numeric NUMBER; res_array SDO_NUMBER_ARRAY; indx NUMBER; BEGIN net_mem := 'XYZ_NETWORK'; -- GET_ADJACENT_NODE_IDS res_array := SDO_NET_MEM.NODE.GET_ADJACENT_NODE_IDS(net_mem, 103); DBMS_OUTPUT.PUT('Node 103 has the following adjacent nodes: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_CHILD_NODE_IDS res_array := SDO_NET_MEM.NODE.GET_CHILD_NODE_IDS(net_mem, 1); DBMS_OUTPUT.PUT('Node 1 has the following child nodes: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_COMPONENT_NO res_numeric := SDO_NET_MEM.NODE.GET_COMPONENT_NO(net_mem, 103); DBMS_OUTPUT.PUT_LINE('The component number of node 103 is: ' || res_numeric); -- GET_COST res_numeric := SDO_NET_MEM.NODE.GET_COST(net_mem, 103); DBMS_OUTPUT.PUT_LINE('The cost of node 103 is: ' || res_numeric); -- GET_HIERARCHY_LEVEL res_numeric := SDO_NET_MEM.NODE.GET_HIERARCHY_LEVEL(net_mem, 1); DBMS_OUTPUT.PUT_LINE('The hierarchy level of node 1 is: ' || res_numeric); -- GET_IN_LINK_IDS res_array := SDO_NET_MEM.NODE.GET_IN_LINK_IDS(net_mem, 103); DBMS_OUTPUT.PUT('Node 103 has the following inbound links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_INCIDENT_LINK_IDS res_array := SDO_NET_MEM.NODE.GET_INCIDENT_LINK_IDS(net_mem, 103); DBMS_OUTPUT.PUT('Node 103 has the following incident links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_NAME res_string := SDO_NET_MEM.NODE.GET_NAME(net_mem, 103); DBMS_OUTPUT.PUT_LINE('The name of node 103 is: ' || res_string); -- GET_OUT_LINK_IDS res_array := SDO_NET_MEM.NODE.GET_OUT_LINK_IDS(net_mem, 103); DBMS_OUTPUT.PUT('Node 103 has the following outbound links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_PARENT_NODE_ID res_numeric := SDO_NET_MEM.NODE.GET_PARENT_NODE_ID(net_mem, 103); DBMS_OUTPUT.PUT_LINE('The parent node of node 103 is: ' || res_numeric); -- GET_SIBLING_NODE_IDS res_array := SDO_NET_MEM.NODE.GET_SIBLING_NODE_IDS(net_mem, 103); DBMS_OUTPUT.PUT('Node 103 has the following sibling nodes: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_STATE res_string := SDO_NET_MEM.NODE.GET_STATE(net_mem, 103); DBMS_OUTPUT.PUT_LINE('The state of node 103 is: ' || res_string); -- IS_ACTIVE res_string := SDO_NET_MEM.NODE.IS_ACTIVE(net_mem, 103); DBMS_OUTPUT.PUT_LINE('Is node 103 active?: ' || res_string); -- IS_LOGICAL res_string := SDO_NET_MEM.NODE.IS_LOGICAL(net_mem, 103); DBMS_OUTPUT.PUT_LINE('Is node 103 a logical node?: ' || res_string); -- IS_TEMPORARY res_string := SDO_NET_MEM.NODE.IS_TEMPORARY(net_mem, 103); DBMS_OUTPUT.PUT_LINE('Is node 103 temporary?: ' || res_string); -- LINK_EXISTS res_string := SDO_NET_MEM.NODE.LINK_EXISTS(net_mem, 103, 104); DBMS_OUTPUT.PUT_LINE('Does a link exist between nodes 103 and 104?: ' || res_string); -- MAKE_TEMPORARY -- Make node 114 temporary. SDO_NET_MEM.NODE.MAKE_TEMPORARY(net_mem, 114); -- SET_COMPONENT_NO -- Set the component number of node 114 to 987. SDO_NET_MEM.NODE.SET_COMPONENT_NO(net_mem, 114, 987); -- SET_COST -- Set the cost of node 114 to 40. SDO_NET_MEM.NODE.SET_COST(net_mem, 114, 40); -- SET_HIERARCHY_LEVEL -- Set the hierarchy level of node 1 to 2. SDO_NET_MEM.NODE.SET_HIERARCHY_LEVEL(net_mem, 1, 2); -- SET_NAME -- Set the name of node 114 to 'My favorite node'. SDO_NET_MEM.NODE.SET_NAME(net_mem, 114, 'My favorite node'); -- GET_NAME res_string := SDO_NET_MEM.NODE.GET_NAME(net_mem, 114); DBMS_OUTPUT.PUT_LINE('The name of node 114 is: ' || res_string); -- SET_PARENT_NODE -- Make node 1 the parent of node 114. SDO_NET_MEM.NODE.SET_PARENT_NODE(net_mem, 114, 1); -- SET_STATE -- Set the state of node 111 to 'INACTIVE'. SDO_NET_MEM.NODE.SET_STATE(net_mem, 111, 'INACTIVE'); -- GET_STATE res_string := SDO_NET_MEM.NODE.GET_STATE(net_mem, 111); DBMS_OUTPUT.PUT_LINE('The state of node 111 is: ' || res_string); -- SET_TYPE -- Set the type of node 114 to 'Research'. SDO_NET_MEM.NODE.SET_TYPE(net_mem, 114, 'Research'); -- GET_TYPE res_string := SDO_NET_MEM.NODE.GET_TYPE(net_mem, 114); DBMS_OUTPUT.PUT_LINE('The type of node 114 is: ' || res_string); END; / -- Path editing (SDO_NET_MEM.PATH) DECLARE net_mem VARCHAR2(32); res_string VARCHAR2(100); res_numeric NUMBER; path_id NUMBER; res_array SDO_NUMBER_ARRAY; indx NUMBER; BEGIN net_mem := 'XYZ_NETWORK'; -- Create a path for use with subsequent statements. Here, it is -- the shortest path between nodes 101 (N1) and 105 (N5). path_id := SDO_NET_MEM.NETWORK_MANAGER.SHORTEST_PATH(net_mem,101,105); DBMS_OUTPUT.PUT_LINE('The shortest path between nodes 101 and 105 is: ' || path_id); -- GET_LINK_IDS res_array := SDO_NET_MEM.PATH.GET_LINK_IDS(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Path ' || path_id || ' has the following links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_COST res_numeric := SDO_NET_MEM.PATH.GET_COST(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The cost of path ' || path_id || ' is: ' || res_numeric); -- GET_END_NODE_ID res_numeric := SDO_NET_MEM.PATH.GET_END_NODE_ID(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The end node ID of path ' || path_id || ' is: ' || res_numeric); -- GET_LINK_IDS res_array := SDO_NET_MEM.PATH.GET_LINK_IDS(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Path ' || path_id || ' has the following links: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_NO_OF_LINKS res_numeric := SDO_NET_MEM.PATH.GET_NO_OF_LINKS(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The number of links in path ' || path_id || ' is: ' || res_numeric); -- GET_NODE_IDS res_array := SDO_NET_MEM.PATH.GET_NODE_IDS(net_mem, path_id); DBMS_OUTPUT.PUT('Path ' || path_id || ' has the following nodes: '); FOR indx IN res_array.FIRST..res_array.LAST LOOP DBMS_OUTPUT.PUT(res_array(indx) || ' '); END LOOP; DBMS_OUTPUT.PUT_LINE(' '); -- GET_START_NODE_ID res_numeric := SDO_NET_MEM.PATH.GET_START_NODE_ID(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The start node ID of path ' || path_id || ' is: ' || res_numeric); -- IS_ACTIVE res_string := SDO_NET_MEM.PATH.IS_ACTIVE(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' active?: ' || res_string); -- IS_CLOSED res_string := SDO_NET_MEM.PATH.IS_CLOSED(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' closed?: ' || res_string); -- IS_CONNECTED res_string := SDO_NET_MEM.PATH.IS_CONNECTED(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' connected?: ' || res_string); -- IS_LOGICAL res_string := SDO_NET_MEM.PATH.IS_LOGICAL(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' a logical path?: ' || res_string); -- IS_SIMPLE res_string := SDO_NET_MEM.PATH.IS_SIMPLE(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' a simple path?: ' || res_string); -- IS_TEMPORARY res_string := SDO_NET_MEM.PATH.IS_TEMPORARY(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('Is path ' || path_id || ' temporary?: ' || res_string); -- SET_NAME -- Set the name of path to 'My favorite path'. SDO_NET_MEM.PATH.SET_NAME(net_mem, path_id, 'My favorite path'); -- GET_NAME res_string := SDO_NET_MEM.PATH.GET_NAME(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The name of path ' || path_id || ' is: ' || res_string); -- SET_TYPE -- Set the type of the path to 'Logical connections'. SDO_NET_MEM.PATH.SET_TYPE(net_mem, path_id, 'Logical connections'); -- GET_TYPE res_string := SDO_NET_MEM.PATH.GET_TYPE(net_mem, path_id); DBMS_OUTPUT.PUT_LINE('The type of path ' || path_id || ' is: ' || res_string); -- SET_PATH_ID -- Set (change) the path ID of the path to 6789. SDO_NET_MEM.PATH.SET_PATH_ID(net_mem, path_id, 6789); -- Get maximum link, node, path, subpath IDs. SELECT SDO_NET_MEM.NETWORK.GET_MAX_LINK_ID(net_mem) INTO res_numeric FROM DUAL; DBMS_OUTPUT.PUT_LINE('Maximum link ID = ' || res_numeric); SELECT SDO_NET_MEM.NETWORK.GET_MAX_NODE_ID(net_mem) INTO res_numeric FROM DUAL; DBMS_OUTPUT.PUT_LINE('Maximum node ID = ' || res_numeric); SELECT SDO_NET_MEM.NETWORK.GET_MAX_PATH_ID(net_mem) INTO res_numeric FROM DUAL; DBMS_OUTPUT.PUT_LINE('Maximum path ID = ' || res_numeric); SELECT SDO_NET_MEM.NETWORK.GET_MAX_SUBPATH_ID(net_mem) INTO res_numeric FROM DUAL; DBMS_OUTPUT.PUT_LINE('Maximum subpath ID = ' || res_numeric); END; /
This section presents examples of partitioning a network, including related operations, and performing load on demand network analysis. The examples illustrate concepts and techniques explained in Section 5.7.
Example 5-6 partitions a spatial network named NYC_NET
. (Assume that this network already exists and its metadata, node, and link tables are populated.)
Example 5-6 Partitioning a Spatial Network
exec sdo_net.spatial_partition( network->'NYC_NET', -- network name partition_table_name->'NYC_PART$', -- partition table name max_num_nodes->5000, -- max. number of nodes per partition log_loc->'MDDIR', -- partition log directory log_file->'nyc_part.log', --partition log file name open_mode->'w', -- partition log file open mode link_level->1); -- link level
Example 5-7 generates partition BLOBs for the network.
Example 5-7 Generating Partition BLOBs
exec sdo_net.generate_partition_blobs( network->'NYC_NET', ,-- network name link_level ->1, -- link level partition_blob_table_name->'NYC_PBLOB$', -- partition blob table name includeUserdata->FALSE, -- include user data in partition blobs? log_loc->'MYDIR', -- partition log directory log_file->'nyc_part.log', --partition log file name open_mode->'a'); -- partition log file open mode
Example 5-6 and Example 5-7 generate the necessary partition tables for the NYC_NET
network. After executing these examples, you can check the .log file for the current status or any errors encountered during partitioning or BLOB generation.
Example 5-8 shows the XML for configuring the load on demand environment, including the partition cache.
Example 5-8 Configuring the Load on Demand Environment, Including Partition Cache
<?xml version="1.0" encoding="UTF-8" ?> <LODConfigs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.oracle.com/spatial/network/lodLODConfigs.xsd" xmlns="http://www.oracle.com/spatial/network/lod"> <!-- default configuration for networks not configured --> <defaultLODConfig> <LODConfig> <readPartitionFromBlob>false</readPartitionFromBlob> <partitionBlobTranslator>oracle.spatial.network.lod.PartitionBlobTranslator11g</partitionBlobTranslator> <userDataIO>oracle.spatial.network.lod.LODUserDataIOSDO</userDataIO> <cachingPolicy> <linkLevelCachingPolicy> <linkLevel>1</linkLevel> <maxNodes>500000</maxNodes> <residentPartitions>-1</residentPartitions> <flushRule>oracle.spatial.network.lod.LRUCachingHandler</flushRule> </linkLevelCachingPolicy> </cachingPolicy> </LODConfig> </defaultLODConfig> … <networkLODConfig> <!-- network to be configured --> <networkName> NYC_NET </networkName> <LODConfig> <!- read partitions from partition table or from partition blob table --> <readPartitionFromBlob>true</readPartitionFromBlob> <partitionBlobTranslator>oracle.spatial.network.lod.PartitionBlobTranslator11g</partitionBlobTranslator> <userDataIO>oracle.spatial.network.lod.LODUserDataIOSDO</userDataIO> <cachingPolicy> <linkLevelCachingPolicy> <linkLevel>1</linkLevel> <!-- Maximum number of nodes allowed in cache --> <maxNodes>500000</maxNodes> <!-- resident partitions --> <residentPartitions>-1</residentPartitions> <flushRule>oracle.spatial.network.lod.LRUCachingHandler</flushRule> </linkLevelCachingPolicy> <linkLevelCachingPolicy> <linkLevel>2</linkLevel> <maxNodes>500000</maxNodes> <residentPartitions>*</residentPartitions> <flushRule>oracle.spatial.network.lod.LRUCachingHandler</flushRule> </linkLevelCachingPolicy> </cachingPolicy> </LODConfig> </networkLODConfig> </LODConfigs>
Example 5-9 and Example 5-10 show the Java and PL/SQL APIs, respectively, for reloading the load on demand configuration.
Example 5-9 Reloading the Load on Demand Configuration (Java API)
InputStream config = ClassLoader.getSystemResourceAsStream( "netlodcfg.xml"); LODNetworkManager.getConfigManager().loadConfig(config);
Example 5-10 Reloading the Load on Demand Configuration (PL/SQL API)
EXECUTE SDO_NET.LOAD_CONFIG('WORK_DIR', 'netlodcfg.xml');
Example 5-11 returns the estimated size in bytes for a specified network partition.
Example 5-11 Getting Estimated Partition Size
SELECT SDO_NET.GET_PARTITION_SIZE ( NETWORK->'NYC_NET', PARTITION_ID->1, LINK_LEVEL ->1, INCLUDE_USER_DATA->'FALSE', INCLUDE_SPATIAL_DATA->'TRUE') FROM DUAL;
Example 5-12 uses the load on demand Java API (oracle.spatial.network.lod) to issue a shortest-path query on a network.
Example 5-12 Network Analysis: Shortest Path (LOD Java API)
Connection conn = LODNetworkManager.getConnection(dbUrl, dbUser, dbPassword); // get LOD network IO Adapter String networkName = “NYC_NET”; NetworkIO reader = LODNetworkManager.getCachedNetworkIO(conn, networkName, networkName, null); // get analysis module NetworkAnalyst analyst = LODNetworkManager.getNetworkAnalyst(reader); // compute the shortest path LogicalSubPath path = analyst.shortestPathDijkstra(new PointOnNet(startNodeId), new PointOnNet(endNodeId), null); // print path result PrintUtility.print(System.out, path, false, 0, 0); . . .
Example 5-13 uses the XML API (oracle.spatial.network.xml) to issue a shortest-path query on a network. It includes the request and the response.
Example 5-13 Network Analysis: Shortest Path (XML API)
<?xml version="1.0" encoding="UTF-8"?> <ndm:networkAnalysisRequest xmlns:ndm="http://xmlns.oracle.com/spatial/network" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml"> <ndm:networkName>NYC_NET</ndm:networkName> <ndm:shortestPath> <ndm:startPoint> <ndm:nodeID>65</ndm:nodeID> </ndm:startPoint> <ndm:endPoint> <ndm:nodeID>115</ndm:nodeID> </ndm:endPoint> <ndm:subPathRequestParameter> <ndm:isFullPath> true </ndm:isFullPath> <ndm:startLinkIndex> true </ndm:startLinkIndex> <ndm:startPercentage> true </ndm:startPercentage> <ndm:endLinkIndex> true </ndm:endLinkIndex> <ndm:endPercentage> true </ndm:endPercentage> <ndm:geometry>false</ndm:geometry> <ndm:pathRequestParameter> <ndm:cost> true </ndm:cost> <ndm:isSimple> true </ndm:isSimple> <ndm:startNodeID>true</ndm:startNodeID> <ndm:endNodeID>true</ndm:endNodeID> <ndm:noOfLinks>true</ndm:noOfLinks> <ndm:linksRequestParameter> <ndm:onlyLinkID>true</ndm:onlyLinkID> </ndm:linksRequestParameter> <ndm:nodesRequestParameter> <ndm:onlyNodeID>true</ndm:onlyNodeID> </ndm:nodesRequestParameter> <ndm:geometry>true</ndm:geometry> </ndm:pathRequestParameter> </ndm:subPathRequestParameter> </ndm:shortestPath> </ndm:networkAnalysisRequest> <?xml version = '1.0' encoding = 'UTF-8'?> <ndm:networkAnalysisResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ndm="http://xmlns.oracle.com/spatial/network" xmlns:gml="http://www.opengis.net/gml"> <ndm:networkName>NYC_NET</ndm:networkName> <ndm:shortestPath> <ndm:subPathResponse> <ndm:isFullPath>true</ndm:isFullPath> <ndm:startLinkIndex>0</ndm:startLinkIndex> <ndm:startPercentage>0.0</ndm:startPercentage> <ndm:endLinkIndex>17</ndm:endLinkIndex> <ndm:endPercentage>1.0</ndm:endPercentage> <ndm:pathResponse> <ndm:cost>6173.212694405703</ndm:cost> <ndm:isSimple>true</ndm:isSimple> <ndm:startNodeID>65</ndm:startNodeID> <ndm:endNodeID>115</ndm:endNodeID> <ndm:noOfLinks>18</ndm:noOfLinks> <ndm:linkIDs>145477046 145477044 145477042 145477039 145476926 145476930 145480892 145480891 145476873 145476871 145477023 145489019 145489020 145476851 145488986 145488987 145476913 145476905 </ndm:linkIDs> <ndm:nodeIDs>65 64 60 57 58 61 71 70 73 87 97 95 91 101 102 104 117 120 115 </ndm:nodeIDs> <ndm:geometry> <gml:LineString> <gml:coordinates>-71.707462,43.555262 -71.707521,43.555601… </gml:coordinates> </gml:LineString> </ndm:geometry> </ndm:pathResponse> </ndm:subPathResponse> </ndm:shortestPath> </ndm:networkAnalysisResponse>
Additional examples of using load on demand analysis with partitioned networks are included in the demo files, described in Section 5.14.
This section presents an example of using network user-defined data, which is the information (not related to connectivity) that users want to associate with a network representation. The USER_SDO_NETWORK_USER_DATA and ALL_SDO_NETWORK_USER_DATA metadata views (described in Section 5.10.3) contain information about user-defined data.
Example 5-14 inserts link-related user-defined data into the network metadata.
Example 5-14 Inserting User-Defined Data into Network Metadata
-- Insert link user data named 'interaction' of -- type varchar2 (50) in network 'bi_test'. --'interaction' is a column of type varchar2(50) in the link table of network 'bi_test'. insert into user_sdo_network_user_data (network,table_type,data_name,data_type,data_length) values ('bi_test','LINK','interaction','VARCHAR2',50) ; -- insert link user data named 'PROB' of type Number. --'PROB' is a column of type NUMBER in the link table of network 'bi_test'. insert into user_sdo_network_user_data (network,table_type,data_name,data_type) values ('bi_test','LINK','PROB','NUMBER') ;
After a network or network partition is loaded, user-defined data is available in Java representations. You can access user-defined data through the getUserData
and setUserData
methods for the Node
, Link
, Path
, and SubPath
interfaces. For example:
String interaction = (String)link.getUserData(“interaction”); double prob = ((Double)link.getUserData(“Prob”)).doubleValue();
Oracle Spatial provides several network data model supplementary documentation files, as well as demo files that you can use to reinforce your learning and to create models for coding certain operations. Some of these files are for the Network Editor, an unsupported tool that enables you to visualize and edit network data. (The Network Editor interface is shown in Figure 5-1 in Section 5.1.) If you installed the demo files from the Oracle Database Examples media (see Oracle Database Examples Installation Guide), those related to the network data model are under the following directory:
The supplementary documentation files are installed under the $ORACLE_HOME/md/doc
directory.
If you installed the demo files from the Oracle Database Examples media, these files and additional code examples are installed under the $ORACLE_HOME/md/demo
directory.
Each directory and most of the subdirectories have a README.txt
file that explains the purpose of the files, and many files contain internal explanatory comments.
The $ORACLE_HOME/md/doc
directory contains supplementary documentation.The sdondmxml.zip
file in that directory contains XML Schema (.xsd) files and the default load on demand configuration XML file.
If you installed the demo files from the Oracle Database Examples media, the $ORACLE_HOME/md/demo/network
directory tree includes additional examples (network data, Java, PL/SQL, and SQL*Loader) , as well as files for setting up and using two graphical tools: a network editor and a load on demand analysis viewer. Both tools are provided as a convenience, and are not officially supported by Oracle.
The $ORACLE_HOME/md/demo/network/examples
directory tree contains the following kinds of examples: network data, Java, PL/SQL, and SQL*Loader.
The Network Editor enables you to visualize and edit network data. (The Network Editor interface is shown in Figure 5-1 in Section 5.1.) The files for the Network Editor are in the following directory:
$ORACLE_HOME/md/demo/network/editor
Read the README.txt
file in that directory for information about this tool. Sample data for the network data model is under the following directory:
$ORACLE_HOME/md/demo/network/examples/data
For example, Hillsborough (New Hampshire, United States) sample network data is in the following file:
$ORACLE_HOME/md/demo/network/examples/data/hillsborough_network.dmp
Read the README.txt
file in that directory for information about loading the Hillsborough sample network data into the database.
A viewer tool is provided to help you visualize the results of load on demand analysis. This viewer is a standalone Java application built on top of the load on demand Java API and Oracle MapViewer. It can perform most load on demand analysis functions and provides simple viewing capabilities.
The files for the load on demand analysis viewer tool Network Editor are in the following directory:
$ORACLE_HOME/md/demo/network/lodviewer
To use the viewer tool, first enter database connection information for the database where the network data model (including partition information) is stored. Next, enter MapViewer connection information. For information on how to install and use MapViewer, see the MapViewer User's Guide.
After the connections are validated, you can perform analysis operations on the selected network. Zoom-in, zoom-out, and zoom-window functions are available for viewing analysis results. A text window prints out analysis results and statistics.
Figure 5-8 shows a shortest-path analysis result in the load on demand analysis viewer.
Figure 5-8 Load on Demand Analysis Viewer Tool
A README.txt
file supplements the information in the following manuals: Oracle Spatial Developer's Guide, Oracle Spatial GeoRaster Developer's Guide, and Oracle Spatial Topology and Network Data Models Developer's Guide (this manual). This file is located at:
$ORACLE_HOME/md/doc/README.txt