Batching lat,lon data to see if its in a geofence zone

I have to process a list of latitude and longitude co-ordinates to see if a device has moved in/out of a geo zone

Previously, the app was single threaded, and we delayed processing this information for a few minutes, then we ordered the list by the dateTime and then checked each item in date order to see if it entered / exited a zone

i.e.
12:00:01 - not in zone
12:00:02 - not in zone
12:00:03 -  in zone
12:00:04 -  in zone
12:00:05 -  in zone
12:00:06 -  in zone
12:00:07 -  in zone
12:00:08 - not in zone
12:00:09 - not in zone

Open in new window


this then saves date to db like
12:00:03 - entered the zone
12:00:08 - exited the zone

Open in new window


We have since made the console app multithreaded and we are now seeing race conditions where the data is processed in the wrong order, and its causing data integrity issues where sometimes exits the zone too early, and then the next record see's its inside the zone, therefore its creating data like this

12:00:06 - entered the zone
12:00:08 - exited the zone

12:00:04 - entered the zone
12:00:09 - exited the zone

Open in new window


the user then thinks the device entered the zone twice, when it was infact just once


Due to the high volume of data we process we need to stick with multithreaded solution
We currently check the next item in the list against the in memory "lastPosition" object

I'm now thinking we need to change the approach where we check 1 record against another, and batch the records to speed up performance (however i've no idea how we would do this)

Does anyone have any thoughts on this, and how we might accomplish this?
The data is all in a .net 4.6 console app.

If there are any latitude longitude performance stuff worth knowing about, it would also be helpful

the "zones" are a collection of latitude/longitude points which is essentially a drawn on polygon on a map
Each position is a single lat & lon set
websssAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

louisfrCommented:
By changing a list of successive "in zone" or "not in zone" positions to a single "entered" or "exited" record, you're removing information that is needed to process subsequent records.
You need to have all the data ordered before you start processing it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.