Hi All,
newbie question. I have two tables in Access 2016, one of points (x/y coordinates) and another of polygons (consisting of an Poly_ID and a series of x/y nodes defining each poly perimeter). I need to discover what points are in what polygon. The actual database has over 250K points and 4K polygons.
Below is a vb function (written by Rick Rothstein in another forum) for excel that works brilliantly for one point in one polygon.
I’d like to use this function, or something like it, in Access but can’t get my head around how to refer to a range in access.
Can anyone point me in the right direction?
Pic and sample db attached.
newbie question. I have two tables in Access 2016, one of points (x/y coordinates) and another of polygons (consisting of an Poly_ID and a series of x/y nodes defining each poly perimeter). I need to discover what points are in what polygon. The actual database has over 250K points and 4K polygons.
Below is a vb function (written by Rick Rothstein in another forum) for excel that works brilliantly for one point in one polygon.
I’d like to use this function, or something like it, in Access but can’t get my head around how to refer to a range in access.
Can anyone point me in the right direction?
Pic and sample db attached.
Code:
Public Function PtInPoly(Xcoord As Double, Ycoord As Double, Polygon As Variant) As Variant
Dim x As Long, NumSidesCrossed As Long, m As Double, b As Double, Poly As Variant
Poly = Polygon
For x = LBound(Poly) To UBound(Poly) - 1
If Poly(x, 1) > Xcoord Xor Poly(x + 1, 1) > Xcoord Then
m = (Poly(x + 1, 2) - Poly(x, 2)) / (Poly(x + 1, 1) - Poly(x, 1))
b = (Poly(x, 2) * Poly(x + 1, 1) - Poly(x, 1) * Poly(x + 1, 2)) / (Poly(x + 1, 1) - Poly(x, 1))
If m * Xcoord + b > Ycoord Then NumSidesCrossed = NumSidesCrossed + 1
End If
Next
PtInPoly = CBool(NumSidesCrossed Mod 2)
End Function