public RasterizeObject GetCoordinateTile(List <PointF> points, bool withRasterize, List <PointF> boundingBox = null, int zoomlevel = 14, string encodedTiles = null) { try { RasterizeObject rasterizeObject = new RasterizeObject(); rasterizeObject.tiles = new List <Tile>(); object lockObj = new object(); if (withRasterize) { string postData = @"{""zoom"": " + zoomlevel + @","; if (!string.IsNullOrEmpty(encodedTiles)) { postData += postData = @"""encodedTile"": """ + encodedTiles + @""""; } else if (points != null && points.Count() > 0) { string encodedString = GooglePoints.EncodeBase64(points.Select(x => new CoordinateEntity(x.X, x.Y))); postData += @"""encodedPolygon"": """ + encodedString + @""""; } if (boundingBox != null && boundingBox.Count() > 0) { string boundingBoxPostData = JSONHelper.GetString(boundingBox.Select(x => new LocationPoint { Lat = Convert.ToDecimal(x.X), Lng = Convert.ToDecimal(x.Y) }).ToList()); postData += @",""boundingBox"": " + boundingBoxPostData; } postData += "}"; string responseFromServer = responseFromServer = this.PostData(LambdaResourceType.areas, postData); if (boundingBox != null && boundingBox.Count() > 0) { return(JSONHelper.GetObject <RasterizeObject>(responseFromServer)); } else { RasterizeObject obj = new RasterizeObject(); obj.tiles = JSONHelper.GetObject <List <Tile> >(responseFromServer); return(obj); } } else { List <Tile> tilesCoordinates = new List <Tile>(); foreach (var point in points) { tilesCoordinates.Add(new Tile() { Zoom = zoomlevel, Lat = point.X, Lng = point.Y }); } ; Parallel.ForEach(tilesCoordinates.ChunkBy(200), tilesCoordinate => { string postData = JSONHelper.GetString(tilesCoordinate); string responseFromServer = this.PostData(LambdaResourceType.listings, postData); //string responseFromServer = this.CallRasterizationLambda(postData); lock (lockObj) { rasterizeObject.tiles.AddRange(JSONHelper.GetObject <List <Tile> >(responseFromServer)); } }); } return(rasterizeObject); } catch (Exception ex) { throw ex; } }
public async Task <GetListingWrapper> GetListing(Area area, string north = null, string east = null, string south = null, string west = null, string beds = null, string bathsFull = null, string bathsHalf = null, string propertyAddressId = null, string averageValue = null, string averageRent = null, string encodedCompletedTiles = null, string encodedPartialTiles = null) { List <Listing> listings = new List <Listing>(); List <PointF> boundingBox = null; if (!string.IsNullOrEmpty(north) && !string.IsNullOrEmpty(east) && !string.IsNullOrEmpty(south) && !string.IsNullOrEmpty(west)) { boundingBox = new List <PointF>(); boundingBox.Add(new PointF((float)Convert.ToDouble(north), (float)Convert.ToDouble(east))); boundingBox.Add(new PointF((float)Convert.ToDouble(north), (float)Convert.ToDouble(west))); boundingBox.Add(new PointF((float)Convert.ToDouble(south), (float)Convert.ToDouble(west))); boundingBox.Add(new PointF((float)Convert.ToDouble(south), (float)Convert.ToDouble(east))); } DateTime startLambdaTime = DateTime.Now; List <Tile> tiles = new List <Tile>(); if (!string.IsNullOrEmpty(encodedCompletedTiles) || !string.IsNullOrEmpty(encodedPartialTiles)) { if (!string.IsNullOrEmpty(area.EncodedPolygon)) { area.Points = GooglePoints.DecodeBase64(area.EncodedPolygon).Select(x => new LocationPoint(x.Latitude, x.Longitude)).ToList(); } if (boundingBox == null || boundingBox.Count() == 0) { tiles.AddRange(GooglePoints.DecodeBase64(encodedCompletedTiles).Select(x => new Tile() { Row = (int)x.Latitude, Column = (int)x.Longitude, IsPartialTile = false }).ToList()); tiles.AddRange(GooglePoints.DecodeBase64(encodedPartialTiles).Select(x => new Tile() { Row = (int)x.Latitude, Column = (int)x.Longitude, IsPartialTile = true }).ToList()); } else { RasterizeObject rasterizeObject = this.GetCoordinateTile(area.Points.Select(x => new PointF((float)x.Lat, (float)x.Lng)).ToList(), true, boundingBox); tiles = rasterizeObject.tiles; area.Points = new WKTReader().Read(rasterizeObject.intersectionPolygon).Coordinates.Select(x => new LocationPoint(x.X, x.Y)).ToList(); } } else { if (!string.IsNullOrEmpty(area.EncodedPolygon)) { area.Points = GooglePoints.Decode(area.EncodedPolygon).Select(x => new LocationPoint(x.Latitude, x.Longitude)).ToList(); } RasterizeObject rasterizeObject = this.GetCoordinateTile(area.Points.Select(x => new PointF((float)x.Lat, (float)x.Lng)).ToList(), true, boundingBox); tiles = rasterizeObject.tiles; if (boundingBox != null && boundingBox.Count() > 0) { area.Points = new WKTReader().Read(rasterizeObject.intersectionPolygon).Coordinates.Select(x => new LocationPoint(x.X, x.Y)).ToList(); } } DateTime endLambdaTime = DateTime.Now; //if (tiles == null || tiles.Count() == 0) //{ // throw new Exception("Unable To Calculate Tiles"); //} DateTime startQueryTime = DateTime.Now; GetRegionByPropertyWrapper listing = getRegionByProperty(tiles, beds, bathsFull, bathsHalf, propertyAddressId, averageValue, averageRent).Result; DateTime endQueryTime = DateTime.Now; foreach (var item in listing.CompleteProperties) { if (item != null) { listings.Add(new Listing { Name = item.PropertyAddressName, Lat = item.Latitude, Lng = item.Longitude }); } } Stopwatch containsStopwatch = Stopwatch.StartNew(); Parallel.ForEach(listing.PartialProperties, item => { if (item != null && this.polyCheck(new Vector2((float)item.Latitude, (float)item.Longitude), area.Points.Select(x => new Vector2((float)x.Lat, (float)x.Lng)).ToArray())) { listings.Add(new Listing { Name = item.PropertyAddressName, Lat = item.Latitude, Lng = item.Longitude }); } }); containsStopwatch.Stop(); List <ListingMaster> customProperties = listings.Select(x => new ListingMaster() { Lat = x.Lat, Lng = x.Lng, Name = x.Name }).ToList(); return(new GetListingWrapper { PropertyCount = listing.TotalRecordCount, ScanCount = listing.ScanCount, ConsumedCapacityCount = listing.ConsumedCapacityCount, TotalQueryExecutionTime = (endQueryTime - startQueryTime).TotalMilliseconds, TotalLambdaExecutionTime = (endLambdaTime - startLambdaTime).TotalMilliseconds, TotalContainsExecutionTime = containsStopwatch.ElapsedMilliseconds, Properties = customProperties, }); }