Esempio n. 1
0
        public void GetCenterPointXYOfHexagon(int u, int v, double x, double y)
        {
            var pointXY = HexagonUtils.GetCenterPointXYOfHexagonLocationUV(new HexagonLocationUV(u, v), _hexagonDefinition);

            Assert.Equal(x, Math.Round(pointXY.X, 2));
            Assert.Equal(y, Math.Round(pointXY.Y, 2));
        }
Esempio n. 2
0
        public async Task <bool> ExportResults(IEnumerable <Hexagon> hexagons, HexagonDefinition hexagonDefinition, MergeStrategy mergeStrategy)
        {
            foreach (Hexagon hexagon in hexagons)
            {
                string insertCommand = @"INSERT INTO HexagonLocation (U,V,PIXELX,PIXELY) VALUES (@U,@V,@PixelX,@PixelY) ON CONFLICT(U,V) DO UPDATE SET PixelX=excluded.PixelX,PixelY=excluded.PixelY";

                PointXY hexagonCenter = HexagonUtils.GetCenterPointXYOfHexagonLocationUV(hexagon.LocationUV, hexagonDefinition);

                await _connection.ExecuteAsync(insertCommand,
                                               new
                {
                    hexagon.LocationUV.U,
                    hexagon.LocationUV.V,
                    PixelX = hexagonCenter.X,
                    PixelY = hexagonCenter.Y
                });

                foreach (var key in hexagon.HexagonData.Data.Keys)
                {
                    object dataValue = hexagon.HexagonData.Data[key];

                    string insertDataCommand = @"INSERT INTO HexagonData (U,V,FIELD,VALUE) VALUES (@U,@V,@Field,@Value) ON CONFLICT(U,V,FIELD) DO ";

                    switch (mergeStrategy)
                    {
                    case MergeStrategy.BitMask:
                        insertDataCommand += "UPDATE SET VALUE=VALUE|excluded.Value";
                        break;

                    case MergeStrategy.Ignore:
                        insertDataCommand += "NOTHING";
                        break;

                    case MergeStrategy.Replace:
                        insertDataCommand += "UPDATE Set Value=excluded.Value";
                        break;

                    case MergeStrategy.Max:
                        insertDataCommand += "UPDATE Set Value=max(excluded.Value,Value)";
                        break;

                    case MergeStrategy.Min:
                        insertDataCommand += "UPDATE Set Value=min(excluded.Value,Value)";
                        break;
                    }

                    await _connection.ExecuteAsync(insertDataCommand,
                                                   new
                    {
                        hexagon.LocationUV.U,
                        hexagon.LocationUV.V,
                        Field = key,
                        Value = dataValue
                    });
                }
            }

            return(true);
        }
Esempio n. 3
0
        public IActionResult Get(int z, int x, int y)
        {
            using (var destinationImage = new Image <Rgba32>(TileSize, TileSize))
            {
                if (z >= 7)
                {
                    var hexSize = 500;


                    var size = (int)(hexSize / Math.Pow(2, 10 - z));

                    var hexagonDefinition = new HexagonDefinition(size, 10);

                    //Tile offset
                    var pixelX = x * TileSize;
                    var pixelY = y * TileSize;

                    var topLeft     = new PointXY(pixelX - size, pixelY - size);
                    var bottomRight = new PointXY(pixelX + TileSize + size, pixelY + TileSize + size);

                    foreach (HexagonLocationUV hexagon in HexagonUtils.GetHexagonsInsideBoundingBox(topLeft, bottomRight, hexagonDefinition))
                    {
                        PointXY center = HexagonUtils.GetCenterPointXYOfHexagonLocationUV(hexagon, hexagonDefinition);

                        IList <PointXY> hexagonPoints = HexagonUtils
                                                        .GetHexagonPixels(size, new PointXY(center.X - pixelX, center.Y - pixelY)).ToList();

                        PointF[] points = hexagonPoints.Select(p => new PointF((float)p.X, (float)p.Y)).ToArray();

                        destinationImage.Mutate(ctx => ctx

                                                .DrawLines(
                                                    new Rgba32(200, 200, 200, 200),
                                                    5,
                                                    points)
                                                .DrawLines(
                                                    new Rgba32(100, 100, 100, 200),
                                                    2,
                                                    points));
                    }
                }

                Stream outputStream = new MemoryStream();

                destinationImage.Save(outputStream, new PngEncoder());
                outputStream.Seek(0, SeekOrigin.Begin);
                return(this.File(outputStream, "image/png"));
            }
        }
Esempio n. 4
0
        public IEnumerable <Hexagon> ProcessArea(GeoData geoData, LayersLoaderTarget[] targets = null)
        {
            foreach (PointXY[] geoCoordinates in geoData.Points)
            {
                var topLeftCoordinate     = new PointXY(geoCoordinates.Min(c => c.X), geoCoordinates.Min(c => c.Y));
                var bottomRightCoordinate = new PointXY(geoCoordinates.Max(c => c.X), geoCoordinates.Max(c => c.Y));

                var hexagonLocations = HexagonUtils.GetHexagonsInsideBoundingBox(topLeftCoordinate, bottomRightCoordinate, hexagonDefinition);

                foreach (var hexagonLocation in hexagonLocations)
                {
                    var center = HexagonUtils.GetCenterPointXYOfHexagonLocationUV(hexagonLocation, hexagonDefinition);

                    if (AreaHelper.IsPointInsidePolygon(center.X, center.Y, geoCoordinates))
                    {
                        yield return(CreateHexagon(geoData, targets, hexagonLocation, (geo, target) => geo.Values[target.SourceField]));
                    }
                }
            }
        }