BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cruise
Ammonite | Level 13

Is it possible at all to calculate the distance to the nearest edge of polygon from points (latitude and longitude)  using SAS?

 

I have latitude and longitude of residential homes and the polygons of SuperFund sites. I'd like to calculate the distance for each residential homes to the nearest edge of polygons of SuperFund sites. I know how to do it in ARCGIS. 

 

Any hints are appreciated. 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
pink_poodle
Barite | Level 11

You can use the GREDUCE procedure to find the point on the polygon edge that is closest to the house coordinates, then use GEODIST function to find the distance between house coordinates and that point.

View solution in original post

3 REPLIES 3
pink_poodle
Barite | Level 11

You can use the GREDUCE procedure to find the point on the polygon edge that is closest to the house coordinates, then use GEODIST function to find the distance between house coordinates and that point.

Cruise
Ammonite | Level 13

@pink_poodle

 

Thanks, I'm looking for an example or any link showing steps with Greduce. Let me know if u have one please.

pink_poodle
Barite | Level 11

It might be possible to test a simple scenario, where the polygon is represented by points (0,0), (0,1) and (0,2), while a house is point (1,1). After the GREDUCE procedure, the subset should contain only point (0,1) of the polygon and point (1,1).

 

Three links follow that inspired this idea. Link 2 is the code for link 1. 

 

1. https://blogs.sas.com/content/iml/2018/07/16/points-distance-from-polygon.html

2. https://blogs.sas.com/content/iml/files/2018/07/offsetregion.txt

3. http://morgan.dartmouth.edu/Docs/sas92/support.sas.com/documentation/cdl/en/graphref/61884/HTML/defa...

 

Following is a fragment of code from link 2 used to reduce the contours of Texas to a 36-sided polygon. Input dataset is Texas1 and output dataset is Texas2. For this question, for a simple test, the input dataset would contain all four points. Once the appropriate density level is found, the output dataset will contain only the nearest point of the polygon and the house coordinates.

 

/* Before starting the SAS/IML program, generate a polygon for the state
  of Texas in standardized coordinates.
*/
data Texas1;
   set maps.US;
   where StateCode = "TX" and Segment=1;
   by State Segment;
run;

* Create density variable that can be used to reduce the data set;
proc greduce data=Texas1 out=Texas2;
  id segment;
run;

data Texas;
   set Texas2(keep=segment x y density);
   where (density<=4);
   Obs = _N_;
run;
 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1902 views
  • 2 likes
  • 2 in conversation