Forum Discussion
Getting what Name or Id is a point inside multiple Polygons
- 1 year ago
Hi DanSanDST , Thank you for reaching out to the Microsoft Community Forum.
We reproduced your setup and built a DAX calculated column that filters polygons by zone, groups edges by polygon, applies the ray-casting algorithm per group and returns the first polygon that contains the point. If none match, it returns Outside. This gives you exactly what you need, dynamically, without hardcoding.
Please check the attached .pbix file for reference.
That said, this approach won't scale well. DAX has no spatial engine and evaluating every polygon’s edges per point is expensive. For larger datasets, I recommend moving this logic to Power Query or a Fabric notebook, where spatial operations are more efficient and maintainable.
The algoritm actually works for the sample data im using (a single zone) i havent tested it for all the zones since it takes some time to calculate it.
first what im trying to do is this (calculated column):
Making the algorithm loop for "id zone" then "id polygon", and the column should return the id zone, id polygon and polygon name so i can split the column in the 3 values.
some data example to calculate would be: Polygon edges table for squares, please asume its a complex polygon, whats important is to get the other columns when the algorithm calculates with all the rows on this polygons table.
| id zone | id pol | pol name | lat0 | long0 | lat1 | long1 |
| 1 | 1 | A | 1 | 1 | 1 | 2 |
| 1 | 1 | A | 1 | 2 | 2 | 2 |
| 1 | 1 | A | 2 | 2 | 2 | 1 |
| 1 | 1 | A | 2 | 1 | 1 | 1 |
| 1 | 2 | B | 2 | 2 | 2 | 4 |
| 1 | 2 | B | 2 | 4 | 4 | 4 |
| 1 | 2 | B | 4 | 4 | 4 | 2 |
| 1 | 2 | B | 4 | 2 | 2 | 2 |
| 2 | 3 | C | 4 | 4 | 4 | 8 |
| 2 | 3 | C | 4 | 8 | 8 | 8 |
| 2 | 3 | C | 8 | 8 | 8 | 4 |
| 2 | 3 | C | 8 | 4 | 4 | 4 |
| 3 | 4 | D | 8 | 8 | 8 | 16 |
| 3 | 4 | D | 8 | 16 | 16 | 16 |
| 3 | 4 | D | 16 | 16 | 16 | 8 |
| 3 | 4 | D | 16 | 8 | 8 | 8 |
points to test
| point id | lat | long |
| 1 | 20 | 30 |
| 2 | 3 | 3 |
| 3 | 30 | 40 |
| 4 | 5 | 5 |
| 5 | 10 | 10 |
| 6 | 6 | 6 |
| 7 | 50 | 60 |
| 8 | 1.5 | 1.5 |
Expected result:
| point id | lat | long | Point in Poly |
| 1 | 20 | 30 | Outside |
| 2 | 3 | 3 | 1 2 B |
| 3 | 30 | 40 | Outside |
| 4 | 5 | 5 | 2 3 C |
| 5 | 10 | 10 | 3 4 D |
| 6 | 6 | 6 | 2 3 C |
| 7 | 50 | 60 | Outside |
| 8 | 1.5 | 1.5 | 1 1 A |
like i said, if the point is inside or not is covered, im missing first: getting the zone and name data for when it finds what polygon is into. And trying to at least filter the calculation for each zone, since both the polygon and values to find tables have a "zone", but it would need to be a loop so it searches the data for each zone with its zone on the polygon table. I cant have a table for each polygon since i need it to be automated, for when new polygons are added or removed.
- lbendlin1 year ago
Super User
please check your zone sample data. All of the "zones" are lines, not rectangles. A point cannot be "in" a zone in that case.
- DanSanDST1 year ago
Helper I
The algorithm works with an Edges table, meaning in a line you need x0/y0 and x1/y1 to make a segment.
The real polygons are complex and the algorithm works fine
- v-hashadapu1 year ago
Community Support
Hi DanSanDST , Thank you for reaching out to the Microsoft Community Forum.
We reproduced your setup and built a DAX calculated column that filters polygons by zone, groups edges by polygon, applies the ray-casting algorithm per group and returns the first polygon that contains the point. If none match, it returns Outside. This gives you exactly what you need, dynamically, without hardcoding.
Please check the attached .pbix file for reference.
That said, this approach won't scale well. DAX has no spatial engine and evaluating every polygon’s edges per point is expensive. For larger datasets, I recommend moving this logic to Power Query or a Fabric notebook, where spatial operations are more efficient and maintainable.