Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Finding Max distance from point in polygon (trade area) to edge

psm2000
5 - Atom

Hello Alteryx Users, 

 

I've a trade area polygon that I'm creating for every customer based on a given drive time. Once I've that, I need to find the farthest point from this customer location point to the polygon in miles/km. So the Trade Area polygon is drive time based from customer location, but then the final output I want is the farthest distance in miles from this customer location to the polygon edge. It does not matter if the longest distance is South, North etc. Just need one point. Slight approximation is OK as well. 

 

I can do the first part w/o any issues (customer to lat/long point to Trade Area). I'm not sure which tool to use for 2nd part.

 

When I look inside the TA Polygon, I do see few things I might be able to use, but I'm not sure how to access these. 

e.g. (actual values hidden)

Max Lat/Long: XX.92548, -YY.07332
Min Lat/Long: XX.83619, -YY.14133
 
The above might help me calculate the distance for both min max points and then keep the longest distance from the desired point. But I'm not if that is correct information above and how to access it. 
 
Apologies for being a bit verbose here. I hope someone chimes in on this. 
Thank you. 
7 REPLIES 7
MarqueeCrew
20 - Arcturus
20 - Arcturus

@psm2000,

 

Right or wrong, this is how I would approach the challenge.  First, I would SPLIT the polygon to POINTS.  Then I would append these points to each customer record.  This is going to mean that a single record will get split to MANY records.  Then I would calculate the distance to every point on the polygon.  Now I can sort and find the furthest distance.

 

Capture.PNG

I hope that this picture and description help.

 

Cheers,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
psm2000
5 - Atom

MarqueeCrew,

 

Thank you for quick response. Your approach is doable but it is going to explode my data set as I've large polygons (example below is 1K points for a smallish polygon) and 1/2 MM customers. But frankly, I had not seen that transformation. So at least now I've a way. 

 

My other thought was the MAX LAT/LONG that is available within the polygon. I see it when I click on it but don't know how I can get to it in the flow. If I can do that, I'll get the farthest 2 points, Is this not what it seems to be?

Type: Polygon

Centroid: 32.8790066564179, -97.106389394074
Number of Parts: 1
Number of Points: 1334
Area: 8.09238184165386 Sq Mi / 20.9591727541824 Sq Km
Length: 40.8429086726059 Mi / 65.7302900148062 Km
Max Lat/Long: XX.92548, -XX.07332   <-------------------------
Min Lat/Long: XX.83619, -XX.14133
BenMoss
ACE Emeritus
ACE Emeritus

I would approach this challenge in the same way as @MarqueeCrew too.

 

I believe the information with which you are trying to access isn't necessarily the 'MAX' but more the first and last points of the polygon; that is my understanding anyway. A quick way to test this would be to use the above method on just a single polygon and then access the information manually using your method and see if it is pulling the same point.

 

If it is then we can look at how to access it, if it isn't then it's not something we should look to do!

 

Ben

BenMoss
ACE Emeritus
ACE Emeritus

I have now just found how we can pull the data you have highlighted, again this might neccesarily be correct so be sure to check it against @MarqueeCrew's method.

 

You can use the formula tool and the functions spatiST_MaxX(object) and spatiST_MaxY(object) to return the maximum latitude and longitude of the polygon.

 

The formula tool also has the same functions for Min too.

 

Ben

psm2000
5 - Atom

Thank you, BenMoss. 

 

I tried MarqueeCrew's method and it works. But scaling is impossible. That will mean writing a macro to iterate over some grouping factor or run it in batches. So it will be worth checking what you suggest and match it with few customers from the other method. 

 

I'll try this and report back either way. 

 

Thank you. 

psm2000
5 - Atom

Thank you both for your replies.

 

I tried the formula method. I'm not sure about it as the Max/Min X Y as I did not get very predictable results. Plus validating was a pain.

 

On a good note, I was able to brute force my way through MarqueeCrew's solution. It takes time to run the entire set as the data explodes for large trade areas, but Alteryx came through. This is not an everyday process, so time is not as critical. I'll mark that as an acceptable solution. 

 

Thank you.  

 

 

This helped me solve Weekly Challenge 311, thank you!!

Labels