Data visualization with SAS programming

overlaying maps with GMAP?

Reply
Occasional Contributor
Posts: 10

overlaying maps with GMAP?

I'd like to lay one map over another map using GMAP. I have SAS 9.2. Any suggestions on coding? thanks.
SAS Employee
Posts: 963

Re: overlaying maps with GMAP?

You can use "proc greplay" to overlay one map onto another.

Or, you can build an "annotate" substitute for the 2nd map, and annotate/overlay that onto the first map (for example using gremove on a county map to get the coordinates of just the state outline, and then using annotate move/draw to draw the state outline polygons).

Both of these answers are a bit tricky & involved. If you could post up some more details on what you're wanting to do, I might can point you towards a helpful example. :-)
Occasional Contributor
Posts: 10

Re: overlaying maps with GMAP?

Hello. Here are the details:
My first map is the outline, meaning no county borders displayed, of the state of Virginia. I have the mapping data for the state.
The map I want to overlay is a single state Senate district. The district is just displayed as a solid. No legends are used for the maps. I have the mapping data for the districts and been using GMAP for choro maps for a related task.
The only other technical piece of this is that I will want to locate the combined maps in the upper right quadrant of the page (portrait).
Eventually I will want to do this process 40 times to produce combined maps reflecting the 40 Senate districts in the state.
Eventually I will be putting the combined maps into WORD. I use GMAP with a filename for the ouput and use device=CGMOFMP. thanks. Jeff
SAS Employee
Posts: 963

Re: overlaying maps with GMAP?

Thanks for the details - that helps/simplifies matters!

Since this map has fairly simple areas (just 1 state, and 1 region within that state), I recommend actually "combining" these 2 map areas together into 1 map (rather than trying to overlay or annotate one on top of the other).

Here is some sample code to demonstrate the technique - since I don't have any Senate district maps, I'm just using a county map to show the technique. Note that both the state map and the Senate district map must have their X/Y coordinates as long/lat values in unprojected radians (ie, consistent coordinate systems).

-----

/* Get 1 state outline area */
data state; set maps.states (where=(state=stfips('NC')));
fake_id=1;
run;

/* get 1 county (or senate district, etc) */
data district; set maps.counties (where=(state=stfips('NC') and county=183));
fake_id=2;
run;

data combined; set state district; run;

proc gproject data=combined out=projected;
id fake_id;
run;

pattern1 v=solid c=tan;
pattern2 v=solid c=red;

title "Area 'foo' in North Carolina";
proc gmap map=projected data=projected;
id fake_id;
choro fake_id / discrete coutline=gray44 nolegend;
run;

-----
SAS Employee
Posts: 963

Re: overlaying maps with GMAP?

Note that the above "trick" works, because traditional SAS/Graph "proc gmap" allows you to have overlapping map areas (ie, the map does not have to be "topologically correct" with all areas having common/shared borders and no overlapping areas).

This is an advantage, imho, of using gmap (which is just a simple polygon-drawing tool), versus full-fledged GIS system (which would tend to require topologically correct maps, to be able to do GIS-ey things).
Occasional Contributor
Posts: 10

Re: overlaying maps with GMAP?

This coding works fine. Any sugguestions on how the program can loop 40 times for all the Senate districts? thanks. Jeff
SAS Employee
Posts: 963

Re: overlaying maps with GMAP?

You could write a little macro that takes 1 parameter (the Senate district), and subsets the data, and draws the map.

Then you could call/run the macro 40 times, each time passing a different senate district (this one's brute force, requiring 40 lines of code ... but is very easy). Since your data isn't changing, this brute force technique isn't too bad.

... or create a data set containing the 40 senate districts, and use a "data step" to loop through all of them, calling the macro & passing a different district to it each time. The coding for this is a little tricky, but if your data was changing (ie, doing different states, with different senate districts, etc) then it would be good to have this programmatically data driven technique, rather than having to hard-code the macro calls each time.
Post a Question
Discussion Stats
  • 6 replies
  • 978 views
  • 0 likes
  • 2 in conversation