Hello I have squares defined by LatLong corn...

(Mikko Palmu) #1

Hello

I have squares defined by LatLong cornerpoints, like chess board. How do I check in which square I am? I need to compare HERE() to the table of squares and find the correct square that I’m inside the cormerpoints

(Syed Faheemuddin) #2

Check this sample app https://www.appsheet.com/samples/How-to-filter-data-by-location?appGuidString=ad685a1f-e915-48da-9b98-0d2fae88b35d

(Aleksi Alkio) #3

Let’s say you have LatLong values and they are all positive from all corners in one record. You could read the correct Square with the ANY & SELECT expression like… ANY(SELECT(Tabel[Square], AND( LAT([_THISROW].[HERE])>=LAT([#1Corner]), LAT([_THISROW].[HERE])<=LAT([#2Corner]), LONG([_THISROW].[HERE])>=LONG([#1Corner]), LONG([_THISROW].[HERE])>=LONG([#4Corner]) )))

(Mikko Palmu) #4

Thanks Aleksi, I think that works only if the sides of squares are parallel to coordinates. If the sides are not perpendicular, but more diamond shape then it won’t work anymore.

stackoverflow.com - Finding whether a point lies inside a rectangle or not here’s some solutions to the problem, I think the solution with the GPS on title could be useful, checking if the point is on correct side of line between cornerpoints, and repeat that for all lines. Finding whether a point lies inside a rectangle or not stackoverflow.com

(Aleksi Alkio) #5

@Mikko_Palmu Yes I made the consumption that the square is parallel.

(Syed Faheemuddin) #6

Assuming opposite sides are parallel Try this. Table: Geofence

keycol : squareName

col1: C1

col2: C2

col3: C3

col4: C4

VC-5: Cx, appformula: (Long(C1)+Long(C2)+Long(C3)+Long(C4))/4

VC-6: Cy, appformula: (Lat(C1)+Lat(C2)+Lat(C3)+Lat(C4))/4

VC-7: m1, appformula: (Lat(C2)-Lat(C1))/(Long(C2)-Long(C1))

VC-8: b1, appformula: (Lat(C1)-m1*Long(C1))-Cy

VC-9: a1, appformula: -b1/m1-Cx

VC10: m2, appformula: (Lat(C3)-Lat(C2))/(Long(C3)-Long(C2))

VC11: b2, appformula: (Lat(C2)-m2*Long(C2))-Cy

VC12: a2, appformula: -b2/m2-Cx

Now the formula is Any(Select(Geofence[squareName],AND(ABS(Long(here())/[a1]+Lat(here())/[b1])<1,ABS(Long(here())/[a2]+Lat(here())/[b2])<1)))

PS: I didn’t test this. Please test it well before using. PSS: Can anyone verify this?

Edit: little change in formula

Any(Select(Geofence[squareName],AND(ABS((Long(here())- [Cx])/[a1]+(Lat(here()) -[Cy])/[b1])<1,ABS((Long(here()) -[Cx])/[a2]+(Lat(here()) -[Cy])/[b2])<1)))

(Mikko Palmu) #7

Thanks for that :slight_smile: I actually already got it working with with a random shape, straight lines between corner points, with the formula from my previous link… or at least it works on worksheet level, but I guess getting the result to App is then quite easy

Points 1,2,3,4 Lines 12, 23,34,41 check if point x is on the same side of line 12 as point 3, same side of line 23 as point 4 and so on if … if all are true then it’s inside