1

I am building a C# program that needs to determine if a journey passes through a zone.

I have a database storing 50+ polygons (the zones) in the format of:

Lat  |  Lng  |  ZoneName

I'm using the Google Directions API and decoding the overview_polyline response to receive a collection of Lat & Long coordinates that represent 'the journey'.

So, I need to check if the route (the journey) intersects with any of the polygon zones I have stored within the database.

I wonder if I should take the following approach:

  1. Pull the zone coordinates out of the database to dynamically represent my polygon zone.
  2. For each journey step, determine if the lat & long coordinate is inside that polygon

I see point 2 could be achieved here.

But that could be quite some processing.

A short journey returned about 300 odd lat/long coordinate 'steps' for the polyline & each polygon has about 10 or more lat/long coordinates that comprise the shape boundaries.

Is there a more efficient way of doing this please?

Community
  • 1
  • 1
ChrisCurrie
  • 1,559
  • 5
  • 15
  • 35

1 Answers1

1

You can use SQL Server's spatial data types (like geometry or geography) to store the zones.

You can then use a function like STIntersects to test an existing polyline against whatever is in the database.

In ADO.NET you can use spatial types via the Microsoft.SqlServer.Types NuGet package.

Marcel N.
  • 13,438
  • 5
  • 46
  • 70