- In-line Expressions — calculating weights using inline expressions and forcing the graph server to divide complex WKT LINESTRINGs during the graph creation
- Expansion — using iteration to divide complex WKT LINESTRINGs and, using a subquery, calculate weights prior to the graph creation
Prerequisites
- D.C. Shape data file
- Access to GAdmin
Data File
The tutorial makes use of thedc_shape dataset, which can be ingested from
the data file mentioned above.
To ingest the file using GAdmin:
- Navigate to GAdmin and log in (
http://localhost:8080/) - In the top menu, click Data —> Import
- In the top right corner, click Advanced CSV Import
- Click Select File and select the data file from your local directory
- Leave the default options and values for the rest of Step 1
- Under Step 2, change Schema to
graph - Under Step 3: Confirm, click Import CSV
Fit Using Inline Expressions
Fitting road network data to a graph using inline expressions offers a simpler
but less efficient approach to deriving the individual edge segments’ weight.
The
dc_shape_inline graph that will be created will calculate weight as
distance inline and is based on the aforementioned dc_shape dataset.
Create Schema
Before starting with graph creation, a schema,graph_c_fit_data, will
be created to contain the tables supporting graph creation & solving. To create
the schema:
- Still in GAdmin, on the top menu, click Query —> SQL to go to the SQL Tool page.
- Copy the following CREATE SCHEMA statement into the
SQL Statements text area on the top section of the page:
- Highlight the statement and click Run Selected.
Create Graph
To create the graph, in GAdmin:- Copy the following CREATE GRAPH statement into the
SQL Statements text area on the top section of the page:
- Highlight the statement and click Run Selected.
dc_shape_inline graph with the following characteristics:
- It is DIRECTED because the roads in the graph have directionality (one-way and two-way roads).
- It has no explicitly defined nodes, because the example relies on implicit nodes attached to the defined edges.
-
The EDGES are derived from WKT LINESTRINGs in the
shapecolumn of thedc_shapetable (AS WKTLINE); the graph server will automatically divide each complex LINESTRING into simple edges. Each edge’s directionality is derived from thedirectioncolumn of thedc_shapetable (AS DIRECTION), and each edge will be assigned an ID that is thelink_idcolumn of thedc_shapetable (AS ID). -
The edge weights are represented as distance, which is calculated as the length of the entire
shapecolumn’s LINESTRING (in meters) divided by the number of points in the LINESTRING minus 1 (AS WEIGHT_VALUESPECIFIED). - It has no inherent restrictions for any of the nodes or edges in the graph.
-
It utilizes the following
OPTIONS:- It will be replaced with this instance of the graph if a graph of the same
name exists (
recreate). - If nodes are within 0.00001 degrees (1 meter) of each other, they are
merged together (
merge_tolerance). - The resulting graph’s information is placed into a table
(
graph_table) and anEDGE_WKTLINEcolumn is included so the graph can be visualized.
- It will be replaced with this instance of the graph if a graph of the same
name exists (
- On the top menu, click Data —> Graphs to go to the Graphs page.
- Click on the dc_shape_inline entry in the list of graphs.
- Click Visualize to bring up the map view.
Fit Using Expansion
Fitting road network data to a graph using expansion separates the creation of line segments and calculation of distance from graph creation. This increases the performance of the graph creation process, as most of the calculations are done within the database instead of the graph server. Expansion is achieved through iteration, wherein each source record with a WKT is expanded into a number of records equal to the number of edges in that corresponding WKT. For example, a single road record with a 10-segment WKT LINESTRING will become ten individual records, each containing one of the 10 segments. In this way, the weights can be pre-calculated and assigned directly to the road segments/edges, alleviating the need for the graph server to do this processing itself.Create Expansion Table
To accomplish this, first create the expansion table, in GAdmin:- On the top menu, click Query —> SQL to go to the SQL Tool page.
- Copy the following CREATE TABLE statement into the
SQL Statements text area on the top section of the page:
- Highlight the statement and click Run Selected.
- The existing
dc_shapetable is joined to theITERvirtual table, where each WKT LINESTRING is iterated through to extract line segments. - A new WKT LINESTRING is constructed (
ST_MAKELINE) from each consecutive pair of points in the source LINESTRING (dc_shape.shape) column. - The
directionandlink_idcolumns are extracted from thedc_shapetable to assist in graph creation later.
nullable
property), and also to calculate the weight as distance. Lastly, the result
is saved to a table, which the graph creation will use as input.
- The results of the query are placed in a new table
(
graph_c_fit_data.dc_shape_expanded). - The
link_idanddirectioncolumns are passed through as they are. - The
shapecolumn has its nullability removed (REMOVE_NULLABLE). - The
shapecolumn is used to calculate a distance column (distance), and nullability is removed from that column as well.
Create Graph from Expansion Table
Finally, thedc_shape_expansion graph is created directly from the
dc_shape_expanded table with no extra calculations necessary. The graph
is created with the same characteristics as before, with the following changes:
- The edges are derived from the line segments expanded from the original WKT
LINESTRINGs in the
shapecolumn of thedc_shape_expandedtable (WKTLINE). - The weights are pulled directly from the
distancecolumn of thedc_shape_expandedtable (WEIGHT_VALUESPECIFIED), pre-calculated above.
- Copy the following CREATE GRAPH statement into the
SQL Statements text area on the top section of the page:
- Highlight the statement and click Run Selected.
- On the top menu, click Data —> Graphs to go to the Graphs page.
- Click on the dc_shape_expansion entry in the list of graphs.
- Click Visualize to bring up the map view.