Data visualization with SAS programming

Add Buffer Around Boundaries in Map

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Add Buffer Around Boundaries in Map

I want to add an inward buffer zone around boundaries in my map.

 

I have a US states shapefile, reading it in with proc gmap.  I get an output dataset with X,Y that represent the lats/longs of the boundaries.  I would like to "shrink" the boundaries of each state by 0.5 miles for analysis.  IE the outline of NC is now 0.5miles inward of what it used to be, the outline of TN is also 0.5miles inward of what it used to be.  The state boundaries would no longer be contiguous.

 

In GIS software such as ArcGIS, this functionality is called the Buffer tool - I'd like to replicate this in SAS:

http://pro.arcgis.com/en/pro-app/tool-reference/analysis/how-buffer-analysis-works.htm


Accepted Solutions
Solution
‎12-22-2016 04:19 PM
SAS Employee
Posts: 170

Re: Add Buffer Around Boundaries in Map

Most of the work is done with the data itself.

I do not know how you shrink a state by a half mile all the way around.  You would have to know the direction to shrink it and such.

Just a suggestion, but how about a different option?  Put a half mile circle around each point.  Then treat each point in the circle as a point for GINSIDE.  If any point in the circle is outside of state, then the origional point is within a half mile from an edge.  It might take a while to run and you have a little coding to do.  For example:

 

example2.png

 

There is an example making circles per mile at:

http://support.sas.com/rnd/papers/#SGF2009

Then look for:  Tips and Tricks IV: More SAS/GRAPH Map Secrets

Under that is a link to the paper and the examples.  In the paper, it is the example on page 7.

In the examples, it is SASU2.sas.  The program 'circle' currently does annotate data, but you can modify it to do map data.

 

 

View solution in original post


All Replies
Grand Advisor
Posts: 9,748

Re: Add Buffer Around Boundaries in Map

I suspect you mean that you used Proc Mapimport not GMap. The results are not actually Lat/long but X Y cartesian coordinates.

What do mean "for analysis"? Do you want to exclude locations within 0.5 miles of the border? What type of analysis? What size are you displaying this at? 0.5 miles is going to be very little difference if displaying the entire US.

 

And are you using SAS/GIS or the basic mapping procedures?

 

Occasional Contributor
Posts: 5

Re: Add Buffer Around Boundaries in Map

[ Edited ]

Thank you for the reply!  You are correct - I am using PROC MAPIMPORT to read in shapefiles of the states into SAS.

 

I have a series of addresses (lats/longs) where I am using PROG GINSIDE to place them into states.  However, if the address is within 0.5mi of a state boundary, I don't want it to be assigned a state.

 

For example, I have an address at (43.0001,-91.0001) and I need to figure out what state boundaries it is within.  But if this address lat/long is within 0.5mi of a state boundary, I don't want it assigned to a state.  

 

So I need to "clip" the boundaries inwards of the states by 0.5mi, and output a dataset of the boundaries where the boundaries are shrunk by 0.5mi

 

I think I am using the basic procedures... I have SAS9.4 Enterprise Guide.

Grand Advisor
Posts: 9,748

Re: Add Buffer Around Boundaries in Map

If you have the border data in terms of lat and long then you may want to look at the GEODIST function as that will return distance between to coordinates in Kilometers or miles. The fun part would be reducing the comparison set to only "reasonable" values so you didn't compare every location with all of the border segments.

 

I don't believe that moving the boundaries would result in the points not being included in plots. I think you would want to flag those problem records and remove drop the flagged ones for consideration.

A very crude, inefficient and possibly long running approach:

proc sql;
   create table ToFlag as
   select distinct Location.id,location.x,location.y
   from location, map
   where geodist(location.y,location.x, map.y, map.x,'M') <= 0.5;
quit;

where both the location and map boundary data sets have coordinates in either degrees or radians(set the option) would create a set you could compare the locations to for removal from the analysis. Location.id would be any variable or combination of variables that uniquely identify any point of interest in your address file.

 

 

Or if you had access to the Arcgis create the boundary set as reduced.

Solution
‎12-22-2016 04:19 PM
SAS Employee
Posts: 170

Re: Add Buffer Around Boundaries in Map

Most of the work is done with the data itself.

I do not know how you shrink a state by a half mile all the way around.  You would have to know the direction to shrink it and such.

Just a suggestion, but how about a different option?  Put a half mile circle around each point.  Then treat each point in the circle as a point for GINSIDE.  If any point in the circle is outside of state, then the origional point is within a half mile from an edge.  It might take a while to run and you have a little coding to do.  For example:

 

example2.png

 

There is an example making circles per mile at:

http://support.sas.com/rnd/papers/#SGF2009

Then look for:  Tips and Tricks IV: More SAS/GRAPH Map Secrets

Under that is a link to the paper and the examples.  In the paper, it is the example on page 7.

In the examples, it is SASU2.sas.  The program 'circle' currently does annotate data, but you can modify it to do map data.

 

 

SAS Super FREQ
Posts: 3,232

Re: Add Buffer Around Boundaries in Map

I like Darell's suggestion. I would wager that it you use just 8 points (N, S, E, W, NE, NW, SE, SW) around a point you will identify almost all of the observations that are within a mile of a state boundary. Out West (where many boundaries run N-S or E-W), you will probably identify 100%.  In the East (where boundaries might be defined by a river), I conjecture that the identification rate will still be extremely high.

Grand Advisor
Posts: 9,748

Re: Add Buffer Around Boundaries in Map

@Rick_SAS brings up a point I forgot, and should know better, the states with long "straight" borders would not necessary have enough boundary points to accurately get distance.

Occasional Contributor
Posts: 5

Re: Add Buffer Around Boundaries in Map

Thanks to all for the suggestions!

 

@ballardw Your point about states with straight borders is a great catch... I assume that a straight boundary would just have points at the vertices.

 

I think drawing a 0.5 radius circle around the address points will work, in conjunction with using PROC GINSIDE to determine if any of those points will fall in a different state.

 

Thank you everyone for your suggestions!

 

Post a Question
Discussion Stats
  • 7 replies
  • 185 views
  • 3 likes
  • 4 in conversation