pgRouting doesn't deal well with nondefault schemas, so before we begin, we will set the schema in our user preferences using the following command:
ALTER ROLE me SET search_path TO chp06,public;
Next, we need to add the pgrouting extension to our database. If PostGIS is not already installed on the database, we'll need to add it as an extension as well:
CREATE EXTENSION postgis; CREATE EXTENSION pgrouting;
We will start by loading a test dataset. You can get some really basic sample data from http://docs.pgrouting.org/latest/en/sampledata.html.
This sample data consists of a small grid of streets in which any functions can be run.
Then, run the create table and data insert scripts available at the dataset website. You should make adjustments to preserve the schema structure for chp06—for example:
CREATE TABLE chp06.edge_table (
id BIGSERIAL,
dir character varying,
source BIGINT,
target BIGINT,
cost FLOAT,
reverse_cost FLOAT,
capacity BIGINT,
reverse_capacity BIGINT,
category_id INTEGER,
reverse_category_id INTEGER,
x1 FLOAT,
y1 FLOAT,
x2 FLOAT,
y2 FLOAT,
the_geom geometry
);
Now that the data is loaded, let's build topology on the table (if you haven't already done this during the data-load process):
SELECT pgr_createTopology('chp06.edge_table',0.001);
Building a topology creates a new node table—chp06.edge_table_vertices_pgr—for us to view. This table will aid us in developing queries.