public async Task <SearchAreaModel> GetSearchAreaForIncidentAsync(int incidentId)
        {
            UriBuilder builder = new UriBuilder(Settings.ServiceEndpoint);

            builder.Path = $"api/city/{Settings.SelectedCity}/incidents/{incidentId}/search-area";

            string uri = builder.ToString();

            try
            {
                SearchAreaModel searchArea = await _requestProvider.GetAsync <SearchAreaModel>(uri);

                if (searchArea != null)
                {
                    return(new SearchAreaModel()
                    {
                        Polygon = searchArea.Polygon.ToPolygonConvexHull().ToArray(),
                        //Tickets = jsonSearchArea.Tickets
                    });
                }

                return(default(SearchAreaModel));
            }
            catch
            {
                return(default(SearchAreaModel));
            }
        }
Exemplo n.º 2
0
        public static void StoreSearchArea(SearchAreaModel searchAreaModel)
        {
            ParseObject searchArea = new ParseObject("SearchArea");

            searchArea["SearchAreaID"] = searchAreaModel.Id;
            searchArea["Name"] = searchAreaModel.Name;
            searchArea["Location"] = searchAreaModel.Location;
            searchArea["NorthEastLng"] = searchAreaModel.NortheastLongitude;
            searchArea["NorthEastLat"] = searchAreaModel.NortheastLatitude;
            searchArea["SouthWestLng"] = searchAreaModel.SouthwestLongitude;
            searchArea["SouthWestLat"] = searchAreaModel.SouthwestLatitude;
            searchArea["IsComplete"] = searchAreaModel.IsComplete;

            searchArea.SaveAsync();
        }
Exemplo n.º 3
0
        public List<SearchAreaBlockModel> GenerateBlocks(SearchAreaModel searchArea)
        {
            //Calculates the "X" distance for the search area in meters.
            double horizontalDistance = calculate(searchArea.NortheastLatitude,
                searchArea.NortheastLongitude, searchArea.NortheastLatitude, searchArea.SouthwestLongitude);

            //Calculates the "Y" distance for the search area in meters.
            double verticalDistance = calculate(searchArea.NortheastLatitude,
                searchArea.NortheastLongitude, searchArea.SouthwestLatitude, searchArea.NortheastLongitude);

            //Calculates NE Corner Coordinates
            Tuple<double, double> NWCorner = new Tuple<double, double>(searchArea.NortheastLatitude, searchArea.SouthwestLongitude);

            //Assignes the vertical and horizontal values of the blocks to blockHeight and blockWidth based on the entered terrainType.
            double blockHeight;
            double blockWidth;
            switch (searchArea.AreaType)
            {
                case AreaTypes.Field:
                    blockHeight = 50;
                    blockWidth = 50;
                    break;
                case AreaTypes.Forest:
                    blockHeight = 25;
                    blockWidth = 25;
                    break;
                case AreaTypes.DenseForest:
                    blockHeight = 10;
                    blockWidth = 10;
                    break;
                case AreaTypes.Mountains:
                    blockHeight = 5;
                    blockWidth = 5;
                    break;
                default:
                    blockHeight = 0;
                    blockWidth = 0;
                    throw new InvalidOperationException();
            }
            //Calculates the number of blocks needed and creates an array with that ammount.
            int numberOfXBlocks = (int)Math.Ceiling(horizontalDistance / blockWidth);
            int numberOfYBlocks = (int)Math.Ceiling(verticalDistance / blockHeight);
            SearchAreaBlockModel[,] blockArray = new SearchAreaBlockModel[numberOfXBlocks, numberOfYBlocks];

            //creates a tuple with the coordinates for the first block.
            Tuple<double, double> block0Coords = calculateDisplacement(NWCorner.Item1, NWCorner.Item2, blockWidth / 2, -(blockHeight / 2));
            double arrayLatitude = block0Coords.Item1;
            double arrayLongitude = block0Coords.Item2;

            for (int row = 0; row < numberOfXBlocks; row++)
            {
                //if we're not on the first row, a change in the vertical coordinates for the array.
                if (row != 0)
                {
                    Tuple<double, double> vertChangeCoords = calculateDisplacement(arrayLatitude, arrayLongitude, 0, blockHeight);
                    arrayLatitude = vertChangeCoords.Item1;
                }
                for (int column = 0; column < numberOfYBlocks; column++)
                {
                    //if the end of the column is reached then the longitude is reset to the first blocks coordinates.
                    if (column == 0)
                    {
                        //sets the array longitude to the first blocks longitude.
                        arrayLongitude = block0Coords.Item2;
                    }
                    //A random ID and a Geopoint for the block is created.
                    Guid randomID = System.Guid.NewGuid();
                    string id = randomID.ToString();

                    ParseGeoPoint arrayLocation = new ParseGeoPoint(arrayLatitude, arrayLongitude);

                    //A new searchAreaBlockModel is created in the curent cell with all the given information.
                    blockArray[row, column] = new SearchAreaBlockModel(arrayLongitude, arrayLatitude, arrayLocation, row, column, id, false);

                    //implements longitude change
                    Tuple<double, double> horizChangeCoords = calculateDisplacement(arrayLatitude, arrayLongitude, blockWidth, 0);
                    arrayLongitude = horizChangeCoords.Item2;

                }
            }

            //Adds the blockArray to a list in order from the top left to the bottom right.
            List<SearchAreaBlockModel> lastList = new List<SearchAreaBlockModel>();
            for (int row = 0; row < numberOfXBlocks; row++)
            {
                for (int column = 0; column < numberOfYBlocks; column++)
                {
                    lastList.Add(blockArray[row, column]);
                }
            }
            return lastList;
        }
Exemplo n.º 4
0
        public Models.Search.SearchAreaModel GenerateSearchArea(string name, AreaTypes areaType, ParseGeoPoint northeastGeopoint, ParseGeoPoint southwestGeopoint)
        {
            Guid id = Guid.NewGuid();
            string id_str = id.ToString();

            double neLng = northeastGeopoint.Longitude;
            double neLat = northeastGeopoint.Latitude;
            double swLng = southwestGeopoint.Longitude;
            double swLat = southwestGeopoint.Latitude;

            SearchAreaModel searchAreaModel = new SearchAreaModel(id_str, name, areaType, northeastGeopoint, neLng, neLat, swLng, swLat, false);

            return searchAreaModel;
        }