Data visualization with SAS programming

Drawing lines between 2 points on a map with GMAP?

Reply
Contributor
Posts: 23

Drawing lines between 2 points on a map with GMAP?

Hi all,

I'm trying to figure out how to draw several lines between different pairs of points on a map, using PROC GMAP or some other mapping procedure. I've already done the prep work using PROC GPROJECT to get my annotation dataset projected in line with my source map dataset, and I can display my map and points with:

proc gmap data=States map=Map0 ;

id state;

choro state / annotate=Loc1 discrete nolegend;

run; quit;

In that code,

States comes from maps.states(where=(state not in(2 15 72))), it's basically the continental US.

Map0 comes from States, and then is processed similar to the dataset "Map" in this example: SAS Maps Online

Loc1 is my dataset of various coordinates I've plotted, and was processed similar to the dataset "Cities" in that same example. It has 30 records of coordinates, with a variable LocID numbered 1 through 30, which is how we identify them internally.

So far so good, and all the points in Loc1 come out exactly where they should be. Now, I'd like to be able to draw lines between the point with LocID=1 and LocID=2, or LocID=5 and LocID=7, or LocID=9 and LocID=22, and so on.

I haven't been able to figure out how to do this, either through PROC GMAP or some other mapping procedure. Does anyone have any suggestions for me to try or examples I could follow?

Thanks!

SAS Employee
Posts: 980

Re: Drawing lines between 2 points on a map with GMAP?

You can use an 'annotate' data set to place markers on the map (annotated function='pie') and connect them using annotated lines (function='move' and 'draw').

Here is the simplest example I have...

UPS Tracking Map (SAS/Graph gmap)

http://robslink.com/SAS/democd41/ups_tracking_map_info.htm

Contributor
Posts: 23

Re: Drawing lines between 2 points on a map with GMAP?

That's great, thanks so much! I was able to follow that example and get it to work:

gmap5.png

Now, the next thing I need to figure out is if there's a way to calculate the distances of those line segments. That would probably take some data manipulation and using the GEODIST function, right? Or is there a way to do it within PROC GMAP or one of the other mapping procedures?

Thanks again!

SAS Employee
Posts: 980

Re: Drawing lines between 2 points on a map with GMAP?

You can use Geodist, but you'll need to make the calculations on the lat/long values *before* you project them.

Contributor
Posts: 23

Re: Drawing lines between 2 points on a map with GMAP?

One other thing... is there a way to offset multiple lines that collect the same 2 points? For example, if these represent travel between 2 cities, and someone travels between the same two cities more than once, can there be multiple lines next to each other but slightly offset?

SAS Employee
Posts: 980

Re: Drawing lines between 2 points on a map with GMAP?

There is a way to offset text, using the annotate 'position' (position='5', position='2', etc), but there is not a built-in way to apply offsets to the drawn graphics (such as pie markers and lines/arrows).  You will have to programmatically manipulate the x/y coordinates in your data to do that.  (I think this will not be easy.)

Super User
Posts: 11,134

Re: Drawing lines between 2 points on a map with GMAP?

Unless the number of trips is large, you might be able to summarize your data and get counts of duplicate trips. Then factor the number into a line width parameter.

Contributor
Posts: 23

Re: Drawing lines between 2 points on a map with GMAP?

Thanks to both of you for your responses. What you wrote makes sense, and is along the lines of what I was thinking... it's good to get confirmation on it, definitely.

SAS Employee
Posts: 980

Re: Drawing lines between 2 points on a map with GMAP?

Another option, besides the width or color of the line, would be to use alpha-transparent colors (if you have SAS 9.3 or higher).  With the alpha-transparent colors, the more lines you overlay in the same location, the more color they will get.

An example of a red alpha-transparent color would be ...  Aff000077

Ask a Question
Discussion stats
  • 8 replies
  • 3184 views
  • 0 likes
  • 3 in conversation