Subscribe Bookmark RSS Feed

How do I create a 2D Map with lines from geo-point 1 to geo-point 2?

seanschubert

Community Trekker

Joined:

Jun 23, 2011

I'd like to create a map of the US with lines connecting some of the cities. This is for a Supply Chain application so ideally the width of the lines would be proportional to sales shipped between each of those sets of points. Once I have the lines in place, I can add the US as a background map. Which graph function should I use?

3 REPLIES
ballardw

Community Trekker

Joined:

Jun 23, 2011

There is one example here: http://support.sas.com/kb/24/897.html

Calculate the line thickness (size) using your sales data.

seanschubert

Community Trekker

Joined:

Jun 23, 2011

Are there any ways to do it in JMP? I don't have access to SAS.

ms

Super User

Joined:

Jun 23, 2011

The Line() function draws a line within e.g. a graph and can be part of a graphics script. To add many lines iteratively it's safest to work with a string representation of the graphics script and parse it in each iteration. The JSL example below may give you some ideas.

// Example table with sales between four cities and their coordinates.

dt = New Table( "LinesBetweenCities.jmp",

  Add Rows( 10 ),

  New Column( "City",

  Character,

  Set Values(

  {"Cleveland, Ohio", "Cleveland, Ohio", "Cleveland, Ohio", "Cleveland, Ohio", "Des Moines, Iowa", "Des Moines, Iowa", "Des Moines, Iowa",

  "Los Angeles, Calif.", "Los Angeles, Calif.", "Montgomery, Ala."}

  )

  ),

  New Column( "N", Numeric, Format( "Best", 12 ), Set Values( [41.467, 41.467, 41.467, 41.467, 41.583, 41.583, 41.583, 34.05, 34.05, 32.35] ) ),

  New Column( "W",

  Numeric,

  Format( "Best", 12 ),

  Set Values( [-81.617, -81.617, -81.617, -81.617, -93.617, -93.617, -93.617, -118.25, -118.25, -86.3] )

  ),

  New Column( "Sales", Numeric, Continuous, Format( "Best", 12 ), Formula( Round( Random Uniform(), 2 ) ) ),

  New Column( "With",

  Character,

  Nominal,

  Set Values(

  {"Cleveland, Ohio", "Des Moines, Iowa", "Los Angeles, Calif.", "Montgomery, Ala.", "Des Moines, Iowa", "Los Angeles, Calif.",

  "Montgomery, Ala.", "Los Angeles, Calif.", "Montgomery, Ala.", "Montgomery, Ala."}

  )

  ),

  Set Row States( [8, 0, 0, 0, 8, 0, 0, 8, 0, 8] ),

  Set Label Columns( :City )

);

gb = Graph Builder(

  Variables( X( :W ), Y( :N ) ),

  Elements( Points( X, Y, Legend( 1 ) ) ),

  SendToReport(

  Dispatch(

  {},

  "Graph Builder",

  FrameBox,

  {Background Map( Boundaries( "US States" ) ), Marker Size( 6 ), Grid Line Order( 2 ), Reference Line Order( 3 ),

  DispatchSeg(

  ShapeSeg( 1 ),

  {Line Color( {204, 204, 204} ), Fill Color( "None" ), Missing shape fill( 2147483647 ), Missing value fill( -14540253 )}

  )}

  )

  )

);

fb = Report( gb )[FrameBox( 1 )];

// String representation of script that draws a line

line_string =

"fb << add graphics script( 3, Pen Color( {.3, .5, .7} );

  Pen Size( ^round( 10 * :Sales, 0)^);

  Line( {^:W^, ^:N^}, {^:W[coord]^, ^:N[coord]^})

  )";

// Add graphics scripts that draw lines between each pair of cities. Pen Size depends on Sales.

For( i = 1, i <= N Row( dt ), i++,

  coord = (dt << getrows where( :with[i] == :City ))[1]; //get coordinates of the city in the With column

  Eval( Parse( Eval Insert( line_string ) ) ); // evaluate the variables within line_str and parse the text into working jsl

);