BookmarkSubscribeRSS Feed
Jeff293
Calcite | Level 5
I'd like to lay one map over another map using GMAP. I have SAS 9.2. Any suggestions on coding? thanks.
6 REPLIES 6
GraphGuy
Meteorite | Level 14
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. 🙂
Jeff293
Calcite | Level 5
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
GraphGuy
Meteorite | Level 14
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;

-----
GraphGuy
Meteorite | Level 14
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).
Jeff293
Calcite | Level 5
This coding works fine. Any sugguestions on how the program can loop 40 times for all the Senate districts? thanks. Jeff
GraphGuy
Meteorite | Level 14
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 2735 views
  • 0 likes
  • 2 in conversation