IsoDistance

Description

An isodistance is a polygon representing specific distance intervals from a particular point extended out along all possible paths. The IsoDistance function returns an isodistance connecting a set of points that lie at a specified distance from the given starting point, considering every possible route.

The IsoDistance UDF uses the GetTravelBoundary operation of the Global Routing API to generate the isodistance. The GetTravelBoundary operations helps determine the drive or walk time or the distance boundary from a given location. This function generates polygons corresponding to an isodistance calculation. For more information, see the Global Routing SDK User Guide, which is also available on the Spectrum Spatial for Big Data documentation landing page.

Note: The function may time out when using a large number of datasets that are stored in remote locations (such as HDFS and S3). If you are using Hive with the MapReduce engine, you can adjust the value of the mapreduce.task.timeout property.

Function Registration

create function IsoDistance as 'com.pb.bigdata.spatial.routing.hive.IsoDistance';

Syntax

IsoDistance(WriteableGeometry startPoint, Number|String cost, 
            Map<String, String> options, Map<String, String> propagationFactorOptions)
IsoDistance(WriteableGeometry startPoint, Array<Number|String> costs, 
            Map<String, String> options, Map<String, String> propagationFactorOptions)

Parameters

Parameter Type Description
startPoint WriteableGeometry the location from which travel starts. This must be a point for those UDFs that require it.
cost Number or String contains a single value for the maximum travel distance (default unit is meter)
costs Array contains multiple values for the maximum travel distance (default unit is meter) . When this parameter is provided, the UDF will return an array of responses, one for each cost, in the same order as the costs parameter.
options Map options that affect the generation of the isodistance and engine options that affect the operation of the routing engine
propagationFactorOptions Map propagation factor options that affect the distance traveled when going off a network road

Syntax

IsoDistance(Number|String startX, Number|String startY, Number|String cost, 
            Map<String, String> options, Map<String, String> propagationFactorOptions)
IsoDistance(Number|String startX, Number|String startY, Array<Number|String> costs, 
            Map<String, String> options, Map<String, String> propagationFactorOptions)

Parameters

Parameter Type Description
startX Number or String x ordinate of the location from which travel starts in WGS 84
startY Number or String y ordinate of the location from which travel starts in WGS 84
cost Number or String contains a single value for the maximum travel distance (default unit is meter)
costs Array contains multiple values for the maximum travel distance (default unit is meter) . When this parameter is provided, the UDF will return an array of responses, one for each cost, in the same order as the costs parameter.
options Map options that affect the generation of the isodistance and engine options that affect the operation of the routing engine
propagationFactorOptions Map propagation factor options that affect the distance traveled when going off a network road

Options

The options and propagationFactorOptions keys cannot be derived from a column in the table that the UDF is executed on. The keys of the options and propagationFactorOptions maps must also be of type String or convertible to String, and the values should be convertible to a type appropriate for the key’s value (typically this means that all values must be of type String). Keys and values of any type can be enclosed in either double or single quotes; a number or Boolean value will be processed correctly with or without quotes. For information on options that affect the calculation of the route, see Engine Options.

Key Type Description
pb.routing.bandingStyle BandingStyle The style of banding to be used in the result. Banding styles are the types of multiple distance bands that can be displayed based on multiple costs. The available values are:
Donut
Each boundary is determined by subtracting out the next smallest boundary.
Encompassing
Each boundary is determined independent of all others.This is the default method.
pb.routing.historicSpeedBucket HistoricSpeedBucket Specifies whether the routing calculation uses the historic traffic speeds. These speeds are based on different time-of-day buckets. The data must have historic traffic speeds included in order to use this feature. The data for each country/region has the same bucket definitions, where the speeds for these bucket values may vary. The available values are:
None
The default value. Historic traffic data is not used in the calculation. Instead an averaged speed value is used.
AMPeak
Calculate routes with the peak AM speeds. The AMPeak time bucket is from 07:00 to 10:00.
PMPeak
Calculate routes with the peak PM speeds. The PMPeak time bucket is from 16:00 to 19:00.
OffPeak
Calculate routes with the off peak (daytime) speeds. The OffPeak time bucket is from 10:00 to 16:00.
Night
Calculate routes with the nighttime speeds. The Night time bucket is from 22:00 to 04:00.
pb.routing.majorRoads Boolean Whether to include all roads in the calculation or just major roads. If you choose to include only major roads (that is, set the value to true), performance will improve but accuracy may decrease. The default value is false.
pb.routing.returnHoles Boolean Specifies whether you want to return holes, which are areas within the larger boundary that cannot be reached within the desired time or distance, based on the road network. The default value is false.
pb.routing.returnIslands Boolean Specifies whether you want to return islands, which are small areas outside the main boundary that can be reached within the desired time or distance. The default value is false.
pb.routing.simplificationFactor Number What percentage of the original points should be returned or upon which the resulting complexity of geometries should be based. A number between 0.0 and 1.0 is accepted, exclusive of 0.0 but inclusive of 1.0. Complexity increases as the value increases, therefore 1.0 means the most complex. The default value is 0.5.
pb.routing.maxOffroadDistance Number The maximum distance to allow travel off the road network using the pb.routing.maxOffroadDistanceUnit. Examples of off-network roads include driveways and access roads. For example, if you specify a maximum off road distance of 1 mile the travel boundary will extend no further than one mile from the network road. If you specify a value of 0 the travel boundary will not extend beyond the road itself. Use the ambient speed options to specify the speed of travel along non-network roads.
pb.routing.maxOffroadDistanceUnit String The distance unit defining the pb.routing.maxOffroadDistance. You must also define pb.routing.maxOffroadDistance if you define this key. Available linear units are:
  • in
  • inch
  • ft
  • foot
  • yd
  • yard
  • mi
  • mile
  • mm
  • millimeter
  • cm
  • centimeter
  • m
  • meter
  • km
  • kilometer
pb.routing.distanceUnit String The unit to return distance. If not specified then this value is meter. Available linear units are:
  • in
  • inch
  • ft
  • foot
  • yd
  • yard
  • mi
  • mile
  • mm
  • millimeter
  • cm
  • centimeter
  • m
  • meter
  • km
  • kilometer
pb.routing.error.limit Number The number of routing errors to allow before failing a task for "too many errors". This prevents a task (and thus the job) from continuing in the case of a likely configuration error. The default value is 10.

Optionally you can use the equivalent Hive variable, pb.routing.error.limit.

pb.routing.error.limit.disabled Boolean Disables the error limit. All errors will be logged but will not cause the task or job to fail.

Optionally you can use the equivalent Hive variable, pb.routing.error.limit.disabled.

pb.routing.propagationFactor Number The distance ratio to travel when going off a network road to find the travel boundary (for all road types). To control how off-network travel is used in the distance travel boundary calculation, you need to specify the propagation ratio. The propagation factor can affect the size and shape of the travel boundary polygon. In general, the higher the propagation factor the larger the polygon. For example, if there is 10 miles left to travel and the propagation factor was 0.15, then boundary points would be put at a distance of 1.5 miles.The default value is 0.16.

Propagation Factor Override Road Type Options

This option lets you adjust the distance traveled when going off-network.

Key Type Description
RoadType Number Specifies the propagation factor to use for off-network travel based on the road type. You must specify both the road type and the new propagation factor for that road type. The propagation factor is defined in the options. For a list of road type enumerations, see RoadType Enumeration.

Return Values

This function returns struct values described in the table below. In the case where a single cost is input, a single struct is returned. In the case where an array of multiple cost values are input, then an array of structs are returned.

Return Field Description
Geometry Returns the WritableGeometry of an isodistance.
Error Any error that occurs; if none, then null.
Note: For values of distance linear units, see the Global Routing SDK User Guide, which is also available on the Spectrum Spatial for Big Data documentation landing page.

Examples

This query returns a polygon geometry comprising all the points that lie at the specified distance of 3 kilometers from the starting point. Because the return is in the form of a struct, you need to access the geometry field. You can use the WritableGeometry returned by the IsoDistance UDF with the Spatial UDFs for further processing, as shown in the example given below:
SELECT ToWKT(IsoDistance(ST_Point(-77.088217, 38.937072), 1, map('pb.routing.distanceUnit', 'km')).geometry);
The Routing Hive UDFs are also interoperable with the Spatial and Geocoding Hive UDFs. To avoid returning a geometry from the top of the query which can be problematic, the geometry is wrapped in a call to ToWKT in order to get a text representation:
SELECT ToWKT(IsoDistance(Geocode('485A Watervliet Shaker Rd, Latham, NY 12110','usa').geometry, 500).geometry);
Note: See the Spectrum Geocoding for Big Data User Guide and Spectrum Location Intelligence for Big Data User Guide on the Spectrum Spatial for Big Data documentation landing page for more information on how to use the Geocoding and Spatial UDFs.

Sometimes calculating a route takes longer than expected and times out. You can adjust this using the engine options:

SELECT ToWKT(IsoDistance(x, y, cost, map(pb.routing.engine.timeout, 300)).geometry) FROM <table_name>;

The previous example had the time-out specified as an number. It can also be specified as a string:

SELECT ToWKT(IsoDistance(x, y, cost, map(pb.routing.engine.timeout, '300')).geometry) FROM <table_name>; 

Hive requires that all values in a MAP must be of the same type:

SELECT ToWKT(IsoDistance(x, y, cost, map(pb.routing.engine.timeout, '300', 'pb.routing.allowFallback', 'false')).geometry) FROM <table_name>;

Example showing multiple costs specified in an array for an input point. Hive requires that all values in an array must be of the same type:

SELECT costs[costidx] cost, ToWKT(iso.geometry) wkt, iso.error 
FROM points
LATERAL VIEW explode(array(array(5,10,20))) c as costs
LATERAL VIEW OUTER posexplode(IsoDistance(points.longitude,points.latitude,costs)) isoresult as costidx, iso;

Example showing propagationFactorOptions set:

SELECT ToWKT(IsoDistance(ST_Point(-77.088217, 38.937072), 3, null, map('footpath', '0.45')).geometry);

Example with both options and propagationFactorOptions set:

SELECT ToWKT(IsoDistance(ST_Point(-77.088217, 38.937072), 3, map('pb.routing.timeUnit', 'minute'), map('footpath', '0.45')).geometry);