Example #1
0
        public static double WriteQuadKeysAndCoordinates(string fileName)
        {
            // Write to CSV file
            using (CsvFileWriter writer = new CsvFileWriter(fileName))
            {
                //Generate all QuadKeys from Coordinates based on all real max/min Coordinates (With no decimals)
                // Min. Coordinate: (-90, -180)
                // Max. Coordinate: (90, 180)

                //Write Headers
                CsvRow rowHeader = new CsvRow();
                rowHeader.Add(String.Format("Latitude"));
                rowHeader.Add(String.Format("Longitude"));
                rowHeader.Add(String.Format("QuadKey"));
                writer.WriteRow(rowHeader);

                double numRecords = 0;
                for (double latitude = -90; latitude <= 90; latitude++)
                {
                    for (double logitude = -180; logitude <= 180; logitude++)
                    {
                        CsvRow row            = new CsvRow();
                        string currentQuadKey = GeoTileTool.GeoCoordinateToQuadKey(latitude, logitude, 19);
                        row.Add(String.Format("{0}", latitude));
                        row.Add(String.Format("{0}", logitude));
                        row.Add(String.Format("{0}", currentQuadKey));

                        writer.WriteRow(row);
                        numRecords++;
                    }
                }

                return(numRecords);
            }
        }
Example #2
0
        public async Task <IEnumerable <Vehicle> > GetVehiclesInArea([FromUri] string tenantId, [FromUri] double topLatitude, [FromUri] double leftLongitude, [FromUri] double bottomLatitude, [FromUri] double rightLongitude)
        {
            ServiceEventSource.Current.Message("Called GetVehiclesInArea in STATELESS GATEWAY service to return collection of Vehicles in a particular Map's area and for Tenant {0}", tenantId);

            long topLeftGeoQuad    = GeoTileTool.GeoCoordinateToInt64QuadKey(topLatitude, leftLongitude);
            long bottomDownGeoQuad = GeoTileTool.GeoCoordinateToInt64QuadKey(bottomLatitude, rightLongitude);

            List <Vehicle> aggregatedVehiclesList = new List <Vehicle>();

            ServicePartitionList partitions = await _fabricClient.QueryManager.GetPartitionListAsync(_vehiclesStatefulServiceUriInstance);

            //Do for each partition with partition-key (QuadKey) is greater than top-lef-quadkey or smaller than down-bottom-quadkey
            foreach (Partition p in partitions)
            {
                long lowPartitionKey  = (p.PartitionInformation as Int64RangePartitionInformation).LowKey;
                long highPartitionKey = (p.PartitionInformation as Int64RangePartitionInformation).HighKey;

                //If partition-keys are within our boundary, query vehicles in partition
                if (topLeftGeoQuad <= highPartitionKey && bottomDownGeoQuad >= lowPartitionKey)
                {
                    IVehiclesStatefulService vehiclesServiceClient =
                        ServiceProxy.Create <IVehiclesStatefulService>(_vehiclesStatefulServiceUriInstance, new ServicePartitionKey(lowPartitionKey));

                    //Async call aggregating the results
                    IList <Vehicle> currentPartitionResult;
                    if (tenantId == "MASTER")
                    {
                        currentPartitionResult = await vehiclesServiceClient.GetVehiclesInAreaAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude);
                    }
                    else
                    {
                        currentPartitionResult = await vehiclesServiceClient.GetVehiclesInAreaByTenantAsync(tenantId, topLatitude, leftLongitude, bottomLatitude, rightLongitude);
                    }

                    if (currentPartitionResult.Count > 0)
                    {
                        //Aggregate List from current partition to our global result
                        aggregatedVehiclesList.AddRange(currentPartitionResult);
                    }
                }
            }

            //Show List of vehicles to return
            //foreach (Vehicle vehicle in aggregatedVehiclesList)
            //    System.Diagnostics.Debug.WriteLine($"Returning Existing Car: {vehicle.FullTitle} -- Vehicle-Id: {vehicle.Id} -- TenantId: {vehicle.TenantId} -- Orig-Latitude {vehicle.Latitude}, Orig-Longitude {vehicle.Longitude}, GeoQuadKey {vehicle.GeoQuadKey}, Geohash {vehicle.Geohash}");

            //Return the aggregated list from all the partitions
            return(aggregatedVehiclesList);
        }
Example #3
0
 private void EncodeGeoQuadKey()
 {
     _geoLocationQuadKey = GeoTileTool.GeoCoordinateToInt64QuadKey(Latitude, Longitude);
 }