Click or drag to resize

IMPORT CONSTRAINTS Example

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release
Overview

We will import turn restrictions that apply on certain days of every week using the IMPORT CONSTRAINTS statement.

Data

The data we will use in this example is split across three shapefiles. Even though the restrictions do not contain any graphics objects, shapefiles are still a convenient and flexible method of storing data.

Supporting Data Files

The first shapefile (rdms) is used to generate a sequenced array describing the navigational path that the restriction relates to.

A section of the rdms shapefile table used in this example is shown below:

sfif-import-restrictions-rdms

The Cond_id column refers to a unique identifier for each restriction. The Link_id column refers to the originating link, and the Man_linkid column refers to the terminating link (that is, the restriction is on a turn from the originating link to the terminating link). A restriction may be a sequence of restricted turns. The Seq_number column (in conjunction with the Link_id column) is used to build the sequence of a restriction. A sequence number of one refers to the first turn in the sequence, a sequence number of two refers to the second turn and so on.

We will create a lookup table named restrictionList. Each item in the restrictionList lookup is an array. The first element of each array is always -1, the second element will be the link ID of the second link in the restriction, the third will be the link ID of the third link in the restriction and so on. The value of the first element (-1) is a placeholder; during the IMPORT CONSTRAINTS statement it will be populated with the first link ID for the restriction.

Example: Consider the illustration below. To restrict the movement C-B-A we would use the array [-1, B, A]. Similarly, to restrict the movement A-B-C we would use the array [-1, B, C].

Thus, to restrict the entire traversal of link B we would need two entries in the restrictionList lookup: [-1, B, A] and [-1, B, C]. This would prevent a turn into link B from either link A or link C, effectively preventing the driver from entering link C.

sfif-import-restrictions

The Alchemy code to create the lookup is as follows:

Alchemy
CREATE LOOKUP restrictionList
  ON array.set_at(coalesce(lookup("restrictionList", %cond_id), 
    array.new(-1)), %seq_number, %man_linkid)
  FROM "data\rdms"
  INDEX BY %cond_id;
Note Note

Note the use of the COALESCE statement to add the restriction at the appropriate index in an existing sequence, or at the appropriate index in a new sequence.

After the lookup has been created, a restriction will be referenced by a unique condition ID (contained in the 'cond_id' column of the 'rdms' table).

The second shapefile, 'cdmsdtmod' will be used to generate the DateTimeType hash used to describe the time(s) that this restriction applies. A section of the 'cdmsdtmod' shapefile table used in this example is shown below:

sfif-import-restrictions-cdmsdtmod

The code to generate a DateTimeType hash for each condition ID is shown below. Note that we are only importing those restrictions that are specified as a DayMask.

Alchemy
CREATE LOOKUP timeRestrictions
ON array.set_at(
    coalesce(lookup("timeRestrictions", %cond_id), array.new(-1)),
    coalesce(length(lookup("timeRestrictions", %cond_id)), 0),
{
  type : 'DayMask',
  date1 = %ref_date,
  startTime : %starttime,
  endTime : %endtime,
}
FROM "data\cdmsDtmod" WHERE %dttme_type = 1;
Note Note

The first COALESCE statement returns either an existing array for the given condition ID (to which the time restriction will be appended) or a new array.

The second COALESCE statement appends the time restriction to the array, or sets the time restriction to 0 (does not apply) if no time restriction exists for the given condition ID.

Using the IMPORT CONSTRAINTS Statement

The third shapefile 'cdms' (a section of which is shown below) is used to determine which vehicle types the restriction applies to. We will allow pedestrians and emergency vehicles at all times, but restrict automobile traffic as described by the 'Ar_auto' column.

sfif-import-restrictions-cdms

The IMPORT CONSTRAINTS code is shown below.

Alchemy
IMPORT CONSTRAINTS [
  IDS = array.set_at(coalesce(lookup("restrictionList",%cond_id), array.new(%link_id)), 0, %link_id),
  SPEED = 0,
  CAR = %ar_auto,
  EMERGENCY = false,
  PEDESTRIAN = false,
  DATESPEC = coalesce(lookup("timeRestrictions", %cond_id), 0),
  DIRTRAVEL = "B"
]
FROM "data\cdms";
Note Note

Note the use of the COALESCE statement to conditionally set the IDS and DATESPEC columns to the appropriate restriction, or an appropriate default value.

Summary

This is a conceptual, yet functional, example and in no way describes a definitive method for importing turn restrictions. However it serves to illustrate the following important concepts:

  • Restrictions often apply to a sequence of links and it is often necessary to use a supporting LOOKUP in conjunction with the IMPORT CONSTRAINTS statement.
  • Data is often split across multiple files. In this example we used the unique condition ID (cond_id column) as a key to link the data sets (using LOOKUP statements).