public string DualRegionQueryCircle(DateTime startDate, DateTime endDate, LatLong pointOne, double radiusOne, LatLong pointTwo, double radiusTwo)
        {
            using (TaxiDataEntities context = new TaxiDataEntities())
            {
                SqlGeography centroidOne = CreatePoint(pointOne);
                SqlGeography centroidTwo = CreatePoint(pointTwo);

                List<QueryDto> returnVal = context.TwoRegionQueryCircle(startDate, endDate, radiusOne, centroidOne.ToString(), radiusTwo, centroidTwo.ToString())
                    .Select(x => new QueryDto
                    {
                        Pickup = new LatLong
                        {
                            Latitude = (double)x.pickup_latitude,
                            Longitude = (double)x.pickup_longitude
                        },
                        Dropoff = new LatLong
                        {
                            Latitude = (double)x.dropoff_latitude,
                            Longitude = (double)x.dropoff_longitude
                        },
                        FareTotal = x.total_amount,
                        TravelTime = x.trip_time_in_secs,
                        NumOfPassenger = x.passenger_count,
                        TripDistance = x.trip_distance
                    }).ToList();

                return JsonConvert.SerializeObject(returnVal);
            }
        }
        public string DualRegionQuery(DateTime startDate, DateTime endDate, List<LatLong> regionOnePoints, List<LatLong> regionTwoPoints)
        {
            using (TaxiDataEntities context = new TaxiDataEntities())
            {
                //build both of the polygons to send to the server
                SqlGeography polygon1 = CreatePolygonFromPoints(regionOnePoints);
                SqlGeography polygon2 = CreatePolygonFromPoints(regionTwoPoints);

                List<QueryDto> returnVal = context.TwoRegionQueryPoly(startDate, endDate, polygon1.ToString(), polygon2.ToString())
                                            .Select(x => new QueryDto
                                            {
                                                Pickup = new LatLong
                                                {
                                                    Latitude = (double)x.pickup_latitude,
                                                    Longitude = (double)x.pickup_longitude
                                                },
                                                Dropoff = new LatLong
                                                {
                                                    Latitude = (double)x.dropoff_latitude,
                                                    Longitude = (double)x.dropoff_longitude
                                                },
                                                FareTotal = x.total_amount,
                                                TravelTime = x.trip_time_in_secs,
                                                NumOfPassenger = x.passenger_count,
                                                TripDistance = x.trip_distance
                                            }).ToList();

                return JsonConvert.SerializeObject(returnVal);
            }
        }
        public string GetNearestPoint(DateTime startDate, DateTime endDate, LatLong point, int queryFor)
        {
            using (TaxiDataEntities context = new TaxiDataEntities())
            {
                //create the point to look for given by the latlong object
                SqlGeography sqlPoint = CreatePoint(point);

                //initialize return list and the initial distance to search in
                List<QueryDto> returnVal = new List<QueryDto>();
                int initialDistance = 10;

                //starting from the initialDistance search for a trip and expand the search distance until
                //a point is found. The max is 100000 meters which is around 62 miles which is sufficient for this project
                while (returnVal.Count() == 0 && initialDistance < 100000)
                {
                    returnVal = context.NearestPointQuery(startDate, endDate, initialDistance, sqlPoint.ToString(), queryFor)
                                    .Select(x => new QueryDto
                                    {
                                        Pickup = new LatLong
                                        {
                                            Latitude = (double)x.pickup_latitude,
                                            Longitude = (double)x.pickup_longitude
                                        },
                                        Dropoff = new LatLong
                                        {
                                            Latitude = (double)x.dropoff_latitude,
                                            Longitude = (double)x.dropoff_longitude
                                        },
                                        FareTotal = x.total_amount,
                                        TravelTime = x.trip_time_in_secs,
                                        NumOfPassenger = x.passenger_count,
                                        TripDistance = x.trip_distance
                                    }).ToList();

                    initialDistance *= 2;
                }

                return JsonConvert.SerializeObject(new QueryDto[] {returnVal.First()});
            }
        }
        public string GetTripsOnLine(DateTime startDate, DateTime endDate, List<LatLong> linePoints)
        {
            using (TaxiDataEntities context = new TaxiDataEntities())
            {
                //build the line from the points given
                SqlGeography sqlLine = CreateLineFromPoints(linePoints);

                //kick off the stored procedure
                List<QueryDto> returnVal = context.LineWithVolume(startDate, endDate, sqlLine.ToString())
                                    .Select(x => new QueryDto
                                    {
                                        Pickup = new LatLong
                                        {
                                            Latitude = (double)x.pickup_latitude,
                                            Longitude = (double)x.pickup_longitude
                                        },
                                        Dropoff = new LatLong
                                        {
                                            Latitude = (double)x.dropoff_latitude,
                                            Longitude = (double)x.dropoff_longitude
                                        },
                                        FareTotal = x.total_amount,
                                        TravelTime = x.trip_time_in_secs,
                                        NumOfPassenger = x.passenger_count,
                                        TripDistance = x.trip_distance
                                    }).ToList();

                return JsonConvert.SerializeObject(returnVal);
            }
        }
        public string GetPointsInPolygonRegion(DateTime startDate, DateTime endDate, List<LatLong> boundPoints, int queryFor)
        {
            using (TaxiDataEntities context = new TaxiDataEntities())
            {
                //build the geography polygon from the points
                SqlGeography sqlPoly = CreatePolygonFromPoints(boundPoints);

                //run the stored procedure and make a list of the data
                List<QueryDto> returnVal = context.RegionQueryPoly(startDate, endDate, sqlPoly.ToString(), queryFor)
                    .Select(x => new QueryDto
                    {
                        Pickup = new LatLong
                        {
                            Latitude = (double)x.pickup_latitude,
                            Longitude = (double)x.pickup_longitude
                        },
                        Dropoff = new LatLong
                        {
                            Latitude = (double)x.dropoff_latitude,
                            Longitude = (double)x.dropoff_longitude
                        },
                        FareTotal = x.total_amount,
                        TravelTime = x.trip_time_in_secs,
                        NumOfPassenger = x.passenger_count,
                        TripDistance = x.trip_distance
                    }).ToList();

                return JsonConvert.SerializeObject(returnVal);
            }
        }
        public string GetPointsInCircleRegion(DateTime startDate, DateTime endDate, double radius, LatLong centroid, int queryFor)
        {
            using (TaxiDataEntities context = new TaxiDataEntities())
            {
                //build the centroid out of the latlong object given
                SqlGeography sqlPoint = CreatePoint(centroid);

                //kick off the stored procedure and return the data
                List<QueryDto> returnVal = context.RegionQueryCircle(startDate, endDate, radius, sqlPoint.ToString(), queryFor)
                        .Select(x => new QueryDto
                            {
                                Pickup = new LatLong
                                {
                                    Latitude = (double)x.pickup_latitude,
                                    Longitude = (double)x.pickup_longitude
                                },
                                Dropoff = new LatLong
                                {
                                    Latitude = (double)x.dropoff_latitude,
                                    Longitude = (double)x.dropoff_longitude
                                },
                                FareTotal = x.total_amount,
                                TravelTime = x.trip_time_in_secs,
                                NumOfPassenger = x.passenger_count,
                                TripDistance = x.trip_distance
                            }).ToList();

                return JsonConvert.SerializeObject(returnVal);
            }
        }